Module: utils

This is an internal module.
Source:

Members

(inner) deepCompare

Compare two objects for equality. The objects MUST NOT have circular references.
Source:

Methods

(static) checkObjectHasKeys(obj, keys)

Checks that the given object has the specified keys.
Parameters:
Name Type Description
obj Object The object to check.
keys Array.<string> The list of keys that 'obj' must have.
Source:
Throws:
If the object is missing keys.

(static) checkObjectHasNoAdditionalKeys(obj, allowedKeys)

Checks that the given object has no extra keys other than the specified ones.
Parameters:
Name Type Description
obj Object The object to check.
allowedKeys Array.<string> The list of allowed key names.
Source:
Throws:
If there are extra keys.

(static) deepCopy(obj) → {Object}

Deep copy the given object. The object MUST NOT have circular references and MUST NOT have functions.
Parameters:
Name Type Description
obj Object The object to deep copy.
Source:
Returns:
A copy of the object without any references to the original.
Type
Object

(static) encodeParams(params) → {string}

Encode a dictionary of query parameters.
Parameters:
Name Type Description
params Object A dict of key/values to encode e.g. {"foo": "bar", "baz": "taz"}
Source:
Returns:
The encoded string e.g. foo=bar&baz=taz
Type
string

(static) encodeUri(pathTemplate, variables) → {string}

Encodes a URI according to a set of template variables. Variables will be passed through encodeURIComponent.
Parameters:
Name Type Description
pathTemplate string The path with template variables e.g. '/foo/$bar'.
variables Object The key/value pairs to replace the template variables with. E.g. { "$bar": "baz" }.
Source:
Returns:
The result of replacing all template variables e.g. '/foo/baz'.
Type
string

(static) extend(target, …source) → {Object}

Copy properties from one object to another. All enumerable properties, included inherited ones, are copied. This is approximately equivalent to ES6's Object.assign, except that the latter doesn't copy inherited properties.
Parameters:
Name Type Attributes Description
target Object The object that will receive new properties
source Object <repeatable>
Objects from which to copy properties
Source:
Returns:
target
Type
Object

(static) filter(array, fn) → {Array}

Applies a filter function to the given array.
Parameters:
Name Type Description
array Array The array to apply the function to.
fn function The function that will be invoked for each element in the array. It should return true to keep the element. The function signature looks like fn(element, index, array){...}.
Source:
Returns:
A new array with the results of the function.
Type
Array

(static) findElement(array, fn, reverse) → {*}

The findElement() method returns a value in the array, if an element in the array satisfies (returns true) the provided testing function. Otherwise undefined is returned.
Parameters:
Name Type Description
array Array The array.
fn function Function to execute on each value in the array, with the function signature fn(element, index, array)
reverse boolean True to search in reverse order.
Source:
Returns:
The first value in the array which returns true for the given function.
Type
*

(static) forEach(array, fn)

Invoke a function for each item in the array.
Parameters:
Name Type Description
array Array The array.
fn function The function to invoke for each element. Has the function signature fn(element, index).
Source:

(static) inherits(ctor, superCtor)

Inherit the prototype methods from one constructor into another. This is a port of the Node.js implementation with an Object.create polyfill.
Parameters:
Name Type Description
ctor function Constructor function which needs to inherit the prototype.
superCtor function Constructor function to inherit prototype from.
Source:

(static) isArray(value) → {boolean}

Checks if the given thing is an array.
Parameters:
Name Type Description
value * The thing to check.
Source:
Returns:
True if it is an array.
Type
boolean

(static) isFunction(value) → {boolean}

Checks if the given thing is a function.
Parameters:
Name Type Description
value * The thing to check.
Source:
Returns:
True if it is a function.
Type
boolean

(static) keys(obj) → {Array.<string>}

Get the keys for an object. Same as Object.keys().
Parameters:
Name Type Description
obj Object The object to get the keys for.
Source:
Returns:
The keys of the object.
Type
Array.<string>

(static) map(array, fn) → {Array}

Applies a map function to the given array.
Parameters:
Name Type Description
array Array The array to apply the function to.
fn function The function that will be invoked for each element in the array with the signature fn(element){...}
Source:
Returns:
A new array with the results of the function.
Type
Array

(static) removeElement(array, fn, reverse) → {boolean}

The removeElement() method removes the first element in the array that satisfies (returns true) the provided testing function.
Parameters:
Name Type Description
array Array The array.
fn function Function to execute on each value in the array, with the function signature fn(element, index, array). Return true to remove this element and break.
reverse boolean True to search in reverse order.
Source:
Returns:
True if an element was removed.
Type
boolean

(static) runPolyfills()

Run polyfills to add Array.map and Array.filter if they are missing.
Source:

(static) values(obj) → {Array.<*>}

Get the values for an object.
Parameters:
Name Type Description
obj Object The object to get the values for.
Source:
Returns:
The values of the object.
Type
Array.<*>