The definitive collection of is* functions for runtime type checking. Lodash-compatible, tree-shakable, with types.
- Lodash-compatible: The provided functions are compatible with lodash's, so they can be used as drop-in replacements. This includes non-obvious things like being able to work with polyfilled builtins, not throwing in old environments where things like Map aren't available, working with objects from other realms, working with weird things like
Boolean ( true )
andObject ( true )
, and being isomorphic. - Types: Good TypeScript types ship with the library rather than being an afterthought. Also more subtlety this means that some extra functions like
isFalsy
andisTruthy
are provided because their return type is useful for type checking, for lodash it doesn't make much sense to provide these functions because all their value is in the type system, and lodash doesn't care about that. - Modern: Some functions have been updated to account for bigints and some addititional ones have been added, the library is tree-shakable so you only pay for what you use.
- Focused: Every function provided accepts a single argument of unknown type and returns a boolean, almost always as a TypeScript type guard.
npm install --save is@npm:@fabiospampinato/is
Checks if a value is an arguments object.
import {isArguments} from 'is';
const args = (function () { return arguments; })();
isArguments ( args ); // => true
isArguments ( [] ); // => false
Checks if a value is an ArrayBuffer object.
import {isArrayBuffer} from 'is';
isArrayBuffer ( new ArrayBuffer ( 8 ) ); // => true
isArrayBuffer ( [] ); // => false
Checks if a value is an Array-like object, meaning a non-string and non-function with an integer length
property.
import {isArrayLikeObject} from 'is';
isArrayLikeObject ( [] ); // => true
isArrayLikeObject ( { length: 1 } ); // => true
isArrayLikeObject ( 'foo' ); // => false
isArrayLikeObject ( isArrayLikeObject ); // => false
Checks if a value is an Array-like object, meaning a non-function with an integer length
property.
import {isArrayLike} from 'is';
isArrayLike ( [] ); // => true
isArrayLike ( { length: 1 } ); // => true
isArrayLike ( 'foo' ); // => true
isArrayLike ( isArrayLike ); // => false
Checks if a value is an Array.
import {isArray} from 'is';
isArray ( [] ); // => true
isArray ( {} ); // => false
Checks if a value is an arrow function. There's a detectable difference between regular and arrow functions.
import {isArrowFunction} from 'is';
isArrowFunction ( () => {} ); // => true
isArrowFunction ( function () {} ); // => false
Checks if a value is an async function. Note that this will return false for async generator functions.
import {isAsyncFunction} from 'is';
isAsyncFunction ( async () => {} ); // => true
isAsyncFunction ( () => {} ); // => false
Checks if a value is an async generator function.
import {isAsyncGeneratorFunction} from 'is';
isAsyncGeneratorFunction ( function* () {} ); // => true
isAsyncGeneratorFunction ( function () {} ); // => false
Checks if a value is an async iterable.
import {isAsyncIterable} from 'is';
const myAsyncIterable = {
async * [Symbol.asyncIterator]() {
yield 'hello';
}
};
isAsyncIterable ( myAsyncIterable ); // => true
isAsyncIterable ( [] ); // => false
Checks if a value is likely a DOM attribute.
import {isAttribute} from 'is';
isAttribute ( document.createAttribute ( 'foo' ) ); // => true
isAttribute ( body ); // => false
Checks if a value is a bigint.
import {isBigInt} from 'is';
isBigInt ( 0n ); // => true
isBigInt ( 0 ); // => false
Checks if a value is a BigInt64Array.
import {isBigInt64Array} from 'is';
isBigInt64Array ( new BigInt64Array () ); // => true
isBigInt64Array ( [] ); // => false
Checks if a value is a BigUint64Array.
import {isBigUint64Array} from 'is';
isBigUint64Array ( new BigUint64Array () ); // => true
isBigUint64Array ( [] ); // => false
Checks if a value is a Blob.
import {isBlob} from 'is';
isBlob ( new Blob ( [] ) ); // => true
isBlob ( [] ); // => false
Checks if a value is a boolean.
import {isBoolean} from 'is';
isBoolean ( true ); // => true
isBoolean ( false ); // => true
isBoolean ( 0 ); // => false;
Checks if a value is a bound function.
import {isBoundFunction} from 'is';
isBoundFunction ( (function () {}).bind ( this ) ); // => true
isBoundFunction ( () => {} ); // => true
isBoundFunction ( function () {} ); // => false
Check if a value is a boxed bigint.
import {isBoxedBigInt} from 'is';
isBoxedBigInt ( 0n ); // => false
isBoxedBigInt ( Object ( 0n ) ); // => true
Check if a value is a boxed boolean.
import {isBoxedBoolean} from 'is';
isBoxedBoolean ( true ); // => false
isBoxedBoolean ( Object ( true ) ); // => true
Check if a value is a boxed number.
import {isBoxedNumber} from 'is';
isBoxedNumber ( 0 ); // => false
isBoxedNumber ( Object ( 0 ) ); // => true
Check if a value is a boxed primitive.
import {isBoxedPrimitive} from 'is';
isBoxedPrimitive ( 0 ); // => false
isBoxedPrimitive ( Object ( 0 ) ); // => true
isBoxedPrimitive ( Object ( 0n ) ); // => true
Check if a value is a boxed string.
import {isBoxedString} from 'is';
isBoxedString ( 'foo' ); // => false
isBoxedString ( Object ( 'foo' ) ); // => true
Check if a value is a boxed symbol.
import {isBoxedSymbol} from 'is';
isBoxedSymbol ( Symbol () ); // => false
isBoxedSymbol ( Object ( Symbol () ) ); // => true
Checks if a value is a Buffer.
import {isBuffer} from 'is';
isBuffer ( Buffer.from ( '' ) ); // => true
isBuffer ( [] ); // => false
Checks if a value is an ES6 class. Note that classes lowered to work in ES5 are not actual classes anymore, there's a detectable difference when the class
keyword is used.
import {isClass} from 'is';
isClass ( class Foo {} ); // => true
isClass ( isClass ); // => false
Checks if a value is likely a DOM comment.
import {isComment} from 'is';
isComment ( document.createComment ( 'foo' ) ); // => true
isComment ( body ); // => false
Checks if a value is a DataView.
import {isDataView} from 'is';
isDataView ( new DataView ( new ArrayBuffer ( 2 ) ) ); // => true
isDataView ( [] ); // => false
Checks if a value is a Date.
import {isDate} from 'is';
isDate ( new Date () ); // => true
isDate ( 0 ); // => false
Checks if a value is not undefined, nor null.
import {isDefined} from 'is';
isDefined ( undefined ); // => false
isDefined ( null ); // => false
isDefined ( 0 ); // => true
Checks if a value is likely a DOM document.
import {isDocument} from 'is';
isDocument ( document ); // => true
isDocument ( window ); // => false
Checks if a value is likely a DOM document fragment.
import {isDocumentFragment} from 'is';
isDocumentFragment ( new DocumentFragment () ); // => true
isDocumentFragment ( document ); // => false
Checks if a value is likely a DOM document type.
import {isDocumentType} from 'is';
isDocumentType ( document.doctype ); // => true
isDocumentType ( document ); // => false
Checks if a value is likely a DOM element.
import {isElement} from 'is';
isElement ( body ); // => true
isElement ( window ); // => false
Checks if a value is an empty array, string, buffer, typed array, arguments object, map, set, prototype or regular object.
import {isEmpty} from 'is';
isEmpty ( [] ); // => true
isEmpty ( {} ); // => true
isEmpty ( 123 ); // => true
isEmpty ( [123] ); // => false
Checks if a value is an Error.
import {isError} from 'is';
isError ( new Error () ); // => true
isError ( { message: 'asd' } ); // => false
Checks if a value is an even integer.
import {isEven} from 'is';
isEven ( 2 ); // => true
isEven ( 1 ); // => false
Checks if a value is falsy.
import {isFalsy} from 'is';
isFalsy ( 0 ); // => true
isFalsy ( '' ); // => true
isFalsy ( [] ); // => false
Checks if a value is a finite number.
import {isFinite} from 'is';
isFinite ( 0 ); // => true
isFinite ( Infinity ); // => false
isFinite ( -Infinity ); // => false
isFinite ( NaN ); // => false
Checks if a value is a float.
import {isFloat} from 'is';
isFloat ( 1.2 ); // => true
isFloat ( 0 ); // => false
isFloat ( -1 ); // => false
Checks if a value is a Float32Array.
import {isFloat32Array} from 'is';
isFloat32Array ( new Float32Array () ); // => true
isFloat32Array ( [] ); // => false
Checks if a value is a Float64Array.
import {isFloat64Array} from 'is';
isFloat64Array ( new Float64Array () ); // => true
isFloat64Array ( [] ); // => false
Checks if a value is frozen.
import {isFrozen} from 'is';
isFrozen ( Object.freeze ( {} ) ); // => true
isFrozen ( {} ); // => false
Checks if a value is a function.
import {isFunction} from 'is';
isFunction ( isFunction ); // => true
isFunction ( { call: () => {} } ); // => false
Checks if a value is a generator function. Note that this will return false for async generator functions.
import {isGeneratorFunction} from 'is';
isGeneratorFunction ( function* () {} ); // => true
isGeneratorFunction ( function () {} ); // => false
Checks if a value is a Int8Array.
import {isInt8Array} from 'is';
isInt8Array ( new Int8Array () ); // => true
isInt8Array ( [] ); // => false
Checks if a value is a Int16Array.
import {isInt16Array} from 'is';
isInt16Array ( new Int16Array () ); // => true
isInt16Array ( [] ); // => false
Checks if a value is a Int32Array.
import {isInt32Array} from 'is';
isInt32Array ( new Int32Array () ); // => true
isInt32Array ( [] ); // => false
Checks if a value is an integer.
import {isInteger} from 'is';
isInteger ( 0 ); // => true
isInteger ( -1 ); // => true
isInteger ( 1.2 ); // => false
Checks if a value is an iterable.
import {isIterable} from 'is';
isIterable ( [] ); // => true
isIterable ( {} ); // => false
Checks if a value could be a valid length index.
import {isLength} from 'is';
isLength ( 0 ); // => true
isLength ( -1 ); // => false
isLength ( 1.2 ); // => false
isLength ( Infinity ); // => false
Checks if a value is a Map.
import {isMap} from 'is';
isMap ( new Map () ); // => true
isMap ( {} ); // => false
Checks if a value is exactly NaN.
import {isNaN} from 'is';
isNaN ( NaN ); // => true
isNaN ( undefined ); // => false
Checks if a value is likely a native function.
import {isNative} from 'is';
isNative ( [].push ); // => true
isNative ( isNative ); // => false
Checks if a value is a negative zero, which if you didn't know is detectably different from a positive zero, for real.
import {isNegativeZero} from 'is';
isNegativeZero ( -0 ); // => true
isNegativeZero ( 0 ); // => false
Checks if a value is null or undefined.
import {isNil} from 'is';
isNil ( null ); // => true
isNil ( undefined ); // => true
isNil ( {} ); // => false
Checks if a value is likely a DOM node.
import {isNode} from 'is';
isNode ( document.body ); // => true
isNode ( undefined ); // => false
Checks if a value is null.
import {isNull} from 'is';
isNull ( null ); // => true
isNull ( undefined ); // => false
Checks if a value is a number.
import {isNumber} from 'is';
isNumber ( 0 ); // => true
isNumber ( Infinity ); // => true
isNumber ( -Infinity ); // => true
isNumber ( NaN ); // => true
isNumber ( '0' ); // => false
Checks if a string can be safely converted to a number.
import {isNumberLike} from 'is';
isNumberLike ( '3' ); // => true
isNumberLike ( '12.3' ); // => true
isNumberLike ( '1e100' ); // => true
isNumberLike ( '0xff' ); // => true
isNumberLike ( 'foo' ); // => false
Checks if a value is an object (not necessarily a plain object).
import {isObjectLike} from 'is';
isObjectLike ( {} ); // => true
isObjectLike ( [] ); // => true
isObjectLike ( isObjectLike ); // => false
Checks if a value is not a primitive. This is the opposite of isPrimitive.
import {isObject} from 'is';
isObject ( {} ); // => true
isObject ( [] ); // => true
isObject ( isObject ); // => true
isObject ( 123 ); // => false
Checks if a value is an odd integer.
import {isOdd} from 'is';
isOdd ( 1 ); // => true
isOdd ( 2 ); // => false
Checks if a value is a plain object.
import {isPlainObject} from 'is';
isPlainObject ( {} ); // => true
isPlainObject ( [] ); // => false
isPlainObject ( isPlainObject ); // => false
Checks if a value is a primitive. This is the opposite of isObject.
import {isPrimitive} from 'is';
isPrimitive ( null ); // => true
isPrimitive ( undefined ); // => true
isPrimitive ( '' ); // => true
isPrimitive ( 0 ); // => true
isPrimitive ( 0n ); // => true
isPrimitive ( true ); // => true
isPrimitive ( Symbol () ); // => true
isPrimitive ( {} ); // => false
isPrimitive ( isPrimitive ); // => false
Checks if a value is a Promise.
import {isPromise} from 'is';
isPromise ( Promise.resolve () ); // => true
isPromise ( Promise.reject () ); // => true
isPromise ( { then: () => {} } ); // => false
Checks if a value is likely a prototype.
import {isPrototype} from 'is';
isPrototype ( Array.prototype ); // => true
isPrototype ( isPrototype ); // => false
Checks if a value is likely a regex.
import {isRegExp} from 'is';
isRegExp ( /x/ ); // => true
isRegExp ( new RegExp ( 'x' ) ); // => true
isRegExp ( 'x' ); // => false
Checks if a value is sealed.
import {isSealed} from 'is';
isSealed ( Object.seal ( {} ) ); // => true
isSealed ( {} ); // => false
Checks if a value is an integer that can be represented faithfully in JavaScript.
import {isSafeInteger} from 'is';
isSafeInteger ( 0 ); // => true
isSafeInteger ( Number.MAX_SAFE_INTEGER ); // => true
isSafeInteger ( -Number.MAX_SAFE_INTEGER ); // => true
isSafeInteger ( Number.MAX_SAFE_INTEGER + 1 ); // => false
Checks if a value is a Set.
import {isSet} from 'is';
isSet ( new Set () ); // => true
isSet ( [] ); // => false
Checks if a value is a SharedArrayBuffer object.
import {isSharedArrayBuffer} from 'is';
isSharedArrayBuffer ( new SharedArrayBuffer ( 8 ) ); // => true
isSharedArrayBuffer ( [] ); // => false
Checks if a value is a string.
import {isString} from 'is';
isString ( 'foo' ); // => true
isString ( ['f', 'o', 'o'] ); // => false
Checks if a value is a symbol.
import {isSymbol} from 'is';
isSymbol ( Symbol () ); // => true
isSymbol ( {} ); // => false
Checks if a value is likely a DOM text.
import {isText} from 'is';
isText ( new Text ( 'foo' ) ); // => true
isText ( 'foo ); // => false
Checks if a value is truthy.
import {isTruthy} from 'is';
isTruthy ( [] ); // => true
isTruthy ( 0 ); // => false
isTruthy ( '' ); // => false
Checks if a value is a TypedArray.
import {isTypedArray} from 'is';
isTypedArray ( new Int8Array ( 8 ) ); // => true
isTypedArray ( [] ); // => false
Checks if a value is a Uint8Array.
import {isUint8Array} from 'is';
isUint8Array ( new Uint8Array () ); // => true
isUint8Array ( [] ); // => false
Checks if a value is a Uint8ClampedArray.
import {isUint8ClampedArray} from 'is';
isUint8ClampedArray ( new Uint8ClampedArray () ); // => true
isUint8ClampedArray ( [] ); // => false
Checks if a value is a Uint16Array.
import {isUint16Array} from 'is';
isUint16Array ( new Uint16Array () ); // => true
isUint16Array ( [] ); // => false
Checks if a value is a Uint32Array.
import {isUint32Array} from 'is';
isUint32Array ( new Uint32Array () ); // => true
isUint32Array ( [] ); // => false
Checks if a value is undefined.
import {isUndefined} from 'is';
isUndefined ( undefined ); // => true
isUndefined ( null ); // => false
Checks if a value is a WeakMap.
import {isWeakMap} from 'is';
isWeakMap ( new WeakMap () ); // => true
isWeakMap ( new Map () ); // => false
Checks if a value is a WeakRef.
import {isWeakRef} from 'is';
isWeakRef ( new WeakRef ( WeakRef ) ); // => true
isWeakRef ( WeakRef ) ); // => false
Checks if a value can be held weakly, via WeakRef, WeakMap and WeakSet.
import {isWeakReferable} from 'is';
isWeakReferable ( {} ); // => true
isWeakReferable ( 123 ) ); // => false
Checks if a value is a WeakSet.
import {isWeakSet} from 'is';
isWeakSet ( new WeakSet () ); // => true
isWeakSet ( new Set () ); // => false
Checks if a value is the Window object.
import {isWindow} from 'is';
isWindow ( globalThis.window ); // => true, in a browser environment
isWindow ( {} ) ); // => false
- Parts: MIT Β© Fabio Spampinato.
- Parts: MIT Β© lodash.