> **Warning**: The docs are outdated since `v0.31.0` as the `jsdoc` library cannot parse `@type` definition properly. Until I find a workaround, please trust the types more than this file. # API Docs - [Animation](#animation) - [Array](#array) - [Color](#color) - [Conversion](#conversion) - [Dom](#dom) - [Event](#event) - [Format](#format) - [Functional Programming](#functional-programming) - [Geometry](#geometry) - [Index](#index) - [Map](#map) - [Math](#math) - [Object](#object) - [Other](#other) - [Sorting](#sorting) - [String](#string) - [Timing](#timing) - [Type Checking](#type-checking) - [Vector](#vector) --- # Animation [⬆️ Back to the top](#api-docs) ## Constants
cubicInnumber

Cubic in easing function

cubicInOutnumber

Cubic in and out easing function

cubicOutnumber

Cubic out easing function

interpolateNumbernumber

Linearly interpolate two numbers

interpolateVectorarray

Lineraly interpolate a numerical vector

linearnumber

Linear easing function

quadInnumber

Quadratic in easing function

quadInOutnumber

Quadratic in and out easing function

quadOutnumber

Quadratic out easing function

quartInnumber

Quartic in easing function

quartInOutnumber

Quartic out easing function

quartOutnumber

Quartic in and out easing function

quintInnumber

Quintic in easing function

quintInOutnumber

Quintic out easing function

quintOutnumber

Quintic in and out easing function

## cubicIn ⇒ number Cubic in easing function **Kind**: global constant **Returns**: number - The eased time | Param | Type | Description | | ----- | ------------------- | ---------------------------------------------------------------------------------------------- | | t | number | The input time to be eased. Must be in [0, 1] where `0` refers to the start and `1` to the end | --- ## cubicInOut ⇒ number Cubic in and out easing function **Kind**: global constant **Returns**: number - The eased time | Param | Type | Description | | ----- | ------------------- | ---------------------------------------------------------------------------------------------- | | t | number | The input time to be eased. Must be in [0, 1] where `0` refers to the start and `1` to the end | --- ## cubicOut ⇒ number Cubic out easing function **Kind**: global constant **Returns**: number - The eased time | Param | Type | Description | | ----- | ------------------- | ---------------------------------------------------------------------------------------------- | | t | number | The input time to be eased. Must be in [0, 1] where `0` refers to the start and `1` to the end | --- ## interpolateNumber ⇒ number Linearly interpolate two numbers **Kind**: global constant **Returns**: number - The interpolated number | Param | Type | Description | | ----- | ------------------- | ---------------------------------------------------------------------------------------------------------- | | a | number | The start value | | b | number | The end value | | p | number | The interpolation progress. Must be in [0, 1] where `0` refers to the start value and `1` to the end value | --- ## interpolateVector ⇒ array Lineraly interpolate a numerical vector **Kind**: global constant **Returns**: array - The interpolated vector | Param | Type | Description | | ----- | ------------------- | ------------------------------------------------------------------------------------------------------------ | | a | array | The start vector | | b | array | The end vector | | p | number | The interpolation progress. Must be in [0, 1] where `0` refers to the start vector and `1` to the end vector | --- ## linear ⇒ number Linear easing function **Kind**: global constant **Returns**: number - Same as the input | Param | Type | Description | | ----- | ------------------- | ---------------------------------------------------------------------------------------------- | | t | number | The input time to be eased. Must be in [0, 1] where `0` refers to the start and `1` to the end | --- ## quadIn ⇒ number Quadratic in easing function **Kind**: global constant **Returns**: number - The eased time | Param | Type | Description | | ----- | ------------------- | ---------------------------------------------------------------------------------------------- | | t | number | The input time to be eased. Must be in [0, 1] where `0` refers to the start and `1` to the end | --- ## quadInOut ⇒ number Quadratic in and out easing function **Kind**: global constant **Returns**: number - The eased time | Param | Type | Description | | ----- | ------------------- | ---------------------------------------------------------------------------------------------- | | t | number | The input time to be eased. Must be in [0, 1] where `0` refers to the start and `1` to the end | --- ## quadOut ⇒ number Quadratic out easing function **Kind**: global constant **Returns**: number - The eased time | Param | Type | Description | | ----- | ------------------- | ---------------------------------------------------------------------------------------------- | | t | number | The input time to be eased. Must be in [0, 1] where `0` refers to the start and `1` to the end | --- ## quartIn ⇒ number Quartic in easing function **Kind**: global constant **Returns**: number - The eased time | Param | Type | Description | | ----- | ------------------- | ---------------------------------------------------------------------------------------------- | | t | number | The input time to be eased. Must be in [0, 1] where `0` refers to the start and `1` to the end | --- ## quartInOut ⇒ number Quartic out easing function **Kind**: global constant **Returns**: number - The eased time | Param | Type | Description | | ----- | ------------------- | ---------------------------------------------------------------------------------------------- | | t | number | The input time to be eased. Must be in [0, 1] where `0` refers to the start and `1` to the end | --- ## quartOut ⇒ number Quartic in and out easing function **Kind**: global constant **Returns**: number - The eased time | Param | Type | Description | | ----- | ------------------- | ---------------------------------------------------------------------------------------------- | | t | number | The input time to be eased. Must be in [0, 1] where `0` refers to the start and `1` to the end | --- ## quintIn ⇒ number Quintic in easing function **Kind**: global constant **Returns**: number - The eased time | Param | Type | Description | | ----- | ------------------- | ---------------------------------------------------------------------------------------------- | | t | number | The input time to be eased. Must be in [0, 1] where `0` refers to the start and `1` to the end | --- ## quintInOut ⇒ number Quintic out easing function **Kind**: global constant **Returns**: number - The eased time | Param | Type | Description | | ----- | ------------------- | ---------------------------------------------------------------------------------------------- | | t | number | The input time to be eased. Must be in [0, 1] where `0` refers to the start and `1` to the end | --- ## quintOut ⇒ number Quintic in and out easing function **Kind**: global constant **Returns**: number - The eased time | Param | Type | Description | | ----- | ------------------- | ---------------------------------------------------------------------------------------------- | | t | number | The input time to be eased. Must be in [0, 1] where `0` refers to the start and `1` to the end | --- # Array [⬆️ Back to the top](#api-docs) ## Constants
array2dTransposearray

