Core utility functions/classes for Transformers.js.
These are only used internally, meaning an end-user shouldn’t need to access anything here.
.Callable
: *
.reverseDictionary(data)
⇒ Object
.escapeRegExp(string)
⇒ string
.isString(text)
⇒ boolean
.isTypedArray(val)
⇒ boolean
.isIntegralNumber(x)
⇒ boolean
.exists(x)
⇒ boolean
.calculateDimensions(arr)
⇒ Array
.pop(obj, key, defaultValue)
⇒ *
.mergeArrays(arrs)
⇒ Array
A base class for creating callable objects.
Kind: static constant of utils/core
Reverses the keys and values of an object.
Kind: static method of utils/core
Returns: Object
- The reversed object.
See: https://ultimatecourses.com/blog/reverse-object-keys-and-values-in-javascript
Param | Type | Description |
---|---|---|
data | Object | The object to reverse. |
Escapes regular expression special characters from a string by replacing them with their escaped counterparts.
Kind: static method of utils/core
Returns: string
- The escaped string.
Param | Type | Description |
---|---|---|
string | string | The string to escape. |
Check if a value is a string.
Kind: static method of utils/core
Returns: boolean
- True if the value is a string, false otherwise.
Param | Type | Description |
---|---|---|
text | * | The value to check. |
Check if a value is a typed array.
Kind: static method of utils/core
Returns: boolean
- True if the value is a TypedArray
, false otherwise.
Adapted from https://stackoverflow.com/a/71091338/13989043
Param | Type | Description |
---|---|---|
val | * | The value to check. |
Check if a value is an integer.
Kind: static method of utils/core
Returns: boolean
- True if the value is a string, false otherwise.
Param | Type | Description |
---|---|---|
x | * | The value to check. |
Check if a value is exists.
Kind: static method of utils/core
Returns: boolean
- True if the value exists, false otherwise.
Param | Type | Description |
---|---|---|
x | * | The value to check. |
Calculates the dimensions of a nested array.
Kind: static method of utils/core
Returns: Array
- An array containing the dimensions of the input array.
Param | Type | Description |
---|---|---|
arr | Array | The nested array to calculate dimensions for. |
Replicate python’s .pop() method for objects.
Kind: static method of utils/core
Returns: *
- The value of the popped key.
Throws:
Error
If the key does not exist and no default value is provided.Param | Type | Description |
---|---|---|
obj | Object | The object to pop from. |
key | string | The key to pop. |
defaultValue | * | The default value to return if the key does not exist. |
Efficiently merge arrays, creating a new copy. Adapted from https://stackoverflow.com/a/6768642/13989043
Kind: static method of utils/core
Returns: Array
- The merged array.
Param | Type | Description |
---|---|---|
arrs | Array.<Array> | Arrays to merge. |
Kind: inner class of utils/core
Creates a new instance of the Callable class.
This method should be implemented in subclasses to provide the functionality of the callable object.
Kind: instance method of Callable
Throws:
Error
If the subclass does not implement the `_call` method.Param | Type |
---|---|
...args | Array.<any> |