Is
The definitive collection of is* functions for runtime type checking. Lodash-compatible, tree-shakable, with types.
Install / Use
/learn @fabiospampinato/IsREADME
Is
The definitive collection of is* functions for runtime type checking. Realms support, tree-shakable, with types.
Every function provided accepts a single argument of unknown type and returns a boolean, almost always as a TypeScript type guard.
Install
npm install is@npm:@fabiospampinato/is
Functions
| Primitives | Boxed Primitives | Built-ins | DOM | Typed Array | | --------------------------- | ------------------------------------- | ------------------------------------------- | ----------------------------------------- | ------------------------------------------- | | isPrimitive | isBoxedPrimitive | isArray | isAttribute | isTypedArray | | isBigInt | isBoxedBigInt | isArguments | isComment | isInt8Array | | isBoolean | isBoxedBoolean | isArrayBuffer | isDocument | isInt16Array | | isNil | isBoxedNumber | isArrayLike | isDocumentFragment | isInt32Array | | isNull | isBoxedString | isAsyncIterable | isDocumentType | isUint8Array | | isNumber | isBoxedSymbol | isBlob | isElement | isUint8ClampedArray | | isString | | isBuffer | isNode | isUint16Array | | isSymbol | | isClass | isText | isUint32Array | | isUndefined | | isDataView | isWindow | isFloat32Array | | | | isDate | | isFloat64Array | | | | isError | | isBigInt64Array | | | | isIterable | | isBigUint64Array | | | | isMap | | | | | | isNative | | | | | | isPromise | | | | | | isRegExp | | | | | | isSet | | | | | | isSharedArrayBuffer | | | | | | isWeakMap | | | | | | isWeakRef | | | | | | isWeakSet | | |
| Function | Number | Object | Others | | ----------------------------------------------------- | --------------------------------- | --------------------------------------- | ----------------------------------- | | isArrowFunction | isEven | isArrayLikeObject | isDefined | | isAsyncFunction | isFinite | isFrozen | isEmpty | | isAsyncGeneratorFunction | isFloat | isObject | isFalsy | | isBoundFunction | isInteger | isObjectLike | isTruthy | | isFunction | isLength | isPlainObject | isWeakReferable | | isGeneratorFunction | isNaN | isPrototype | | | | isNegativeZero | isSealed | | | | isNumberLike | | | | | isOdd | | | | | isSafeInteger | | |
Usage
isArguments
Checks if a value is an arguments object.
import {isArguments} from 'is';
const args = (function () { return arguments; })();
isArguments ( args ); // => true
isArguments ( [] ); // => false
isArrayBuffer
Checks if a value is an ArrayBuffer object.
import {isArrayBuffer} from 'is';
isArrayBuffer ( new ArrayBuffer ( 8 ) ); // => true
isArrayBuffer ( [] ); // => false
isArrayLikeObject
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
isArrayLike
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
isArray
Checks if a value is an Array.
import {isArray} from 'is';
isArray ( [] ); // => true
isArray ( {} ); // => false
isArrowFunction
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
isAsyncFunction
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
isAsyncGeneratorFunction
Checks if a value is an async generator function.
import {isAsyncGeneratorFunction} from 'is';
isAsyncGeneratorFunction ( function* () {} ); // => true
isAsyncGeneratorFunction ( function () {} ); // => false
isAsyncIterable
Checks if a value is an async iterable.
import {isAsyncIterable} from 'is';
const myAsyncIterable = {
async * [Symbol.asyncIterator]() {
yield 'hello';
}
};
isAsyncIterable ( myAsyncIterable ); // => true
isAsyncIterable ( [] ); // => false
isAttribute
Checks if a value is likely a DOM attribute.
import {isAttribute} from 'is';
isAttribute ( document.createAttribute ( 'foo' ) ); // => true
isAttribute ( body ); // => false
isBigInt
Checks if a value is a bigint.
import {isBigInt} from 'is';
isBigInt ( 0n ); // => true
isBigInt ( 0 ); // => false
isBigInt64Array
Checks if a value is a BigInt64Array.
import {isBigInt64Array} from 'i
