Transformers.js documentation
utils/core
utils/core
Core utility functions/classes for Transformers.js.
These are only used internally, meaning an end-user shouldnβt need to access anything here.
- utils/core
- static
.reverseDictionary(data)βObject.escapeRegExp(string)βstring.isTypedArray(val)βboolean.isIntegralNumber(x)βboolean.isNullishDimension(x)βboolean.calculateDimensions(arr)βArray.pop(obj, key, defaultValue)β*.mergeArrays(arrs)βArray.calculateReflectOffset(i, w)βnumber.pick(o, props)βObject.len(s)βnumber.count(arr, value)
- inner
~InitiateProgressInfo:Object~DownloadProgressInfo:Object~ProgressStatusInfo:Object~DoneProgressInfo:Object~ReadyProgressInfo:Object~ProgressInfo:InitiateProgressInfo|DownloadProgressInfo|ProgressStatusInfo|DoneProgressInfo|ReadyProgressInfo~ProgressCallbackβvoid
- static
utils/core.reverseDictionary(data) β Object
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. |
utils/core.escapeRegExp(string) β string
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. |
utils/core.isTypedArray(val) β boolean
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. |
utils/core.isIntegralNumber(x) β boolean
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. |
utils/core.isNullishDimension(x) β boolean
Determine if a provided width or height is nullish.
Kind: static method of utils/core
Returns: boolean - True if the value is null, undefined or -1, false otherwise.
| Param | Type | Description |
|---|---|---|
| x | * | The value to check. |
utils/core.calculateDimensions(arr) β Array
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. |
utils/core.pop(obj, key, defaultValue) β *
Replicate pythonβs .pop() method for objects.
Kind: static method of utils/core
Returns: * - The value of the popped key.
Throws:
ErrorIf 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. |
utils/core.mergeArrays(arrs) β Array
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 | Arrays to merge. |
utils/core.calculateReflectOffset(i, w) β number
Calculates the index offset for a given index and window size.
Kind: static method of utils/core
Returns: number - The index offset.
| Param | Type | Description |
|---|---|---|
| i | number | The index. |
| w | number | The window size. |
utils/core.pick(o, props) β Object
Kind: static method of utils/core
| Param | Type |
|---|---|
| o | Object |
| props | Array |
utils/core.len(s) β number
Calculate the length of a string, taking multi-byte characters into account.
This mimics the behavior of Pythonβs len function.
Kind: static method of utils/core
Returns: number - The length of the string.
| Param | Type | Description |
|---|---|---|
| s | string | The string to calculate the length of. |
utils/core.count(arr, value)
Count the occurrences of a value in an array or string.
This mimics the behavior of Pythonβs count method.
Kind: static method of utils/core
| Param | Type | Description |
|---|---|---|
| arr | Array | string | The array or string to search. |
| value | any | The value to count. |
utils/core~InitiateProgressInfo : Object
Kind: inner typedef of utils/core
Properties
| Name | Type | Description |
|---|---|---|
| status | 'initiate' | |
| name | string | The model id or directory path. |
| file | string | The name of the file. |
utils/core~DownloadProgressInfo : Object
Kind: inner typedef of utils/core
Properties
| Name | Type | Description |
|---|---|---|
| status | 'download' | |
| name | string | The model id or directory path. |
| file | string | The name of the file. |
utils/core~ProgressStatusInfo : Object
Kind: inner typedef of utils/core
Properties
| Name | Type | Description |
|---|---|---|
| status | 'progress' | |
| name | string | The model id or directory path. |
| file | string | The name of the file. |
| progress | number | A number between 0 and 100. |
| loaded | number | The number of bytes loaded. |
| total | number | The total number of bytes to be loaded. |
utils/core~DoneProgressInfo : Object
Kind: inner typedef of utils/core
Properties
| Name | Type | Description |
|---|---|---|
| status | 'done' | |
| name | string | The model id or directory path. |
| file | string | The name of the file. |
utils/core~ReadyProgressInfo : Object
Kind: inner typedef of utils/core
Properties
| Name | Type | Description |
|---|---|---|
| status | 'ready' | |
| task | string | The loaded task. |
| model | string | The loaded model. |
utils/core~ProgressInfo : InitiateProgressInfo | DownloadProgressInfo | ProgressStatusInfo | DoneProgressInfo | ReadyProgressInfo
Kind: inner typedef of utils/core
utils/core~ProgressCallback β void
A callback function that is called with progress information.
Kind: inner typedef of utils/core
| Param | Type |
|---|---|
| progressInfo | ProgressInfo |
Update on GitHub