tools

tools

This module contains generic utility functions which are used heavily internally.

Methods

<static> baseUri(document) → {string}

Returns the base url directory for a given document. This value can be used to create URLs relative to a document. It is guaranteed to have a trailing slash.
Parameters:
Name Type Description
document HTMLDocument
Returns:
Type
string

<static> beget(prototype) → {Object}

Creates a new object with the given [[Prototype]].
Parameters:
Name Type Description
prototype Object The [[Prototype]].
Returns:
The new object.
Type
Object

<static> descriptorAccessor(get, set, enumerable, configurable) → {Object}

Creates a property descriptor for an accessor property.
Parameters:
Name Type Argument Description
get Function The getter function
set Function The setter function
enumerable boolean <optional>
Whether the property should be enumerable
configurable boolean <optional>
Whether the property should be configurable
Returns:
A property descriptor suitable for Object.create(), Object.defineProperty() and Object.defineProperties().
Type
Object

<static> descriptorData(value, writable, enumerable, configurable) → {Object}

Creates a property descriptor for a data property.
Parameters:
Name Type Argument Description
value any The initial value
writable boolean <optional>
Whether the property should be writable
enumerable boolean <optional>
Whether the property should be enumerable
configurable boolean <optional>
Whether the property should be configurable
Returns:
A property descriptor suitable for Object.create(), Object.defineProperty() and Object.defineProperties().
Type
Object

<static> extractUnit(any) → {string}

Parse a given unit string into the amount and unit
Parameters:
Name Type Description
any any Anything that can be converted to a string. E.g. '7deg', ['50%']
Returns:
unit
Type
string

<static> forEach(array, callback, thisArg) → {Array}

A generic `Array#forEach` like method. Callbacks may terminate the loop by explicitly returning `false`.
Parameters:
Name Type Description
array Array The array to iterate over.
callback Function The function called per iteration.
thisArg Object The `this` binding for the callback function.
Returns:
Returns the array iterated over.
Type
Array

<static> forOwn(object, callback, thisArg) → {Object}

Iterates over an object's own properties, executing the `callback` for each. Callbacks may terminate the loop by explicitly returning `false`.
Parameters:
Name Type Description
object Object The object to iterate over.
callback Function The function executed per own property.
thisArg Object The `this` binding for the callback function.
Returns:
Returns the object iterated over.
Type
Object

<static> getter(propertyName) → {Function}

Creates a simple getter. The function returned will return the property specified from the respective context (`this`) on invokation.
Parameters:
Name Type Description
propertyName string The name of the property to look up.
Returns:
Type
Function

<static> hitch(thisArg, A) → {Function}

Returns a function that will only ever execute with a specified `this` binding.
Parameters:
Name Type Argument Description
thisArg Object The `this` binding for the `fn` function. If `fn` is a string, `thisArg` is also the object containing `fn`.
A Function | string function to be bound to `thisArg`, or the name of the method in `thisArg` to be bound.
fixedArgs... <optional>
Any number of parameters. Will be passed to the bound function before any other parameters.
Returns:
The bound function.
Type
Function

<static> indexOf(array, value, fromIndex) → {number}

Performs a strict equality search for the given `value` and returns the index it is found at else `-1`.
Parameters:
Name Type Argument Default Description
array Array The array to iterate over.
value any The value to search for.
fromIndex number <optional>
0 The index to start searching from.
Returns:
The index of the matched value or `-1`.
Type
number

<static> isArray(value) → {boolean}

Checks if a value has an internal `[[Class]]` of Array.
Parameters:
Name Type Description
value any The value to check.
Returns:
Returns `true` if the value has an internal [[Class]] of Array, else `false`.
Type
boolean

<static> keys(object) → {Array}

Returns an array of all own enumerable property names.
Parameters:
Name Type Description
object Object The object to iterate over.
Returns:
An array of property names.
Type
Array

<static> map(array, callback, thisArg) → {Array}

A generic `Array#map` like method.
Parameters:
Name Type Description
array Array The array to iterate over.
callback Function The function called per iteration.
thisArg Object The `this` binding for the callback function.
Returns:
A new array of values returned by the callback.
Type
Array

<static> mixin(destination) → {Object}

Copies all enumerable properties from source object(s) to the destination object. Multiple source objects are supported.
Parameters:
Name Type Argument Description
destination Object The object to copy properties to.
source, .. Object <optional>
The object(s) to copy properties from.
Returns:
The destination object.
Type
Object

<static> offset(element) → {Object}

Gets absolute offset of the given DOM element.
Parameters:
Name Type Description
element Element The DOM element.
Returns:
An object with the absolute offset left and top values.
Type
Object

<static> parseAngle(angle) → {number}

Parses the angle string to radians https://developer.mozilla.org/en-US/docs/CSS/angle
Parameters:
Name Type Description
angle number | string The angle/unit string
Returns:
The angle in radians
Type
number

<static> reduce(array, callback, accumulator) → {any}

A generic `Array#reduce` like method.
Parameters:
Name Type Description
array Array The array to iterate over.
callback Function The function called per iteration.
accumulator any Initial value of the accumulator.
Returns:
The accumulator.
Type
any

<static> removeValueFromArray(array, value) → {Array}

Removes all occurrences of a value within an array. Can also be used to remove gaps from an array.
Parameters:
Name Type Argument Default Description
array Array The array to remove values from
value <optional>
undefined The value to remove from the array
Returns:
The array passed in.
Type
Array