Transpose a nested 2D array

clearArrayarray

Clear an array without while keeping it's reference

hasSameElementsboolean

Check if two arrays contain the same elements

uniquearray

Return unique values of an array

## array2dTranspose ⇒ array Transpose a nested 2D array **Kind**: global constant **Returns**: array - The transposed 2D nested matrix-like array | Param | Type | Description | | ------ | ------------------ | ------------------------------------------------- | | matrix | array | The matrix-liked 2D nested array to be transposed | --- ## clearArray ⇒ array Clear an array without while keeping it's reference **Kind**: global constant **Returns**: array - The array itself | Param | Type | Description | | ----- | ------------------ | ------------------- | | a | array | Array to be cleared | --- ## hasSameElements ⇒ boolean Check if two arrays contain the same elements **Kind**: global constant **Returns**: boolean - If `true` the two arrays contain the same elements | Param | Type | Description | | ----- | ------------------ | ------------ | | a | array | First array | | b | array | Second array | --- ## unique ⇒ array Return unique values of an array **Kind**: global constant **Returns**: array - Array with unique values | Param | Type | Description | | ----- | ------------------ | ----------- | | a | array | Input array | --- # Color [⬆️ Back to the top](#api-docs) ## Constants
decToRgbnumber

Convert a HEX string to its decimal representation

hexToDecnumber

Convert a HEX string to its decimal representation

hexToRgbaArrayarray

Convert a HEX-encoded color to an RGBA-encoded color

hexToRgbArrayarray

Convert a HEX-encoded color to an RGB-encoded color

rgbaStrToRgbaArray

Same as rgbStrToRgbArray()

rgbStrToDecnumber

Convert RGB string to its decimal representation

rgbStrToRgbArraynumber

Convert RGB(A) string to its array representation

rgbToHexstring

Convert RGB values to a HEX string

toRgbaArray

Convert a color to an RGBA color

## decToRgb ⇒ number Convert a HEX string to its decimal representation **Kind**: global constant **Returns**: number - Decimal representation | Param | Type | Description | | ----- | ------------------- | ----------- | | hex | string | HEX string | --- ## hexToDec ⇒ number Convert a HEX string to its decimal representation **Kind**: global constant **Returns**: number - Decimal representation | Param | Type | Description | | ----- | ------------------- | ----------- | | hex | string | HEX string | --- ## hexToRgbaArray ⇒ array Convert a HEX-encoded color to an RGBA-encoded color **Kind**: global constant **Returns**: array - Triple holding the RGBA values. | Param | Type | Description | | --------- | -------------------- | ----------------------------------------------------------------- | | hex | string | HEX-encoded color string. | | normalize | boolean | If `true` the returned RGBA values will be normalized to `[0,1]`. | --- ## hexToRgbArray ⇒ array Convert a HEX-encoded color to an RGB-encoded color **Kind**: global constant **Returns**: array - Triple holding the RGB values. | Param | Type | Description | | --------- | -------------------- | ---------------------------------------------------------------- | | hex | string | HEX-encoded color string. | | normalize | boolean | If `true` the returned RGB values will be normalized to `[0,1]`. | --- ## rgbaStrToRgbaArray Same as `rgbStrToRgbArray()` **Kind**: global constant --- ## rgbStrToDec ⇒ number Convert RGB string to its decimal representation **Kind**: global constant **Returns**: number - Decimal representation | Param | Type | Description | | ------ | ------------------- | ----------- | | rgbStr | string | RGB string | --- ## rgbStrToRgbArray ⇒ number Convert RGB(A) string to its array representation **Kind**: global constant **Returns**: number - RGB(A) array | Param | Type | Description | | ------ | ------------------- | ------------- | | rgbStr | string | RGB(A) string | --- ## rgbToHex ⇒ string Convert RGB values to a HEX string **Kind**: global constant **Returns**: string - HEX string | Param | Type | Description | | ----- | ------------------- | --------------- | | r | number | Red component | | g | number | Green component | | b | number | Blue component | --- ## toRgbaArray Convert a color to an RGBA color **Kind**: global constant **Return{array}**: Quadruple defining an RGBA color. | Param | Type | Description | | --------- | -------------------- | ----------------------------------------------------------------- | | color | \* | Color to be converted. Currently supports: HEX, RGB, or RGBA. | | normalize | boolean | If `true` the returned RGBA values will be normalized to `[0,1]`. | --- # Conversion [⬆️ Back to the top](#api-docs) ## iteratorToArray ⇒ array Store the values of an iterator in an array. This code is about 9x faster than `Array.from()` **Kind**: global constant **Returns**: array - The array with the map keys | Param | Type | Description | | ----- | ---------------- | -------------------------------------------------- | | map | map | The map whose keys are to be converted to an array | --- # Dom [⬆️ Back to the top](#api-docs) ## Constants
addClass

