Home Manual Reference Source

Function

Static Public Summary
public

attributeObjectToHtml(attributes: {}): string

Takes an object that maps attribute names to values, and returns it as html formatted attributes.

public

Element.remove() polyfill for IE11 compatibility

public

ensureMapHasDataInReduxStore(typeMap: *, dispatchAction: *, dispatch: *): boolean

Used to ensure that a map built by makeTypeMappedReduxMapFromApiData or makeImmutableOrderedMapFromValueArray is loaded in redux-store

public

Escape HTML attribute value.

public

getFileExtension(filename: *): string

Get file extension.

public

getObjectFromReduxMapOrNullIfLoading(map: *, id: *, dispatchAction: *, dispatch: *): null | Immutable.Map

Simple util to fetch data from a redux-api-map (which should always be built by makeApiDataMapIsLoading, makeApiDataMapNewData or makeApiDataMapError).

public

getValuesFromTypeMappedReduxMap(typeMappedReduxMap: *, typeKey: *, fallbackToDefault: *): Immutable.OrderedMap<string, Immutable.Map<string, string>>

Used to fetch the ImmutableOrderedMap of values for a <typeKey> in a structure built by makeTypeMappedReduxMapFromApiData.

public

isInlineTag(tagName: string): *

Returns True if the provided tagName is an inline tag.

public

isSelfClosingTag(tagName: string): *

Returns True if the provided tagName is a self closing tag.

public

makeApiDataMapDeleted(oldData: *): Immutable.Map

Used to mark an object in redux-state as deleted.

public

makeApiDataMapError(error: *): Immutable.Map

