> For the complete documentation index, see [llms.txt](https://boinc-ai.gitbook.io/transformers.js/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://boinc-ai.gitbook.io/transformers.js/api-reference/utilities/core.md).

# 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](https://huggingface.co/docs/transformers.js/api/utils/core#module_utils/core)
  * *static*
    * [`.Callable`](https://huggingface.co/docs/transformers.js/api/utils/core#module_utils/core.Callable) : `*`
    * [`.reverseDictionary(data)`](https://huggingface.co/docs/transformers.js/api/utils/core#module_utils/core.reverseDictionary) ⇒ `Object`
    * [`.escapeRegExp(string)`](https://huggingface.co/docs/transformers.js/api/utils/core#module_utils/core.escapeRegExp) ⇒ `string`
    * [`.isString(text)`](https://huggingface.co/docs/transformers.js/api/utils/core#module_utils/core.isString) ⇒ `boolean`
    * [`.isTypedArray(val)`](https://huggingface.co/docs/transformers.js/api/utils/core#module_utils/core.isTypedArray) ⇒ `boolean`
    * [`.isIntegralNumber(x)`](https://huggingface.co/docs/transformers.js/api/utils/core#module_utils/core.isIntegralNumber) ⇒ `boolean`
    * [`.exists(x)`](https://huggingface.co/docs/transformers.js/api/utils/core#module_utils/core.exists) ⇒ `boolean`
    * [`.calculateDimensions(arr)`](https://huggingface.co/docs/transformers.js/api/utils/core#module_utils/core.calculateDimensions) ⇒ `Array`
    * [`.pop(obj, key, defaultValue)`](https://huggingface.co/docs/transformers.js/api/utils/core#module_utils/core.pop) ⇒ `*`
    * [`.mergeArrays(arrs)`](https://huggingface.co/docs/transformers.js/api/utils/core#module_utils/core.mergeArrays) ⇒ `Array`
  * *inner*
    * [\~Callable](https://huggingface.co/docs/transformers.js/api/utils/core#module_utils/core..Callable)
      * [`new Callable()`](https://huggingface.co/docs/transformers.js/api/utils/core#new_module_utils/core..Callable_new)
      * [`._call(...args)`](https://huggingface.co/docs/transformers.js/api/utils/core#module_utils/core..Callable+_call)

***

### utils/core.Callable : \<code> \* \</code>

A base class for creating callable objects.

**Kind**: static constant of [`utils/core`](https://huggingface.co/docs/transformers.js/api/utils/core#module_utils/core)

***

### utils/core.reverseDictionary(data) ⇒ \<code> Object \</code>

Reverses the keys and values of an object.

**Kind**: static method of [`utils/core`](https://huggingface.co/docs/transformers.js/api/utils/core#module_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) ⇒ \<code> string \</code>

Escapes regular expression special characters from a string by replacing them with their escaped counterparts.

**Kind**: static method of [`utils/core`](https://huggingface.co/docs/transformers.js/api/utils/core#module_utils/core)\
**Returns**: `string` - The escaped string.

| Param  | Type     | Description           |
| ------ | -------- | --------------------- |
| string | `string` | The string to escape. |

***

### utils/core.isString(text) ⇒ \<code> boolean \</code>

Check if a value is a string.

**Kind**: static method of [`utils/core`](https://huggingface.co/docs/transformers.js/api/utils/core#module_utils/core)\
**Returns**: `boolean` - True if the value is a string, false otherwise.

| Param | Type | Description         |
| ----- | ---- | ------------------- |
| text  | `*`  | The value to check. |

***

### utils/core.isTypedArray(val) ⇒ \<code> boolean \</code>

Check if a value is a typed array.

**Kind**: static method of [`utils/core`](https://huggingface.co/docs/transformers.js/api/utils/core#module_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) ⇒ \<code> boolean \</code>

Check if a value is an integer.

**Kind**: static method of [`utils/core`](https://huggingface.co/docs/transformers.js/api/utils/core#module_utils/core)\
**Returns**: `boolean` - True if the value is a string, false otherwise.

| Param | Type | Description         |
| ----- | ---- | ------------------- |
| x     | `*`  | The value to check. |

***

### utils/core.exists(x) ⇒ \<code> boolean \</code>

Check if a value is exists.

**Kind**: static method of [`utils/core`](https://huggingface.co/docs/transformers.js/api/utils/core#module_utils/core)\
**Returns**: `boolean` - True if the value exists, false otherwise.

| Param | Type | Description         |
| ----- | ---- | ------------------- |
| x     | `*`  | The value to check. |

***

### utils/core.calculateDimensions(arr) ⇒ \<code> Array \</code>

Calculates the dimensions of a nested array.

**Kind**: static method of [`utils/core`](https://huggingface.co/docs/transformers.js/api/utils/core#module_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) ⇒ \<code> \* \</code>

Replicate python’s .pop() method for objects.

**Kind**: static method of [`utils/core`](https://huggingface.co/docs/transformers.js/api/utils/core#module_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. |

***

### utils/core.mergeArrays(arrs) ⇒ \<code> Array \</code>

Efficiently merge arrays, creating a new copy. Adapted from <https://stackoverflow.com/a/6768642/13989043>

**Kind**: static method of [`utils/core`](https://huggingface.co/docs/transformers.js/api/utils/core#module_utils/core)\
**Returns**: `Array` - The merged array.

| Param | Type            | Description      |
| ----- | --------------- | ---------------- |
| arrs  | `Array.<Array>` | Arrays to merge. |

***

### utils/core\~Callable

**Kind**: inner class of [`utils/core`](https://huggingface.co/docs/transformers.js/api/utils/core#module_utils/core)

* [\~Callable](https://huggingface.co/docs/transformers.js/api/utils/core#module_utils/core..Callable)
  * [`new Callable()`](https://huggingface.co/docs/transformers.js/api/utils/core#new_module_utils/core..Callable_new)
  * [`._call(...args)`](https://huggingface.co/docs/transformers.js/api/utils/core#module_utils/core..Callable+_call)

***

#### new Callable()

Creates a new instance of the Callable class.

***

#### callable.\_call(...args)

This method should be implemented in subclasses to provide the functionality of the callable object.

**Kind**: instance method of [`Callable`](https://huggingface.co/docs/transformers.js/api/utils/core#module_utils/core..Callable)\
**Throws**:

* `Error` If the subclass does not implement the \`\_call\` method.

| Param   | Type          |
| ------- | ------------- |
| ...args | `Array.<any>` |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://boinc-ai.gitbook.io/transformers.js/api-reference/utilities/core.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
