TypeUtils

Utility functions for working with data types.
Description:
  • Utility functions for working with data types.
Source:

Classes

InferDataTypeResult

Methods

(static) getTypeName(value) → {string}

Description:
  • Returns the type name of a given value. - For primitives: returns `"string"`, `"number"`, etc. - For objects: returns class name or `"object"` if plain. - For built-in types like Date, RegExp, Map: returns the constructor name. - For plain objects: returns "object". For arrays: "array". - For classes: returns `"class"` for user defined classes. - For functions: returns `"function"`
Source:
Parameters:
Name Type Description
value * The value whose type name to determine.
Returns:
The detected type name.
Type
string

(static) inferDataType(value) → {InferDataTypeResult}

Description:
  • Parses common values like string "true" → boolean true, "42.0" → number, etc.
Source:
Parameters:
Name Type Description
value *
Returns:
Type
InferDataTypeResult

(static) isArray(value) → {boolean}

Description:
  • Checks if the specified value is an array.
Source:
Parameters:
Name Type Description
value * The value to test.
Returns:
- `true` if the specified value is an array.
Type
boolean

(static) isAsyncFunction(value) → {boolean}

Description:
  • Checks if the specified value is an asynchronous function.
Source:
Parameters:
Name Type Description
value * The value to test.
Returns:
- `true` if the specified value is an asynchronous function.
Type
boolean

(static) isBigInt(value) → {boolean}

Description:
  • Checks if the specified value is a bigint (primitive or BigInt object).
Source:
Parameters:
Name Type Description
value * The value to test.
Returns:
- `true` if the specified value is big integer.
Type
boolean

(static) isBoolean(value) → {boolean}

Description:
  • Checks if the specified value is a boolean (primitive or Boolean object).
Source:
Parameters:
Name Type Description
value * The value to test.
Returns:
- `true` if the specified value is boolean.
Type
boolean

(static) isDate(value) → {boolean}

Description:
  • Checks if the specified value is instance of Date.
Source:
Parameters:
Name Type Description
value * The value to test.
Returns:
- `true` if the specified value is instance of Date.
Type
boolean

(static) isEmpty(value) → {boolean}

Description:
  • Checks if the specified value is "empty". The following are considered empty: - null, undefined - empty string: "" - empty array: [] - empty object: {} - empty Map or Set - Note: The implementation avoids treating numbers or booleans as "empty". Only typical "container-like" values and nullish types are evaluated.
Source:
Parameters:
Name Type Description
value * The value to test.
Returns:
`true` if the value is considered empty.
Type
boolean

(static) isError(value) → {boolean}

Description:
  • Checks if the specified value is of Error type.
Source:
Parameters:
Name Type Description
value * The value to test.
Returns:
- `true` if the specified value is of Error type.
Type
boolean

(static) isFunction(value) → {boolean}

Description:
  • Checks if the specified value is a standard function.
Source:
Parameters:
Name Type Description
value * The value to test.
Returns:
- `true` if the specified value is Function.
Type
boolean

(static) isFunctionOrGeneratorFunction(value) → {boolean}

Description:
  • Checks if the specified value is a function or a generator function.
Source:
Parameters:
Name Type Description
value * The value to test.
Returns:
- `true` if the specified value is a function or a generator function.
Type
boolean

(static) isGeneratorFunction(value) → {boolean}

Description:
  • Checks if the specified value is a generator function.
Source:
Parameters:
Name Type Description
value * The value to test.
Returns:
- `true` if the specified value is a generator function.
Type
boolean

(static) isIntegral(value, additionalPredicateopt) → {boolean}

Description:
  • Checks if the value is an integer (number or bigint), optionally applying a custom predicate.
Source:
Parameters:
Name Type Attributes Default Description
value * The value to test.
additionalPredicate function <optional>
null Additional test to apply to the value.
Returns:
- `true` if the value is integral number and passed the test against the additional predicate (if it was specified) .
Type
boolean

(static) isIterable(value) → {boolean}

Description:
  • Checks if the specified value is iterable (has a `[Symbol.iterator]` method).
Source:
Parameters:
Name Type Description
value * The value to test.
Returns:
- `true` if the specified value is iterable (has a `[Symbol.iterator]` method).
Type
boolean

(static) isMap(value) → {boolean}

Description:
  • Checks if the specified value is a Map.
Source:
Parameters:
Name Type Description
value * The value to test.
Returns:
`true` if the value is a Map.
Type
boolean

(static) isNotEmpty(value) → {boolean}

Description:
  • Checks if the specified value is not empty. See `isEmpty` for full empty definition.
Source:
Parameters:
Name Type Description
value * The value to test.
Returns:
`true` if the value is not considered empty.
Type
boolean

(static) isNull(value) → {boolean}

Description:
  • Checks if the specified value is null.
Source:
Parameters:
Name Type Description
value * The value to test.
Returns:
- `true` if the specified value is null.
Type
boolean

(static) isNumber(value, optionsopt) → {boolean}