Method to add a class name to an HTML or SVG element.

createHtmlByTemplatenode

Create HTML from a template string

hasClassboolean

Check if an HTML or SVG element has a certain class

isParentOfboolean

Test whether a DOM element is the parent of another DOM element.

removeAllChildren

Remove all children of a DOM node

removeClass

Remove a class from an HTML or SVG element.

removeLastChild

Remove last child of a DOM node

## addClass Method to add a class name to an HTML or SVG element. **Kind**: global constant | Param | Type | Description | | --------- | ------------------- | -------------------------------------- | | element | object | HTML or SVG element to add a class to. | | className | string | The class name to be added. | --- ## createHtmlByTemplate ⇒ node Create HTML from a template string **Kind**: global constant **Returns**: node - Root DOM element | Param | Type | Description | | -------- | ------------------- | -------------------- | | template | string | HTML template string | --- ## hasClass ⇒ boolean Check if an HTML or SVG element has a certain class **Kind**: global constant **Returns**: boolean - If `true` `element` has the class name | Param | Type | Description | | --------- | ------------------- | --------------------------------- | | element | object | HTML or SVG element to be checked | | className | string | Class name to be checked for | --- ## isParentOf ⇒ boolean Test whether a DOM element is the parent of another DOM element. **Kind**: global constant **Returns**: boolean - If `true` `parent` is a parent of `element`. | Param | Type | Description | | ------- | ------------------- | -------------------------------------------------------------- | | element | object | Potential child element. | | parent | object | Target parent element which is tested to have `el` as a child. | --- ## removeAllChildren Remove all children of a DOM node **Kind**: global constant | Param | Type | Description | | ----- | ------------------- | ----------------------------------------- | | node | object | DOM node whose children are to be removed | --- ## removeClass Remove a class from an HTML or SVG element. **Kind**: global constant | Param | Type | Description | | --------- | ------------------- | ------------------------- | | element | object | HTML or SVG element. | | className | string | Class name to be removed. | --- ## removeLastChild Remove last child of a DOM node **Kind**: global constant | Param | Type | Description | | ----- | ------------------- | ------------------------------------------ | | node | object | DOM node whose last child is to be removed | --- # Event [⬆️ Back to the top](#api-docs) ## Constants
cloneEventobject

Clone an event by invoking the source event's constructor and passing in the source event.

forwardEvent

Forward an event by cloning and dispatching it.

## cloneEvent ⇒ object Clone an event by invoking the source event's constructor and passing in the source event. **Kind**: global constant **Returns**: object - Cloned event | Param | Type | Description | | ----- | ------------------- | -------------------------- | | event | object | Source event to be cloned. | --- ## forwardEvent Forward an event by cloning and dispatching it. **Kind**: global constant | Param | Type | Description | | ------ | ------------------- | ---------------------------------- | | event | object | Event to be forwarded. | | target | object | Target HTML element for the event. | --- # Format [⬆️ Back to the top](#api-docs) ## Constants
getD3FormatSpecifierstring

Get a D3 Format specifier given the data domain.

## getD3FormatSpecifier ⇒ string Get a D3 Format specifier given the data domain **Kind**: global constant **Returns**: string - A D3 Format specifier that fits the data extent | Param | Type | Description | | ------ | ----------------------------- | --------------------------------------- | | domain | [number, number] | The domain of the data to be formatted. | --- # Functional Programming [⬆️ Back to the top](#api-docs) ## Constants
forEacharray

More flexible and applicable to other array-like data types.

maparray

The pure map function is more powerful because it can be used on data types other than Array too.

mapFilterfunction

Map and filter data in one iteration.

Combining the loops is about 7-8x faster than

pipefunction

Convenience function to compose functions

some*

Functional version of Array.forEach. More flexible and applicable to other array-like data types like NodeList.

withConstructor

Assign a constructor to the object

withForwardedMethod

Forward a method call

withProperty

Assign a property to an object

withReadOnlyProperty

Assign a read-only property to an object

withStaticProperty

Assign a static property to an object

