@openinf/util-types
    TypeScript icon, indicating that this package has built-in type declarations

    2.1.3 • Public • Published

    @openinf/util-types

    Fundamental JavaScript type-related utilities


    view on npm License: MIT


    The high-level goal of @openinf/util-types is to serve as a Node.js package containing utilities for fundamental JavaScript type-related operations primarily enabling users to perform native typechecking and simplify type coercion. As is the case with any software project in continuous development, omissions and errors may exist, for which contributions are welcome.




    Installation

    @openinf/util-types runs on Node.js and is available via npm.

    npm install @openinf/util-types

    Usage

    Import the helper functions based on your platform.

    import { isObject } from '@openinf/util-types';
    
    const maybeObject = null;
    
    if (isObject(maybeObject)) {
      console.log('The value of `maybeObject` is of type Object.');
    } else {
      console.log('The value of `maybeObject` is not of type Object.');
    }



    Functions

    toString(value)string

    Returns the ECMAScript [[Class]] internal property of the passed value.

    isArray(value)boolean

    Determines whether the passed value is of type Array.

    toArray(arrayLike)Array.<T>

    Converts an array-like object to an array.

    isObject(value)boolean

    Determines whether the passed value is of type Object.

    isFiniteNumber(value)boolean

    Determines whether the passed value is of number type and finite. NaN and Infinity are not considered a finite number. String numbers are not considered numbers.

    isAnyArrayBuffer(value)boolean

    Determines whether the passed value is one of either ArrayBuffer or SharedArrayBuffer.

    isArrayBufferView(value)boolean

    Determines whether the passed value is an ArrayBufferView.

    isArgumentsObject(value)boolean

    Determines whether the passed value is of type Arguments object.

    isArrayBuffer(value)boolean

    Determines whether the passed value is of type ArrayBuffer.

    isAsyncFunction(value)boolean

    Determines whether the passed value is of type AsyncFunction.

    isBigInt64Array(value)boolean

    Determines whether the passed value is of type BigInt64Array.

    isBigUint64Array(value)boolean

    Determines whether the passed value is of type BigUint64Array.

    isBooleanObject(value)boolean

    Determines whether the passed value is a Boolean object.

    isBoxedPrimitive(value)boolean

    Determines whether the passed value is one of the boxed primitives:

    • Boolean
    • String
    • Number
    • Symbol
    • BigInt
    isDataView(value)boolean

    Determines whether the passed value is of type DataView.

    isDate(value)boolean

    Determines whether the passed value is of type Date.

    isFloat32Array(value)boolean

    Determines whether the passed value is of type Float32Array.

    isFloat64Array(value)boolean

    Determines whether the passed value is of type Float64Array.

    isOrdinaryFunction(value)boolean

    Determines whether the passed value is of type Function.

    isGeneratorFunction(value)boolean

    Determines whether the passed value is of type GeneratorFunction.

    isGeneratorObject(value)boolean

    Determines whether the passed value is of type Generator object.

    isInt8Array(value)boolean

    Determines whether the passed value is of type Int8Array.

    isInt16Array(value)boolean

    Determines whether the passed value is of type Int16Array.

    isInt32Array(value)boolean

    Determines whether the passed value is of type Int32Array.

    isMap(value)boolean

    Determines whether the passed value is of type Map.

    isMapIterator(value)boolean

    Determines whether the passed value is of type Map Iterator.

    isModuleNamespaceObject(value)boolean

    Determines whether the passed value is a Module namespace object.

    isNativeError(value)boolean

    Determines whether the passed value is a one of the native error types:

    • EvalError
    • RangeError
    • ReferenceError
    • SyntaxError
    • TypeError
    • URIError
    • AggregateError
    • InternalError
    isNumberObject(value)boolean

    Determines if value is actually a Number object.

    isBigIntObject(value)boolean

    Determines if value is actually a BigInt object.

    isPromise(value)boolean

    Determines whether the passed value is of type Promise.

    isRegExp(value)boolean

    Determines whether the passed value is of type RegExp.

    isSet(value)boolean

    Determines whether the passed value is of type Set.

    isSetIterator(value)boolean

    Determines whether the passed value is of type Set Iterator.

    isSharedArrayBuffer(value)boolean

    Determines whether the passed value is of type SharedArrayBuffer.

    isStringObject(value)boolean

    Determines if value is actually a String object.

    isSymbolObject(value)boolean

    Determines if value is actually a Symbol object.

    isTypedArray(value)boolean

    Determines if value is one of the typed arrays:

    • Float32Array
    • Float64Array
    • Int8Array
    • Uint8Array
    • Uint8ClampedArray
    • Int16Array
    • Uint16Array
    • Int32Array
    • Uint32Array
    isUint8Array(value)boolean

    Determines whether the passed value is of type Uint8Array.

    isUint8ClampedArray(value)boolean

    Determines whether the passed value is of type Uint8ClampedArray.

    isUint16Array(value)boolean

    Determines whether the passed value is of type Uint16Array.

    isUint32Array(value)boolean

    Determines whether the passed value is of type Uint32Array.

    isWeakMap(value)boolean

    Determines whether the passed value is of type WeakMap.

    isWeakSet(value)boolean

    Determines whether the passed value is of type WeakSet.

    toString(value) ⇒ string

    Returns the ECMAScript [[Class]] internal property of the passed value.

    Kind: global function
    Returns: string - A specification-defined classification of objects.

    Param Type Description
    value unknown The value to be checked.

    isArray(value) ⇒ boolean

    Determines whether the passed value is of type Array.

    Kind: global function
    Returns: boolean - true if the value is an Array; otherwise, false.

    Param Type Description
    value unknown The value to be checked.

    toArray(arrayLike) ⇒ Array.<T>

    Converts an array-like object to an array.

    Kind: global function

    Param Type
    arrayLike ArrayLike.<T> | string

    isObject(value) ⇒ boolean

    Determines whether the passed value is of type Object.

    Kind: global function
    Returns: boolean - true if the value is an Object; otherwise, false.

    Param Type Description
    value unknown The value to be checked.

    isFiniteNumber(value) ⇒ boolean

    Determines whether the passed value is of number type and finite. NaN and Infinity are not considered a finite number. String numbers are not considered numbers.

    Kind: global function
    Returns: boolean - true if the value is a finite number; otherwise, false.

    Param Type Description
    value unknown The value to be checked.

    isAnyArrayBuffer(value) ⇒ boolean

    Determines whether the passed value is one of either ArrayBuffer or SharedArrayBuffer.

    Kind: global function
    Returns: boolean - true if the value is an any array buffer; otherwise, false.

    Param Type Description
    value unknown The value to be checked.

    isArrayBufferView(value) ⇒ boolean

    Determines whether the passed value is an ArrayBufferView.

    Kind: global function
    Returns: boolean - true if the value is an ArrayBufferView; otherwise, false.

    Param Type Description
    value unknown The value to be checked.

    isArgumentsObject(value) ⇒ boolean

    Determines whether the passed value is of type Arguments object.

    Kind: global function
    Returns: boolean - true if the value is an Arguments object; otherwise, false.

    Param Type Description
    value unknown The value to be checked.

    isArrayBuffer(value) ⇒ boolean

    Determines whether the passed value is of type ArrayBuffer.

    Kind: global function
    Returns: boolean - true if the value is an ArrayBuffer; otherwise, false.

    Param Type Description
    value unknown The value to be checked.

    isAsyncFunction(value) ⇒ boolean

    Determines whether the passed value is of type AsyncFunction.

    Kind: global function
    Returns: boolean - true if the value is an AsyncFunction; otherwise, false.

    Param Type Description
    value unknown The value to be checked.

    isBigInt64Array(value) ⇒ boolean

    Determines whether the passed value is of type BigInt64Array.

    Kind: global function
    Returns: boolean - true if the value is a BigInt64Array; otherwise, false.

    Param Type Description
    value unknown The value to be checked.

    isBigUint64Array(value) ⇒ boolean

    Determines whether the passed value is of type BigUint64Array.

    Kind: global function
    Returns: boolean - true if the value is a BigUint64Array; otherwise, false.

    Param Type Description
    value unknown The value to be checked.

    isBooleanObject(value) ⇒ boolean

    Determines whether the passed value is a Boolean object.

    Kind: global function
    Returns: boolean - true if the value is a Boolean; otherwise, false.

    Param Type Description
    value unknown The value to be checked.

    isBoxedPrimitive(value) ⇒ boolean

    Determines whether the passed value is one of the boxed primitives:

    • Boolean
    • String
    • Number
    • Symbol
    • BigInt

    Kind: global function
    Returns: boolean - true if the value is one of the boxed primitives; otherwise, false.

    Param Type Description
    value unknown The value to be checked.

    isDataView(value) ⇒ boolean

    Determines whether the passed value is of type DataView.

    Kind: global function
    Returns: boolean - true if the value is a DataView; otherwise, false.

    Param Type Description
    value unknown The value to be checked.

    isDate(value) ⇒ boolean

    Determines whether the passed value is of type Date.

    Kind: global function
    Returns: boolean - true if the value is a Date; otherwise, false.

    Param Type Description
    value unknown The value to be checked.

    isFloat32Array(value) ⇒ boolean

    Determines whether the passed value is of type Float32Array.

    Kind: global function
    Returns: boolean - true if the value is a Float32Array; otherwise, false.

    Param Type Description
    value unknown The value to be checked.

    isFloat64Array(value) ⇒ boolean

    Determines whether the passed value is of type Float64Array.

    Kind: global function
    Returns: boolean - true if the value is a Float64Array; otherwise, false.

    Param Type Description
    value unknown The value to be checked.

    isOrdinaryFunction(value) ⇒ boolean

    Determines whether the passed value is of type Function.

    Kind: global function
    Returns: boolean - true if the value is a Function; otherwise, false.

    Param Type Description
    value unknown The value to be checked.

    isGeneratorFunction(value) ⇒ boolean

    Determines whether the passed value is of type GeneratorFunction.

    Kind: global function
    Returns: boolean - true if the value is a GeneratorFunction; otherwise, false.

    Param Type Description
    value unknown The value to be checked.

    isGeneratorObject(value) ⇒ boolean

    Determines whether the passed value is of type Generator object.

    Kind: global function
    Returns: boolean - true if the value is a Generator; otherwise, false.

    Param Type Description
    value unknown The value to be checked.

    isInt8Array(value) ⇒ boolean

    Determines whether the passed value is of type Int8Array.

    Kind: global function
    Returns: boolean - true if the value is an Int8Array; otherwise, false.

    Param Type Description
    value unknown The value to be checked.

    isInt16Array(value) ⇒ boolean

    Determines whether the passed value is of type Int16Array.

    Kind: global function
    Returns: boolean - true if the value is an Int16Array; otherwise, false.

    Param Type Description
    value unknown The value to be checked.

    isInt32Array(value) ⇒ boolean

    Determines whether the passed value is of type Int32Array.

    Kind: global function
    Returns: boolean - true if the value is an Int32Array; otherwise, false.

    Param Type Description
    value unknown The value to be checked.

    isMap(value) ⇒ boolean

    Determines whether the passed value is of type Map.

    Kind: global function
    Returns: boolean - true if the value is a Map; otherwise, false.

    Param Type Description
    value unknown The value to be checked.

    isMapIterator(value) ⇒ boolean

    Determines whether the passed value is of type Map Iterator.

    Kind: global function
    Returns: boolean - true if the value is a Map Iterator; otherwise, false.

    Param Type Description
    value unknown The value to be checked.

    isModuleNamespaceObject(value) ⇒ boolean

    Determines whether the passed value is a Module namespace object.

    Kind: global function
    Returns: boolean - true if the value is a Module; otherwise, false.

    Param Type Description
    value unknown The value to be checked.

    isNativeError(value) ⇒ boolean

    Determines whether the passed value is a one of the native error types:

    • EvalError
    • RangeError
    • ReferenceError
    • SyntaxError
    • TypeError
    • URIError
    • AggregateError
    • InternalError

    Kind: global function
    Returns: boolean - true if the value is a native error; otherwise, false.

    Param Type Description
    value unknown The value to be checked.

    isNumberObject(value) ⇒ boolean

    Determines if value is actually a Number object.

    Kind: global function
    Returns: boolean - true if the value is a Number; otherwise, false.

    Param Type Description
    value unknown The value to be checked.

    isBigIntObject(value) ⇒ boolean

    Determines if value is actually a BigInt object.

    Kind: global function
    Returns: boolean - true if the value is a BigInt; otherwise, false.

    Param Type Description
    value unknown The value to be checked.

    isPromise(value) ⇒ boolean

    Determines whether the passed value is of type Promise.

    Kind: global function
    Returns: boolean - true if the value is a Promise; otherwise, false.

    Param Type Description
    value unknown The value to be checked.

    isRegExp(value) ⇒ boolean

    Determines whether the passed value is of type RegExp.

    Kind: global function
    Returns: boolean - true if the value is a RegExp; otherwise, false.

    Param Type Description
    value unknown The value to be checked.

    isSet(value) ⇒ boolean

    Determines whether the passed value is of type Set.

    Kind: global function
    Returns: boolean - true if the value is a Set; otherwise, false.

    Param Type Description
    value unknown The value to be checked.

    isSetIterator(value) ⇒ boolean

    Determines whether the passed value is of type Set Iterator.

    Kind: global function
    Returns: boolean - true if the value is a Set Iterator; otherwise, false.

    Param Type Description
    value unknown The value to be checked.

    isSharedArrayBuffer(value) ⇒ boolean

    Determines whether the passed value is of type SharedArrayBuffer.

    Kind: global function
    Returns: boolean - true if the value is a SharedArrayBuffer; otherwise, false.

    Param Type Description
    value unknown The value to be checked.

    isStringObject(value) ⇒ boolean

    Determines if value is actually a String object.

    Kind: global function
    Returns: boolean - true if the value is a String; otherwise, false.

    Param Type Description
    value unknown The value to be checked.

    isSymbolObject(value) ⇒ boolean

    Determines if value is actually a Symbol object.

    Kind: global function
    Returns: boolean - true if the value is a Symbol; otherwise, false.

    Param Type Description
    value unknown The value to be checked.

    isTypedArray(value) ⇒ boolean

    Determines if value is one of the typed arrays:

    • Float32Array
    • Float64Array
    • Int8Array
    • Uint8Array
    • Uint8ClampedArray
    • Int16Array
    • Uint16Array
    • Int32Array
    • Uint32Array

    Kind: global function
    Returns: boolean - true if the value is one of the typed arrays; otherwise, false.

    Param Type Description
    value unknown The value to be checked.

    isUint8Array(value) ⇒ boolean

    Determines whether the passed value is of type Uint8Array.

    Kind: global function
    Returns: boolean - true if the value is a Uint8Array; otherwise, false.

    Param Type Description
    value unknown The value to be checked.

    isUint8ClampedArray(value) ⇒ boolean

    Determines whether the passed value is of type Uint8ClampedArray.

    Kind: global function
    Returns: boolean - true if the value is a Uint8ClampedArray; otherwise, false.

    Param Type Description
    value unknown The value to be checked.

    isUint16Array(value) ⇒ boolean

    Determines whether the passed value is of type Uint16Array.

    Kind: global function
    Returns: boolean - true if the value is a Uint16Array; otherwise, false.

    Param Type Description
    value unknown The value to be checked.

    isUint32Array(value) ⇒ boolean

    Determines whether the passed value is of type Uint32Array.

    Kind: global function
    Returns: boolean - true if the value is a Uint32Array; otherwise, false.

    Param Type Description
    value unknown The value to be checked.

    isWeakMap(value) ⇒ boolean

    Determines whether the passed value is of type WeakMap.

    Kind: global function
    Returns: boolean - true if the value is a WeakMap; otherwise, false.

    Param Type Description
    value unknown The value to be checked.

    isWeakSet(value) ⇒ boolean

    Determines whether the passed value is of type WeakSet.

    Kind: global function
    Returns: boolean - true if the value is a WeakSet; otherwise, false.

    Param Type Description
    value unknown The value to be checked.



    © The OpenINF Authors

    Install

    npm i @openinf/util-types

    DownloadsWeekly Downloads

    10

    Version

    2.1.3

    License

    MIT

    Unpacked Size

    129 kB

    Total Files

    10

    Last publish

    Collaborators

    • avatar