Description:
  • Checks whether the specified value is a number (primitive or Number object). Excludes NaN and Infinity by default unless explicitly allowed.
Source:
Parameters:
Name Type Attributes Description
value * The value to test.
options Object <optional>
Properties
Name Type Attributes Default Description
allowNaN boolean <optional>
true Whether to consider NaN a valid number.
allowInfinity boolean <optional>
true Whether to consider Infinity/-Infinity valid.
Returns:
- `true` if the specified value is a number.
Type
boolean

(static) isNumeric(value) → {boolean}

Description:
  • Checks if the value is a numeric type (either number or bigint).
Source:
Parameters:
Name Type Description
value *
Returns:
- `true` if the value is a numeric type (either number or bigint).
Type
boolean

(static) isObject(value) → {boolean}

Description:
  • Checks if the specified value is a non-wrapper object (i.e., not a function, not null, not a boxed primitive). Includes objects like arrays, plain objects, Date, RegExp, etc.
Source:
Parameters:
Name Type Description
value * The value to check.
Returns:
`true` if it's a real object, excluding primitive wrappers and functions.
Type
boolean

(static) isPlainObject(value) → {boolean}

Description:
  • Checks if the specified value is a plain object (i.e., created via `{}` or `new Object()`). This works reliably across realms.
Source:
Parameters:
Name Type Description
value * The value to check.
Returns:
`true` if it's a plain object.
Type
boolean

(static) isPrimitive(value) → {boolean}

Description:
  • Determines whether the specified value is one of the primitive types: string, number, bigint, boolean and symbol (including wrapper type over primitive) This function treats primitives any of the following: string, number, boolean, symbol, bigint and their wrapper String, Number, Boolean.
Source:
Parameters:
Name Type Description
value *
Returns:
- true if the specified value is one of the primitive types: string, number, bigint, boolean and symbol (including wrapper type over primitive)
Type
boolean

(static) isPromise(value) → {boolean}

Description:
  • Checks if the specified value is a Promise.
Source:
Parameters:
Name Type Description
value * The value to test.
Returns:
`true` if the value is a Promise.
Type
boolean

(static) isRegExp(value) → {boolean}

Description:
  • Checks if the specified value is a RegExp.
Source:
Parameters:
Name Type Description
value * The value to test.
Returns:
`true` if the value is a RegExp.
Type
boolean

(static) isSet(value) → {boolean}

Description:
  • Checks if the specified value is a Set.
Source:
Parameters:
Name Type Description
value * The value to test.
Returns:
`true` if the value is a Set.
Type
boolean

(static) isString(value) → {boolean}

Description:
  • Checks if the specified value is a string (primitive or String object).
Source:
Parameters:
Name Type Description
value * The value to test.
Returns:
`true` if the specified value is a string.
Type
boolean

(static) isSymbol(value) → {boolean}

Description:
  • Checks if the specified value is a symbol.
Source:
Parameters:
Name Type Description
value * The value to test.
Returns:
`true` if the specified value is a symbol.
Type
boolean

(static) isType(value, typeName) → {boolean}

Description:
  • Checks if the specified value matches the given type name.
Source:
Parameters:
Name Type Description
value * The value to test.
typeName string The expected type name.
Returns:
`true` if the value’s type matches the given name.
Type
boolean

(static) isUndefined(value) → {boolean}

Description:
  • Checks if the specified value is undefined.
Source:
Parameters:
Name Type Description
value * The value to test.
Returns:
- `true` if the specified value is undefined.
Type
boolean

(static) isUserDefinedClass(value) → {boolean}

Description:
  • Checks if the specified value is a user defined class.
Source:
Parameters:
Name Type Description
value * The value to test.
Returns:
- `true` if the specified value is user defined class.
Type
boolean

(static) isWeakMap(value) → {boolean}

Description:
  • Checks if the specified value is a WeakMap.
Source:
Parameters:
Name Type Description
value * The value to test.
Returns:
`true` if the value is a WeakMap.
Type
boolean

(static) isWeakSet(value) → {boolean}

Description:
  • Checks if the specified value is a WeakSet.
Source:
Parameters:
Name Type Description
value * The value to test.
Returns:
`true` if the value is a WeakSet.
Type
boolean

(static) parseBool(value) → {boolean|undefined}

Description:
  • Parses a string to boolean. If the input is already boolean, returns it. If it's "true" or "false" (case insensitive), converts accordingly.
Source:
Parameters:
Name Type Description
value * The value to parse.
Returns:
- 'true' if the specified value is a string trimmed to literal 'true' (case insensitive) or `false` if it is trimmed to literal 'false' (case insensitive).
Type
boolean | undefined

(static) version() → {string}

Description:
  • Returns the semantic version of this library.
Source:
Returns:
- The semantic version of this library.
Type
string

(inner) isClass(fn) → {boolean}

Description:
  • Determines whether the given function is a user defined class constructor. Inspects the function’s string to determine if it's a class constructor.
Source:
Parameters:
Name Type Description
fn * The function to test.
Returns:
`true` if the given function is a user defined class constructor.
Type
boolean