## forEach ⇒ array More flexible and applicable to other array-like data types. **Kind**: global constant **Returns**: array - Modified array-like variable. | Param | Type | Description | | ----- | --------------------- | ----------------------------------------------------- | | f | function | Modifier function applied on every item of the array. | --- ## map ⇒ array The pure map function is more powerful because it can be used on data types other than Array too. **Kind**: global constant **Returns**: array - Mapped array | Param | Type | Description | | ----- | --------------------- | ---------------- | | f | function | Mapping function | --- ## mapFilter ⇒ function Map and filter data in one iteration. Combining the loops is about 7-8x faster than **Kind**: global constant **Returns**: function - A function that accepts a single array paremeter | Param | Type | Description | | -------- | --------------------- | ---------------- | | mapFn | function | Mapping function | | filterFn | function | Filter function | --- ## pipe ⇒ function Convenience function to compose functions **Kind**: global constant **Returns**: function - The composed function | Param | Type | Description | | ------ | --------------------- | ------------------ | | ...fns | function | Array of functions | --- ## some ⇒ \* Functional version of `Array.forEach`. More flexible and applicable to other array-like data types like `NodeList`. **Kind**: global constant **Returns**: \* - Modified array-like variable. | Param | Type | Description | | ----- | --------------------- | ----------------------------------------------------- | | f | function | Modifier function applied on every item of the array. | --- ## withConstructor Assign a constructor to the object **Kind**: global constant | Param | Type | Description | | ----------- | --------------------- | --------------------- | | constructor | function | Constructor functions | --- ## withForwardedMethod Forward a method call **Kind**: global constant | Param | Type | Description | | ----- | --------------------- | ------------------------ | | name | string | Exposed function name | | fn | function | Function to be forwarded | --- ## withProperty Assign a property to an object **Kind**: global constant | Param | Type | Description | | -------------------- | --------------------- | ------------------------------------------------------------------------------- | | name | string | Name of the property | | options | object | Option object | | options.initialValue | \* | Initial value of the property | | options.getter | function | Custom getter | | options.setter | function | Custom setter | | options.cloner | function | Clone function. Used before the value is returned. | | options.transformer | function | Value transformer. Used before a new value is set. | | options.validator | function | Validator function decides whether the new and transformed value is set or not. | --- ## withReadOnlyProperty Assign a read-only property to an object **Kind**: global constant | Param | Type | Description | | ------ | --------------------- | -------------------- | | name | string | Name of the property | | getter | function | Getter function | --- ## withStaticProperty Assign a static property to an object **Kind**: global constant | Param | Type | Description | | ----- | ------------------- | -------------------- | | name | string | Name of the property | | value | \* | Static value | --- # Geometry [⬆️ Back to the top](#api-docs) ## Constants
isPointHalfwayInRectboolean

Check if a 2D or 1D point is within a rectangle or range

isPointInPolygonboolean

From: https://wrf.ecse.rpi.edu//Research/Short_Notes/pnpoly.html

isPointInRectboolean

Check if a 2D or 1D point is within a rectangle or range

l1PointDistnumber

Identical but much faster than l1Dist([fromX, fromY], [toX, toY])

l2PointDistnumber

Identical but much faster than l2Dist([fromX, fromY], [toX, toY])

lPointDist

Identical but much faster than lDist(l)([fromX, fromY], [toX, toY])

lRectDist

L distance between a pair of rectangles

## isPointHalfwayInRect ⇒ boolean Check if a 2D or 1D point is within a rectangle or range **Kind**: global constant **Returns**: boolean - If `true` the [x,y] point is in the rectangle. | Param | Type | Description | | ----- | ------------------- | ----------------------------------- | | x | number | The point's X coordinate. | | y | number | The point's Y coordinate. | | minX | number | The rectangle's start X coordinate. | | maxX | number | The rectangle's start X coordinate. | | minY | number | The rectangle's start X coordinate. | | maxY | number | The rectangle's start X coordinate. | --- ## isPointInPolygon ⇒ boolean From: https://wrf.ecse.rpi.edu//Research/Short_Notes/pnpoly.html **Kind**: global constant **Returns**: boolean - If `true` point lies within the polygon. | Param | Type | Description | | ------- | ------------------ | ----------------------------------------- | | point | Array | Tuple of the form `[x,y]` to be tested. | | polygon | Array | 1D list of vertices defining the polygon. | --- ## isPointInRect ⇒ boolean Check if a 2D or 1D point is within a rectangle or range **Kind**: global constant **Returns**: boolean - If `true` the [x,y] point is in the rectangle. | Param | Type | Description | | ----- | ------------------- | ----------------------------------- | | x | number | The point's X coordinate. | | y | number | The point's Y coordinate. | | minX | number | The rectangle's start X coordinate. | | maxX | number | The rectangle's start X coordinate. | | minY | number | The rectangle's start X coordinate. | | maxY | number | The rectangle's start X coordinate. | --- ## l1PointDist ⇒ number Identical but much faster than `l1Dist([fromX, fromY], [toX, toY])` **Kind**: global constant **Returns**: number - L1 distance | Param | Type | Description | | ----- | ------------------- | -------------------------------- | | fromX | number | X coordinate of the first point | | fromY | number | Y coordinate of the first point | | toX | number | X coordinate of the second point | | toY | number | Y coordinate of the first point | --- ## l2PointDist ⇒ number Identical but much faster than `l2Dist([fromX, fromY], [toX, toY])` **Kind**: global constant **Returns**: number - L2 distance | Param | Type | Description | | ----- | ------------------- | -------------------------------- | | fromX | number | X coordinate of the first point | | fromY | number | Y coordinate of the first point | | toX | number | X coordinate of the second point | | toY | number | Y coordinate of the first point | --- ## lPointDist Identical but much faster than `lDist(l)([fromX, fromY], [toX, toY])` **Kind**: global constant | Param | Type | Description | | ----- | ------------------- | -------------------- | | l | number | Defines the Lp space | --- ## lRectDist L distance between a pair of rectangles **Kind**: global constant | Param | Type | Description | | ----- | ------------------- | -------------------- | | l | number | Defines the Lp space | --- # Index [⬆️ Back to the top](#api-docs) # Map [⬆️ Back to the top](#api-docs) # Math [⬆️ Back to the top](#api-docs) ## Constants
clampNumber