Util used by all action.js-files in redux/api/*.

public

makeApiDataMapIsLoading(oldApiDataMap: *): Immutable.Map<string, any>

Util used by all action.js-files in redux/api/*.

public

makeApiDataMapNewData(newData: *, fromList: *, noWrap: *): Immutable.Map

Util used by all action.js-files in redux/api/*.

public

makeCustomError(name: string, extendsError: Error): Error

Make a custom error "class".

public

Make a HTML end tag.

public

makeHtmlStartTag(tagName: string, attributes: {}): string

Make a HTML start tag.

public

makeImmutableOrderedMapFromValueArray(valueArray: *, valueKey: *): Immutable.OrderedMap<string, Immutable.Map<string, string>>

Used for the internal OrderedMap from makeTypeMappedReduxMapFromApiData, and should be used for other type-lists from api.

public

makeTypeMappedReduxMapFromApiData(apiResponseBodydata: *): Immutable.Map<string, Immutable.OrderedMap<string, Immutable.Map<string, string>>>

Used for apis like nodePaymentSubscriptionTypes and nodeMembershipTypes.

public

onDocumentReady(callback: *)

Wrap a callback that is called when the document is done loading.

public

typeDetect(obj: *): string

Detect the type of an object and return the result as a string.

Static Public

public attributeObjectToHtml(attributes: {}): string source

import {attributeObjectToHtml} from 'ievv_jsbase/lib/html/utils'

Takes an object that maps attribute names to values, and returns it as html formatted attributes.

The result will start with an empty space if the provided object is not empty.

Params:

NameTypeAttributeDescription
attributes {}

Object mapping attribute names to values.

Return:

string

The HTML encoded attributes.

public elementRemovePolyfill() source

import elementRemovePolyfill from 'ievv_jsbase/lib/polyfill/elementRemovePolyfill'

Element.remove() polyfill for IE11 compatibility

public ensureMapHasDataInReduxStore(typeMap: *, dispatchAction: *, dispatch: *): boolean source

import {ensureMapHasDataInReduxStore} from 'ievv_jsbase/lib/utils/reduxApiUtilities'

Used to ensure that a map built by makeTypeMappedReduxMapFromApiData or makeImmutableOrderedMapFromValueArray is loaded in redux-store

Note that this should only be used in cases where the data is static (e.g. load once, use always), as it does not pass any params to the api or check if any specific data is present. This simply triggers the given action if the map is empty and not already loading.

Params:

NameTypeAttributeDescription
typeMap *

The redux-store-map you want to ensure is loaded (e.g. userNotificationTypesMap)

dispatchAction *

the redux-action to dispatch to load the typemap

dispatch *

The dispatcher to use to dispatch the dispatchAction, e.g. props.dispatch

Return:

boolean

true if the given map is loaded, false if not.

public escapeAttributeValue(value: *): string source

import {escapeAttributeValue} from 'ievv_jsbase/lib/html/utils'

Escape HTML attribute value.

Params:

NameTypeAttributeDescription
value *

The attribute value to escape. Coerced to string if it not a string.

Return:

string

public getFileExtension(filename: *): string source

import {getFileExtension} from 'ievv_jsbase/lib/utils/filepath'

Get file extension.

Params:

NameTypeAttributeDescription
filename *

A filename. An URL also works.

Return:

string

The extension. Will be an empty string if we can not determine the extension.

public getObjectFromReduxMapOrNullIfLoading(map: *, id: *, dispatchAction: *, dispatch: *): null | Immutable.Map source

import {getObjectFromReduxMapOrNullIfLoading} from 'ievv_jsbase/lib/utils/reduxApiUtilities'

Simple util to fetch data from a redux-api-map (which should always be built by makeApiDataMapIsLoading, makeApiDataMapNewData or makeApiDataMapError).

This util will lookup the given id in the given map and return it if it exists. If the entry is missing or loading, null is returned. If the entry is missing (and not already loading), the given dispatchAction is dispatched and null is returned.

Note that this util will still return the object even if it is an error-object (apiError !== null), so you need to handle errors in your component.

Params:

NameTypeAttributeDescription
map *

{Immutable.Map} a map built by makeApiDataMapIsLoading, makeApiDataMapNewData or makeApiDataMapError

id *

{number} the entry-id to look for in the map

dispatchAction *

{function} the redux.api...actions.<action> to dispatch to load the entry if missing

dispatch *

{function} a redux-thunk dispatch, like this.props.dispatch from a connected React.Component.

Return:

null | Immutable.Map

null if the entry is loading, or an ImmutableMap of the entry if it exists.

public getValuesFromTypeMappedReduxMap(typeMappedReduxMap: *, typeKey: *, fallbackToDefault: *): Immutable.OrderedMap<string, Immutable.Map<string, string>> source

import {getValuesFromTypeMappedReduxMap} from 'ievv_jsbase/lib/utils/reduxApiUtilities'

Used to fetch the ImmutableOrderedMap of values for a <typeKey> in a structure built by makeTypeMappedReduxMapFromApiData. See its documentation for structure.

If the given <typeKey> is not present in the map, then the entry referenced by TYPE_MAPPED_REDUX_MAP_DEFAULT_KEY will be returned instead.

Params:

NameTypeAttributeDescription
typeMappedReduxMap *

a map built by makeTypeMappedReduxMapFromApiData

typeKey *

the <typeKey> to look for in the map

fallbackToDefault *

if true return default-data if no data for typekey is present. If false, return null.

Return:

Immutable.OrderedMap<string, Immutable.Map<string, string>>

The ImmutableOrderedMap referenced by the given <typeKey>

public isInlineTag(tagName: string): * source

import {isInlineTag} from 'ievv_jsbase/lib/html/utils'

Returns True if the provided tagName is an inline tag.

Params:

NameTypeAttributeDescription
tagName string

The tag name.

Return:

*

public isSelfClosingTag(tagName: string): * source

import {isSelfClosingTag} from 'ievv_jsbase/lib/html/utils'

Returns True if the provided tagName is a self closing tag.

Params:

NameTypeAttributeDescription
tagName string

The tag name.

Return:

*

public makeApiDataMapDeleted(oldData: *): Immutable.Map source

import {makeApiDataMapDeleted} from 'ievv_jsbase/lib/utils/reduxApiUtilities'

Used to mark an object in redux-state as deleted.

Params:

NameTypeAttributeDescription
oldData *

Return:

Immutable.Map

public makeApiDataMapError(error: *): Immutable.Map source

import {makeApiDataMapError} from 'ievv_jsbase/lib/utils/reduxApiUtilities'

Util used by all action.js-files in redux/api/*.

This is used to build a common error-format for all redux-map-entries. sets isLoading to false, data to null, timestamp to now.

stores the error in the field apiError formatted like this:

apiError: ImmutableMap({ status: error.response.status, bodydata: ImmutableMap(error.response.bodydata) })

Params:

NameTypeAttributeDescription
error *

Return:

Immutable.Map

public makeApiDataMapIsLoading(oldApiDataMap: *): Immutable.Map<string, any> source

import {makeApiDataMapIsLoading} from 'ievv_jsbase/lib/utils/reduxApiUtilities'

Util used by all action.js-files in redux/api/*. This is used to mark an entry in a redux-map as loading.

sets isLoading to true and apiError to null.

Params:

NameTypeAttributeDescription
oldApiDataMap *

Previous contents of data in the redux-map in question

Return:

Immutable.Map<string, any>

The new Map to insert as entry in the redux-map being updated.

public makeApiDataMapNewData(newData: *, fromList: *, noWrap: *): Immutable.Map source

import {makeApiDataMapNewData} from 'ievv_jsbase/lib/utils/reduxApiUtilities'

Util used by all action.js-files in redux/api/*. This is used to format data to store in redux-state-map when an api-call is successful.

The given newData is inserted as an ImmutableMap data.

sets isLoading to false, apiError to null and timestamp to now.

Params:

NameTypeAttributeDescription
newData *

{Object} the object returned from the api which should be formated for insertion in the redux-state-map. If fromList is true this should be an iterable.

fromList *

{boolean} if true, make an ImmutableList of the given data instead of ImmutableMap

noWrap *

{boolean} if true, newData will not be wrapped in ImmutableMap or ImmutableList. Only use this if the data you are setting is already an ImmutableMap or ImmutableList!

Return:

Immutable.Map

newly formatted ImmutableMap ready to be placed in redux-state-map

public makeCustomError(name: string, extendsError: Error): Error source

import makeCustomError from 'ievv_jsbase/lib/makeCustomError'

Make a custom error "class".

Makes an old style prototype based error class.

Params:

NameTypeAttributeDescription
name string

The name of the error class.

extendsError Error

An optional Error to extend. Defaults to Error. Can be a built in error or a custom error created by this function.

Return:

Error

The created error class.

Example:

Typical usage
// In myerrors.js
export let MyCustomError = makeCustomError('MyCustomError');

// Using the error
import {MyCustomError} from './myerrors';
throw new MyCustomError('The message');
Throwing the error - complete example
try {
    throw new MyCustomError('The message', {
         code: 'stuff_happened',
         details: {
             size: 10
         }
    });
} catch(e) {
    if(e instanceof MyCustomError) {
        console.error(`${e.toString()} -- Code: ${e.code}. Size: ${e.details.size}`);
    }
}
Define an error that extends Error
let NotFoundError = makeCustomError('NotFoundError');
// error instanceof NotFoundError === true
// error instanceof Error === true
Define an error that extends a built in error
let MyValueError = makeCustomError('MyValueError', TypeError);
let error = new MyValueError();
// error instanceof MyValueError === true
// error instanceof TypeError === true
// error instanceof Error === true
Define an error that extends another custom error
let MySuperError = makeCustomError('MySuperError', TypeError);
let MySubError = makeCustomError('MySubError', MySuperError);
let error = new MySubError();
// error instanceof MySubError === true
// error instanceof MySuperError === true
// error instanceof TypeError === true
// error instanceof Error === true

public makeHtmlEndTag(tagName: string): string source

import {makeHtmlEndTag} from 'ievv_jsbase/lib/html/utils'

Make a HTML end tag.

Handles self-closing tags automatically.

Params:

NameTypeAttributeDescription
tagName string

Tag name.

Return:

string

The HTML end tag.

public makeHtmlStartTag(tagName: string, attributes: {}): string source

import {makeHtmlStartTag} from 'ievv_jsbase/lib/html/utils'

Make a HTML start tag.

Handles self-closing tags automatically.

Params:

NameTypeAttributeDescription
tagName string

Tag name.

attributes {}

Object mapping attribute names to values.

Return:

string

The HTML start tag.

public makeImmutableOrderedMapFromValueArray(valueArray: *, valueKey: *): Immutable.OrderedMap<string, Immutable.Map<string, string>> source

import {makeImmutableOrderedMapFromValueArray} from 'ievv_jsbase/lib/utils/reduxApiUtilities'

Used for the internal OrderedMap from makeTypeMappedReduxMapFromApiData, and should be used for other type-lists from api.

The only required fieldname on the api-data is value, which will be used as key in the ImmutableOrderedMap

Builds a structure like this: ImmutableOrderedMap({ <valueKey>: ImmutableMap({ label: <some label>, description: <some description>, <otherfield>: <otherfieldkey>, ... }) })

from input-data formatted like this: [ { "value": "<valueKey>", "label": "<some label>", "description": "<some description>", <otherfield>: <otherfieldkey>, ... } ]

Params:

NameTypeAttributeDescription
valueArray *

See input-data doc above

valueKey *

default to 'value' as in example above. can be set to any valid value. note that this is NOT validated or enforced in any way

Return:

Immutable.OrderedMap<string, Immutable.Map<string, string>>

see example above

public makeTypeMappedReduxMapFromApiData(apiResponseBodydata: *): Immutable.Map<string, Immutable.OrderedMap<string, Immutable.Map<string, string>>> source

import {makeTypeMappedReduxMapFromApiData} from 'ievv_jsbase/lib/utils/reduxApiUtilities'

Used for apis like nodePaymentSubscriptionTypes and nodeMembershipTypes.

Builds a structure like this: ImmutableMap({ <nodeType>: ImmutableOrderedMap({ <valueKey>: ImmutableMap({ label: <some label>, description: <some description>, <otherfield>: <otherfieldkey>, ... }) }) })

Expects apiResponseBodydata to be formatted like this: { "<nodeType>": [ { "value": "<valueKey>", "label": "<some label>", "description": "<some description>", <otherfield>: <otherfieldkey>, ... } ] }

Params:

NameTypeAttributeDescription
apiResponseBodydata *

bodydata from a response. This response has to be formatted correctly.

Return:

Immutable.Map<string, Immutable.OrderedMap<string, Immutable.Map<string, string>>>

See example in doc above

public onDocumentReady(callback: *) source

import onDocumentReady from 'ievv_jsbase/lib/utils/onDocumentReady'

Wrap a callback that is called when the document is done loading.

Params:

NameTypeAttributeDescription
callback *

A callback function. Called without any arguments.

public typeDetect(obj: *): string source

import typeDetect from 'ievv_jsbase/lib/utils/typeDetect'

Detect the type of an object and return the result as a string.

Handles the following types:

  • null (returned as "null").
  • undefined (returned as "undefined").
  • Number (returned as "number").
  • Boolean (returned as "boolean").
  • String (returned as "string").
  • Array (returned as "array").
  • Map (returned as "map").
  • Set (returned as "set").
  • Function (returned as "function").
  • Object (returned as "object").

We do not handle classes - they are returned as "function". We could handle classes, but for Babel classes that will require a fairly expensive and error prone regex.

Params:

NameTypeAttributeDescription
obj *

An object to detect the type for.

Return:

string