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. We are constantly working to improve this repository, so please feel
free to contribute if you notice any omissions or errors.
Thanks!
Supported Node.js Environments
- v4:Argon (Ar)
- v6:Boron (B)
- v8:Carbon (C)
- v10:Dubnium (Db)
- v12:Erbium (Er)
- v14:Fermium (Fm)
- v16:Gallium (Ga)
- v18:Hydrogen (H)
@openinf/util-types
runs on
supported versions of Node.js and is available via
npm
, pnpm
, or yarn
.
Using the npm CLI
See the official documentation for this command for more information.
npm i @openinf/util-types
Using the pnpm CLI
See the official documentation for this command for more information.
pnpm add @openinf/util-types
Using the Yarn 1 CLI (Classic)
See the official documentation for this command for more information.
yarn add @openinf/util-types
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.');
}
- toString(value) ⇒
string
Returns the ECMAScript [[Class]] internal property of the passed value.
- isUndefined(value) ⇒
boolean
Determines whether the passed value is actually of type
undefined
.- isObject(value) ⇒
boolean
Determines whether the passed value is of type
Object
.- isOrdinaryFunction(value) ⇒
boolean
Determines whether the passed value is of type
Function
.- isBooleanObject(value) ⇒
boolean
Determines whether the passed value is actually a
Boolean
object.- isSymbolObject(value) ⇒
boolean
Determines whether the passed value is actually a
Symbol
object.- isNativeError(value) ⇒
boolean
Determines whether the passed value is one of the native error types:
- isNumberObject(value) ⇒
boolean
Determines whether the passed value is actually a
Number
object (boxed primitive).- isBigIntObject(value) ⇒
boolean
Determines whether the passed value is actually a
BigInt
object (boxed primitive).- 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.- isMath(value) ⇒
boolean
Determines whether the passed value is actually the
Math
global object.- isDate(value) ⇒
boolean
Determines whether the passed value is of type
Date
.- isStringObject(value) ⇒
boolean
Determines whether the passed value is actually a
String
object.- isRegExp(value) ⇒
boolean
Determines whether the passed value is of type
RegExp
.- isArray(value) ⇒
boolean
Determines whether the passed value is of type
Array
.- toArray(arrayLike) ⇒
Array<T>
Converts an array-like object to an array.
- isInt8Array(value) ⇒
boolean
Determines whether the passed value is of type
Int8Array
.- isUint8Array(value) ⇒
boolean
Determines whether the passed value is of type
Uint8Array
.- isUint8ClampedArray(value) ⇒
boolean
Determines whether the passed value is of type
Uint8ClampedArray
.- isInt16Array(value) ⇒
boolean
Determines whether the passed value is of type
Int16Array
.- isUint16Array(value) ⇒
boolean
Determines whether the passed value is of type
Uint16Array
.- isInt32Array(value) ⇒
boolean
Determines whether the passed value is of type
Int32Array
.- isUint32Array(value) ⇒
boolean
Determines whether the passed value is of type
Uint32Array
.- isFloat32Array(value) ⇒
boolean
Determines whether the passed value is of type
Float32Array
.- isFloat64Array(value) ⇒
boolean
Determines whether the passed value is of type
Float64Array
.- isBigInt64Array(value) ⇒
boolean
Determines whether the passed value is of type
BigInt64Array
.- isBigUint64Array(value) ⇒
boolean
Determines whether the passed value is of type
BigUint64Array
.- isArrayBufferView(value) ⇒
boolean
Determines whether the passed value is an
ArrayBufferView
, which is a helper type representing any of the following JavaScript TypedArray types:- isTypedArray(value) ⇒
boolean
Determines if value is one of the TypedArray element types:
- 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
.- 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
.- isWeakMap(value) ⇒
boolean
Determines whether the passed value is of type
WeakMap
.- isWeakSet(value) ⇒
boolean
Determines whether the passed value is of type
WeakSet
.- isArrayBuffer(value) ⇒
boolean
Determines whether the passed value is of type
ArrayBuffer
.- isSharedArrayBuffer(value) ⇒
boolean
Determines whether the passed value is of type
SharedArrayBuffer
.- isAnyArrayBuffer(value) ⇒
boolean
Determines whether the passed value is one of either
ArrayBuffer
orSharedArrayBuffer
.- isDataView(value) ⇒
boolean
Determines whether the passed value is of type
DataView
.- isPromise(value) ⇒
boolean
Determines whether the passed value is of type
Promise
.- isGeneratorObject(value) ⇒
boolean
Determines whether the passed value is actually a
Generator
object.- isGeneratorFunction(value) ⇒
boolean
Determines whether the passed value is of type
GeneratorFunction
.- isAsyncFunction(value) ⇒
boolean
Determines whether the passed value is of type
AsyncFunction
.- isArgumentsObject(value) ⇒
boolean
Determines whether the passed value is actually an
arguments
object.- isBoxedPrimitive(value) ⇒
boolean
Determines whether the passed value is a primitive wrapped by its object equivalent (a.k.a. "boxed"). Except for
null
andundefined
, all primitive values have object equivalents that wrap around the primitive values:- isModuleNamespaceObject(value) ⇒
boolean
Determines whether the passed value is a
Module
namespace object.- isPrimitive(value) ⇒
boolean
Determines whether the passed value is of a primitive data type.
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. |
Determines whether the passed value is actually of type undefined
.
Kind: global function
Returns: boolean
- true
if the value is undefined
; otherwise, false
.
Param | Type | Description |
---|---|---|
value | unknown |
The value to be checked. |
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. |
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. |
Determines whether the passed value is actually a Boolean
object.
Kind: global function
Returns: boolean
- true
if the value is a Boolean
object; otherwise,
false
.
Param | Type | Description |
---|---|---|
value | unknown |
The value to be checked. |
Determines whether the passed value is actually a Symbol
object.
Kind: global function
Returns: boolean
- true
if the value is a Symbol
object; otherwise,
false
.
Param | Type | Description |
---|---|---|
value | unknown |
The value to be checked. |
Determines whether the passed value is one of the native error types:
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. |
Determines whether the passed value is actually a Number
object (boxed primitive).
Kind: global function
Returns: boolean
- true
if the value is a Number
object; otherwise,
false
.
Param | Type | Description |
---|---|---|
value | unknown |
The value to be checked. |
Determines whether the passed value is actually a BigInt
object (boxed primitive).
Kind: global function
Returns: boolean
- true
if the value is a BigInt
object; otherwise,
false
.
Param | Type | Description |
---|---|---|
value | unknown |
The value to be checked. |
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. |
Determines whether the passed value is actually the Math
global object.
Kind: global function
Returns: boolean
- true
if the value is the Math
object; otherwise, false
.
Param | Type | Description |
---|---|---|
value | unknown |
The value to be checked. |
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. |
Determines whether the passed value is actually a String
object.
Kind: global function
Returns: boolean
- true
if the value is a String
object; otherwise,
false
.
Param | Type | Description |
---|---|---|
value | unknown |
The value to be checked. |
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. |
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. |
Converts an array-like object to an array.
Kind: global function
Param | Type |
---|---|
arrayLike | ArrayLike<T> | string |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
Determines whether the passed value is an ArrayBufferView
,
which is a helper type representing any of the following JavaScript TypedArray
types:
Int8Array
Uint8Array
Uint8ClampedArray
Int16Array
Uint16Array
Int32Array
Uint32Array
Float32Array
Float64Array
DataView
Kind: global function
Returns: boolean
- true
if the value is an ArrayBufferView
; otherwise,
false
.
Param | Type | Description |
---|---|---|
value | unknown |
The value to be checked. |
Determines if value is one of the TypedArray element types:
Int8Array
Uint8Array
Uint8ClampedArray
Int16Array
Uint16Array
Int32Array
Uint32Array
Float32Array
Float64Array
BigInt64Array
BigUint64Array
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
Determines whether the passed value is one of either ArrayBuffer
or SharedArrayBuffer
.
Kind: global function
Returns: boolean
- true
if the value is one of the array buffers;
otherwise, false
.
Param | Type | Description |
---|---|---|
value | unknown |
The value to be checked. |
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. |
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. |
Determines whether the passed value is actually a 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. |
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. |
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. |
Determines whether the passed value is actually an
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. |
Determines whether the passed value is a primitive wrapped by its object
equivalent (a.k.a. "boxed"). Except for null
and undefined
, all primitive
values have object equivalents that wrap around the primitive values:
Kind: global function
Returns: boolean
- true
if the value is one of the boxed primitives;
otherwise, false
.
See: https://developer.mozilla.org/en-US/docs/Glossary/Primitive#primitive_wrapper_objects_in_javascript
Param | Type | Description |
---|---|---|
value | unknown |
The value to be checked. |
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. |
Determines whether the passed value is of a primitive data type.
Kind: global function
Returns: boolean
- true
if the value is a primitive; otherwise, false
.
Param | Type | Description |
---|---|---|
value | unknown |
The value to be checked. |
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. If for whatever reason you spot something to fix but cannot patch it yourself, please open an issue.
This project is licensed under either of
at your option.
The SPDX license identifier for this project is
MIT OR Apache-2.0
.
If you like the project (or want to bookmark it) —
— give it a star ⭐️ — it will greatly encourage
us.