About 18% faster than Math.max(min, Math.min(max, value))

identity*

Identity function

isCloseboolean

Test if two floats are close given some precision

## clamp ⇒ Number About 18% faster than `Math.max(min, Math.min(max, value))` **Kind**: global constant **Returns**: Number - Clamped value | Param | Type | Description | | ----- | ------------------- | ------------------- | | value | Number | Value to be clamped | | min | Number | Min value | | max | Number | Max value | --- ## identity ⇒ \* Identity function **Kind**: global constant **Returns**: \* - `x` | Param | Type | Description | | ----- | --------------- | ----------------- | | x | \* | Any kind of value | --- ## isClose ⇒ boolean Test if two floats are close given some precision **Kind**: global constant **Returns**: boolean - If `true` the difference between the floats is less than 10^-precision | Param | Type | Description | | --------- | ------------------- | --------------------------------- | | a | number | First float | | b | number | Second float | | precision | number | Number of decimal places to check | --- # Object [⬆️ Back to the top](#api-docs) ## Constants
deepCloneobject

Deep clone an object.

extendobject

Extend an object with another object.

updateobject

Update the target object by the source object. Besides extending that target object, properties that are not present in the source object.

## deepClone ⇒ object Deep clone an object. **Kind**: global constant **Returns**: object - Cloned `source` object. | Param | Type | Description | | ------ | ------------------- | -------------------- | | source | object | Object to be cloned. | --- ## extend ⇒ object Extend an object with another object. **Kind**: global constant **Returns**: object - Cloned `source` object | Param | Type | Description | | ------ | ------------------- | --------------------------------------------------------------- | | target | object | Target object or `undefined` if a new object should be created. | | source | object | Object to be cloned. | --- ## update ⇒ object Update the target object by the source object. Besides extending that target object, properties that are not present in the source object. **Kind**: global constant **Returns**: object - Cloned `source` object | Param | Type | Description | | ------ | ------------------- | --------------------------------------------------------------- | | target | object | Target object or `undefined` if a new object should be created. | | source | object | Object to be cloned. | --- # Other [⬆️ Back to the top](#api-docs) ## Constants
createWorkerWorker

Create a worker from a function

noop

Synonym for toVoid() because it's a convention

toVoidundefined

An adventure into the void!

## createWorker ⇒ Worker Create a worker from a function **Kind**: global constant **Returns**: Worker - Worker function | Param | Type | Description | | ----- | --------------------- | ----------------------------------- | | fn | function | Function to be turned into a worker | --- ## noop Synonym for `toVoid()` because it's a convention **Kind**: global constant --- ## toVoid ⇒ undefined An adventure into the void! **Kind**: global constant **Returns**: undefined - The explorers find nothing but void. --- # Sorting [⬆️ Back to the top](#api-docs) ## Constants
argSortarray

Return a list of indices sorted by the array

sortPosarray

Return the sort position of each element in an array or object

## argSort ⇒ array Return a list of indices sorted by the array **Kind**: global constant **Returns**: array - Array of indices sorted by the values | Param | Type | Description | | ---------- | --------------------- | ---------------------------------- | | array | array | Array of numerical values | | comparator | function | Pairwise value comparator function | **Example** ```js const X = [9, 5, 11, -1, 0]; const sortedIdx = argSort(X); // >> [3, 4, 1, 0, 2] // I.e., the smallest element is X[sortedIdx[0]] == -1 ``` --- ## sortPos ⇒ array Return the sort position of each element in an array or object **Kind**: global constant **Returns**: array - Array of the sorted value positions | Param | Type | Description | | ---------- | --------------------- | ---------------------------------- | | array | array | Array of numerical values | | comparator | function | Pairwise value comparator function | **Example** ```js let array = [9, 5, 11, -1, 0]; let pos = sortPos(array); // >> [3, 2, 4, 0, 1] // I.e., the first element of `array` is at position pos[0] == 3 let object = { 1: 9, 2: 5, 11: 11, 100: -1, 999: 0 }; let pos = sortPos(object); // >> { 1: 3, 2: 2, 11: 4, 100: 0, 999: 1 } // I.e., element `999` of `object` is at position pos[999] == 1 ``` --- # String [⬆️ Back to the top](#api-docs) ## Constants
nthIndexOfnumber

FInd the nth instance of the query string

randomStringstring

Create a random string from some alphabet

## nthIndexOf ⇒ number FInd the nth instance of the query string **Kind**: global constant **Returns**: number - Index of the nth query string or -1 | Param | Type | Description | | ----- | ------------------- | ----------------------- | | str | string | String to search across | | query | string | String to search for | | n | number | nth instance | --- ## randomString ⇒ string Create a random string from some alphabet **Kind**: global constant **Returns**: string - Random string | Param | Type | Description | | -------- | ------------------- | --------------------------- | | length | number | Length of the random string | | alphabet | string | Possible characters | --- # Timing [⬆️ Back to the top](#api-docs) ## Constants
debouncefunction

Function calls are delayed by wait milliseconds and only one out of multiple function calls is executed.

nextAnimationFramePromise

Get a promise that resolves after the next n animation frames

throttlefunction

A throttled function will only ever be called every wait milliseconds at most.

throttleAndDebouncefunction

Throttle and debounce a function call

