@openinf/util-types
Fundamental JavaScript type-related utilities
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
andInfinity
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
orSharedArrayBuffer
. -
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
.
string
toString(value) ⇒ 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. |
boolean
isArray(value) ⇒ 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. |
Array.<T>
toArray(arrayLike) ⇒ Converts an array-like object to an array.
Kind: global function
Param | Type |
---|---|
arrayLike |
ArrayLike.<T> | string
|
boolean
isObject(value) ⇒ 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. |
boolean
isFiniteNumber(value) ⇒ 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. |
boolean
isAnyArrayBuffer(value) ⇒ 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. |
boolean
isArrayBufferView(value) ⇒ 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. |
boolean
isArgumentsObject(value) ⇒ 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. |
boolean
isArrayBuffer(value) ⇒ 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. |
boolean
isAsyncFunction(value) ⇒ 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. |
boolean
isBigInt64Array(value) ⇒ 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. |
boolean
isBigUint64Array(value) ⇒ 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. |
boolean
isBooleanObject(value) ⇒ 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. |
boolean
isBoxedPrimitive(value) ⇒ 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. |
boolean
isDataView(value) ⇒ 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. |
boolean
isDate(value) ⇒ 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. |
boolean
isFloat32Array(value) ⇒ 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. |
boolean
isFloat64Array(value) ⇒ 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. |
boolean
isOrdinaryFunction(value) ⇒ 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. |
boolean
isGeneratorFunction(value) ⇒ 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. |
boolean
isGeneratorObject(value) ⇒ 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. |
boolean
isInt8Array(value) ⇒ 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. |
boolean
isInt16Array(value) ⇒ 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. |
boolean
isInt32Array(value) ⇒ 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. |
boolean
isMap(value) ⇒ 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. |
boolean
isMapIterator(value) ⇒ 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. |
boolean
isModuleNamespaceObject(value) ⇒ 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. |
boolean
isNativeError(value) ⇒ 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. |
boolean
isNumberObject(value) ⇒ 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. |
boolean
isBigIntObject(value) ⇒ 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. |
boolean
isPromise(value) ⇒ 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. |
boolean
isRegExp(value) ⇒ 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. |
boolean
isSet(value) ⇒ 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. |
boolean
isSetIterator(value) ⇒ 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. |
boolean
isSharedArrayBuffer(value) ⇒ 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. |
boolean
isStringObject(value) ⇒ 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. |
boolean
isSymbolObject(value) ⇒ 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. |
boolean
isTypedArray(value) ⇒ 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. |
boolean
isUint8Array(value) ⇒ 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. |
boolean
isUint8ClampedArray(value) ⇒ 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. |
boolean
isUint16Array(value) ⇒ 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. |
boolean
isUint32Array(value) ⇒ 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. |
boolean
isWeakMap(value) ⇒ 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. |
boolean
isWeakSet(value) ⇒ 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