Global

Methods

compactArray(arr) → {array}

Eliminates null/undefined values from array (flow compliant)
Parameters:
Name Type Description
arr array Source array
Source:
Returns:
Type
array

debounce(fn, time) → {function}

Reduces multiple function calls, which are fired in quick succession to a single function call (i.e. to reduce function calls on scroll events.
Parameters:
Name Type Description
fn function Function to debounce
time number Time to wait until function is called - will be reset on every invocation of the debounced function in the given timeframe.
Source:
Returns:
Debounced function
Type
function

first(arr) → {element}

Returns the first element of an array
Parameters:
Name Type Description
arr array Array
Source:
Returns:
First element of the array
Type
element

generateMarkup(markup) → {object}

Given a string containing markup renders the markup into a React component. This needs to be called inside the 'dangerouslySetInnerHTML' prop to work.
Parameters:
Name Type Description
markup string String containing HTML
Source:
Returns:
Object which is transformed to innerHTML by dangerouslySetInnerHTML
Type
object

immutablyDeleteProperty(obj, property) → {object}

Removes a property from an object and returns a new object. The original object is not altered.
Parameters:
Name Type Description
obj object Object to delete property from
property string property to delete
Source:
Returns:
new object without the specified property
Type
object

insertInArrIf(condition, value) → {array}

Conditionally inserts a value into an array. To make practical use of this funciton inside an array you have to use the array spread operator on the result.
Parameters:
Name Type Description
condition boolean condition to determine if property should be inserted
value any value to insert
Source:
Returns:
either empty or containing the new value
Type
array

insertInObjIf(condition, property, value) → {object}

Conditionally inserts a key-value pair into an object. To make practical use of this function inside an object you have to use the object spread operator on the result
Parameters:
Name Type Description
condition boolean condition to determine if property should be inserted
property string property to insert
value any property value
Source:
Returns:
new object either empty or containing the inserted property only
Type
object

last(arr) → {element}

Returns the last element of an array
Parameters:
Name Type Description
arr array Array
Source:
Returns:
Last element of the array
Type
element

objArrayToKeyedObj(arr, property) → {object}

Converts an array of objects to an object keyed by a specific property, where each key is the value of the property and the value is the actual object.
Parameters:
Name Type Description
arr array Array containing objects each containing a specific property
property string Property to key objects by
Source:
Returns:
Type
object

objToArray(obj) → {array}

Converts an object to an array of its values. This is basically the same as Object.values(). The latter sometimes has some unintended effects on flow, which is why we currently fallback to this helper.
Parameters:
Name Type Description
obj object Object to convert
Source:
Returns:
Array of values
Type
array

partial(fn) → {function}

Function partially apply arguments to a function. (Left to right)
Parameters:
Name Type Description
fn function Function to apply to.
...args array Arguments to apply
Source:
Returns:
Partially applied function
Type
function

pipe(f1) → {function}

Pipes the output of functions as arguments into the next function (from left to right).
Parameters:
Name Type Description
f1 function first function to call
...fns array Additional functions to pipe through
Source:
Returns:
Composed function
Type
function
Example
const splitString = str => str.split('')
const getLength = arr => arr.length
pipe(splitString, getLength)('Hello world') // => 11

range(start, end) → {array}

Creates an array containing a range of numbers.
Parameters:
Name Type Description
start number First number of the range, array index 0
end number Endindex, not included inside the resulting array
Source:
Returns:
array of numbers
Type
array
Example
range(2, 6) // => [2, 3, 4, 5]

sortByProperty(property, order, list) → {array}

Given an array of objects sorts the array by the given property of each object in either ascending or descending order.
Parameters:
Name Type Description
property string Property to sort by
order number Should be either 1 or -1
list array list of objects to sort
Source:
Returns:
Sorted list
Type
array

throttle(fn, time, context) → {function}

Makes sure that a given function is only called once in a specified timeframe.
Parameters:
Name Type Description
fn function Function to call after timeout
time number Timeout in ms
context object Useful for throttling object methods
Source:
Returns:
Throttled function
Type
function

toggleClass(node, className, condition) → {void}

Toggles the class on a DOM node by a given condition
Parameters:
Name Type Description
node HTMLElement Domnode to add/remove class to/from
className string Class to add/remove
condition boolean Expression that resolves to true/false
Source:
Returns:
Type
void