Throttling a function call means that the function is called at most every interval milliseconds no matter how frequently you trigger a call. Debouncing a function call means that the function is called the earliest after finalWait milliseconds wait time where the function was not called. Combining the two ensures that the function is called at most every interval milliseconds and is ensured to be called with the very latest arguments after after finalWait milliseconds wait time at the end.

The following imaginary scenario describes the behavior:

MS | throttleTime=3 and debounceTime=3

  1. y(f, 3, 3)(args1) => f(args1) called
  2. y(f, 3, 3)(args2) => call ignored due to throttling
  3. y(f, 3, 3)(args3) => call ignored due to throttling
  4. y(f, 3, 3)(args4) => f(args4) called
  5. y(f, 3, 3)(args5) => all ignored due to throttling
  6. No call => nothing
  7. No call => f(args5) called due to debouncing
timeout

Synonym for wait() because await timeout(250) reads nicer

waitPromise

Promise that resolves after some time

## debounce ⇒ function Function calls are delayed by `wait` milliseconds and only one out of multiple function calls is executed. **Kind**: global constant **Returns**: function - Debounced function | Param | Type | Description | | ----- | --------------------- | ----------------------------------------------------- | | fn | function | Function to be debounced | | wait | number | Number of milliseconds to debounce the function call. | --- ## nextAnimationFrame ⇒ Promise Get a promise that resolves after the next `n` animation frames **Kind**: global constant **Returns**: Promise - A promise that resolves after the next `n` animation frames | Param | Type | Description | | ----- | ------------------- | ---------------------------------- | | n | number | Number of animation frames to wait | --- ## throttle ⇒ function A throttled function will only ever be called every `wait` milliseconds at most. **Kind**: global constant **Returns**: function - Throttled function | Param | Type | Description | | ----- | --------------------- | ------------------------------------------ | | fn | function | Function to be throttled | | wait | number | Number of milliseconds calls are throttled | --- ## throttleAndDebounce ⇒ function Throttle and debounce a function call Throttling a function call means that the function is called at most every `interval` milliseconds no matter how frequently you trigger a call. Debouncing a function call means that the function is called the earliest after `finalWait` milliseconds wait time where the function was not called. Combining the two ensures that the function is called at most every `interval` milliseconds and is ensured to be called with the very latest arguments after after `finalWait` milliseconds wait time at the end. The following imaginary scenario describes the behavior: MS | throttleTime=3 and debounceTime=3 1. y(f, 3, 3)(args1) => f(args1) called 2. y(f, 3, 3)(args2) => call ignored due to throttling 3. y(f, 3, 3)(args3) => call ignored due to throttling 4. y(f, 3, 3)(args4) => f(args4) called 5. y(f, 3, 3)(args5) => all ignored due to throttling 6. No call => nothing 7. No call => f(args5) called due to debouncing **Kind**: global constant **Returns**: function - - Throttled and debounced function | Param | Type | Description | | -------- | -------------------- | ----------------------------------------------------------------------------- | | func | functon | Function to be throttled and debounced | | interval | number | Throttle intevals in milliseconds | | wait | number | Debounce wait time in milliseconds By default this is the same as `interval`. | --- ## timeout Synonym for `wait()` because `await timeout(250)` reads nicer **Kind**: global constant --- ## wait ⇒ Promise Promise that resolves after some time **Kind**: global constant **Returns**: Promise - Promise resolving after `msec` milliseconds | Param | Type | Description | | ----- | ------------------- | -------------------------------------------------- | | msec | number | Time in milliseconds until the promise is resolved | --- # Type Checking [⬆️ Back to the top](#api-docs) ## Constants
isArrayboolean

Test if a variable is an array

isFunctionboolean

Test if a variable is a function

isHexboolean

Tests if a string is a valid HEX color encoding

isNormFloatboolean

Tests if a number is in [0,1].

isNormFloatArrayboolean

Tests if an array consist of normalized numbers that are in [0,1] only.

isNumberboolean

Test if a variable is a number

isObjectboolean

Test if a variable is a plain object, e.g., {}

isRgbaArrayboolean

Tests if an array is encoding an RGBA color.

isRgbArrayboolean

Tests if an array is encoding an RGB color.

isRgbaStrboolean

Tests if a string is encoding an RGBA color.

isRgbStrboolean

Tests if a string is encoding an RGB color.

isStringboolean

Tests if a variable is a string

isUint8boolean

Tests if a number is an interger and in [0,255].

isUint8Arrayboolean

Tests if an array consist of Uint8 numbers only.

## isArray ⇒ boolean Test if a variable is an array **Kind**: global constant **Returns**: boolean - If `true` the variable is an array. | Param | Type | Description | | ----- | --------------- | -------------------- | | f | \* | The variable to test | --- ## isFunction ⇒ boolean Test if a variable is a function **Kind**: global constant **Returns**: boolean - If `true` the variable is a function. | Param | Type | Description | | ----- | --------------- | -------------------- | | f | \* | The variable to test | --- ## isHex ⇒ boolean Tests if a string is a valid HEX color encoding **Kind**: global constant **Returns**: boolean - If `true` the string is a valid HEX color encoding. | Param | Type | Description | | ----- | ------------------- | ------------------------- | | hex | string | HEX-encoded color string. | --- ## isNormFloat ⇒ boolean Tests if a number is in `[0,1]`. **Kind**: global constant **Returns**: boolean - If `true` the number is in `[0,1]`. | Param | Type | Description | | ----- | ------------------- | -------------------- | | x | number | Number to be tested. | --- ## isNormFloatArray ⇒ boolean Tests if an array consist of normalized numbers that are in `[0,1]` only. **Kind**: global constant **Returns**: boolean - If `true` the array contains only numbers in `[0,1]`. | Param | Type | Description | | ----- | ------------------ | ------------------ | | a | array | Array to be tested | --- ## isNumber ⇒ boolean Test if a variable is a number **Kind**: global constant **Returns**: boolean - If `true`, `x` is a number. | Param | Type | Description | | ----- | --------------- | --------------------- | | x | \* | Variable to be tested | --- ## isObject ⇒ boolean Test if a variable is a plain object, e.g., `{}` **Kind**: global constant **Returns**: boolean - If `true` the variable is a plain object. | Param | Type | Description | | ----- | --------------- | -------------------- | | o | \* | The variable to test | --- ## isRgbaArray ⇒ boolean Tests if an array is encoding an RGBA color. **Kind**: global constant **Returns**: boolean - If `true` the array hold a quadruple of normalized floats, a quadruple of Uint8s, or a triple of Uint8 and one normalized float. | Param | Type | Description | | ----- | ------------------ | ------------------ | | rgb | array | Array to be tested | --- ## isRgbArray ⇒ boolean Tests if an array is encoding an RGB color. **Kind**: global constant **Returns**: boolean - If `true` the array hold a triple of Uint8 numbers or a triple of normalized floats. | Param | Type | Description | | ----- | ------------------ | ------------------ | | rgb | array | Array to be tested | --- ## isRgbaStr ⇒ boolean Tests if a string is encoding an RGBA color. **Kind**: global constant **Returns**: boolean - If `true` the array hold a quadruple of Uint8 numbers or a quadruple of normalized floats. | Param | Type | Description | | ----- | ------------------- | ------------------- | | rgb | string | String to be tested | --- ## isRgbStr ⇒ boolean Tests if a string is encoding an RGB color. **Kind**: global constant **Returns**: boolean - If `true` the array hold a triple of Uint8 numbers or a triple of normalized floats. | Param | Type | Description | | ----- | ------------------- | ------------------- | | rgb | string | String to be tested | --- ## isString ⇒ boolean Tests if a variable is a string **Kind**: global constant **Returns**: boolean - If `true` variable is a string | Param | Type | Description | | ----- | --------------- | --------------------- | | s | \* | Variable to be tested | --- ## isUint8 ⇒ boolean Tests if a number is an interger and in `[0,255]`. **Kind**: global constant **Returns**: boolean - If `true` the number is an interger and in `[0,255]`. | Param | Type | Description | | ----- | ------------------- | -------------------- | | x | number | Number to be tested. | --- ## isUint8Array ⇒ boolean Tests if an array consist of Uint8 numbers only. **Kind**: global constant **Returns**: boolean - If `true` the array contains only Uint8 numbers. | Param | Type | Description | | ----- | ------------------ | ------------------- | | a | array | Array to be tested. | --- # Vector [⬆️ Back to the top](#api-docs) ## Constants
aggregatearray | number

Aggregate a vector using one or more aggregators. Like a multi-purpose reducer.

diffarray

Get the difference of two vectoe

l1Distarray

This is identical but much faster than lDist(1)(v, w)

l1DistByDimfunction

This is identical but faster than l1Dist(v, w)

l2Distarray

This is identical but much faster than lDist(2)(v, w)

l2DistByDimfunction

This is identical but faster than l2Dist(v, w)

l2Normnumber

This is identical but much faster than Math.hypot(...v)

lDist

L distance between a pair of vectors

maxnumber

This version is muuuch faster than Math.max(...v).

maxVectorarray

Get the max vector

meannumber

Get the mean of a vector

meanNannumber

Roughly 30% slower than mean()

meanVectorarray

Get the mean vector

mediannumber

Get the median of a vector

medianVectorarray

Get the median vector

minnumber

This version is muuuch faster than Math.min(...v) and support longer vectors than 256^2, which is a limitation of Math.min.apply(null, v).

minVectorarray

Get the min vector

modnumber

Non-negative modulo function. E.g., mod(-1, 5) === 4 while -1 % 5 === -1.

normalizearray

Normalize vector

rangearray

A function to created a range array

rangeMaparray

This is equivalent to Array(length).fill().map(mapFn) but about 60% faster

sumnumber

Get the sum of a vector while ignoring NaNs

sumVectorarray

Get the sum vector

unionIntegersarray

Get the unique union of two vectors of integers

## aggregate ⇒ array \| number Aggregate a vector using one or more aggregators. Like a multi-purpose reducer. **Kind**: global constant **Returns**: array \| number - A single or multiple aggregagted values | Param | Type | Description | | -------------- | ------------------------------------------- | --------------------------------------------------------------------------------------- | | v | array | Numerivcal vector | | aggregater | array \| function | A single or multiple aggregator functions. The aggregator functions work like reducers. | | startValue | array \| number | A single or multiple start values | | options.getter | function | A value getter | --- ## diff ⇒ array Get the difference of two vectoe **Kind**: global constant **Returns**: array - Difference vector | Param | Type | Description | | ----- | ------------------ | ----------------- | | v | array | Numerical vectors | | w | array | Numerical vectors | --- ## l1Dist ⇒ array This is identical but much faster than `lDist(1)(v, w)` **Kind**: global constant **Returns**: array - L2 distance | Param | Type | Description | | ----- | ------------------ | ------------- | | v | array | First vector | | w | array | Second vector | --- ## l1DistByDim ⇒ function This is identical but faster than `l1Dist(v, w)` **Kind**: global constant **Returns**: function - A function with the same signature as `l1Dist` | Param | Type | Description | | ----- | ------------------- | --------------------------- | | dim | number | Dimension of the input data | --- ## l2Dist ⇒ array This is identical but much faster than `lDist(2)(v, w)` **Kind**: global constant **Returns**: array - L2 distance | Param | Type | Description | | ----- | ------------------ | ------------- | | v | array | First vector | | w | array | Second vector | --- ## l2DistByDim ⇒ function This is identical but faster than `l2Dist(v, w)` **Kind**: global constant **Returns**: function - A function with the same signature as `l2Dist` | Param | Type | Description | | ----- | ------------------- | --------------------------- | | dim | number | Dimension of the input data | --- ## l2Norm ⇒ number This is identical but much faster than `Math.hypot(...v)` **Kind**: global constant **Returns**: number - L2 norm | Param | Type | Description | | ----- | ------------------ | ---------------- | | v | array | Numerical vector | --- ## lDist L distance between a pair of vectors **Kind**: global constant | Param | Type | Description | | ----- | ------------------- | -------------------------------------- | | l | array | Defines the Lp space | | dim | number | Dimension of the input data (Optional) | --- ## max ⇒ number This version is muuuch faster than `Math.max(...v)`. **Kind**: global constant **Returns**: number - The largest number | Param | Type | Description | | ----- | ------------------ | ---------------- | | v | array | Numerical vector | --- ## maxVector ⇒ array Get the max vector **Kind**: global constant **Returns**: array - Max vector | Param | Type | Description | | ----- | ------------------ | ---------------- | | m | array | Array of vectors | --- ## mean ⇒ number Get the mean of a vector **Kind**: global constant **Returns**: number - The mean | Param | Type | Description | | ----- | ------------------ | ---------------- | | v | array | Numerical vector | --- ## meanNan ⇒ number Roughly 30% slower than `mean()` **Kind**: global constant **Returns**: number - The mean | Param | Type | Description | | ----- | ------------------ | ---------------- | | v | array | Numerical vector | --- ## meanVector ⇒ array Get the mean vector **Kind**: global constant **Returns**: array - Mean vector | Param | Type | Description | | ----- | ------------------ | ---------------- | | m | array | Array of vectors | --- ## median ⇒ number Get the median of a vector **Kind**: global constant **Returns**: number - The median | Param | Type | Description | | ----- | ------------------ | ---------------- | | v | array | Numerical vector | --- ## medianVector ⇒ array Get the median vector **Kind**: global constant **Returns**: array - The median vector | Param | Type | Description | | ----- | ------------------ | ---------------- | | m | array | Array of vectors | --- ## min ⇒ number This version is muuuch faster than `Math.min(...v)` and support longer vectors than 256^2, which is a limitation of `Math.min.apply(null, v)`. **Kind**: global constant **Returns**: number - The smallest number | Param | Type | Description | | ----- | ------------------ | ---------------- | | v | array | Numerical vector | --- ## minVector ⇒ array Get the min vector **Kind**: global constant **Returns**: array - Min vector | Param | Type | Description | | ----- | ------------------ | ---------------- | | m | array | Array of vectors | --- ## mod ⇒ number Non-negative modulo function. E.g., `mod(-1, 5) === 4` while `-1 % 5 === -1`. **Kind**: global constant **Returns**: number - Remainder | Param | Type | Description | | ----- | ------------------- | ----------- | | x | number | Dividend | | y | number | Divisor | --- ## normalize ⇒ array Normalize vector **Kind**: global constant **Returns**: array - Unit vector | Param | Type | Description | | ----- | ------------------ | ---------------- | | v | array | Numerical vector | --- ## range ⇒ array A function to created a range array **Kind**: global constant **Returns**: array - Range array | Param | Type | Description | | -------- | ------------------- | ----------------------------- | | start | number | Start of the range (included) | | end | number | End of the range (excluded) | | stepSize | number | Increase per step | --- ## rangeMap ⇒ array This is equivalent to `Array(length).fill().map(mapFn)` but about 60% faster **Kind**: global constant **Returns**: array - Initialized array | Param | Type | Description | | ------ | --------------------- | ----------------- | | length | number | Size of the array | | mapFn | function | Mapping function | --- ## sum ⇒ number Get the sum of a vector while ignoring NaNs **Kind**: global constant **Returns**: number - The sum | Param | Type | Description | | ----- | ------------------ | ---------------- | | v | array | Numerical vector | **Example** ```js sum([0, 10, 12, 22]); // >> 42 ``` --- ## sumVector ⇒ array Get the sum vector **Kind**: global constant **Returns**: array - Sum vector | Param | Type | Description | | ----- | ------------------ | ---------------- | | m | array | Array of vectors | --- ## unionIntegers ⇒ array Get the unique union of two vectors of integers **Kind**: global constant **Returns**: array - Unique union of `v` and `w` | Param | Type | Description | | ----- | ------------------ | ------------------------- | | v | array | First vector of integers | | w | array | Second vector of integers | ---