is-kit

object

Object/collection/structured data guards.

import {
isFunction,
isObject,
isPlainObject,
isArray,
isDate,
isRegExp,
isMap,
isSet,
isPromiseLike,
isIterable,
isAsyncIterable,
isArrayBuffer,
isDataView,
isTypedArray,
isError,
isURL,
isBlob,
} from 'is-kit';
// Function / Object basics
isFunction(() => {}); // true
isObject({}); // true
isObject(null); // false
isPlainObject({ a: 1 }); // true
isPlainObject(Object.create(null)); // true
// Collections
isArray([]); // true
isMap(new Map()); // true
isSet(new Set()); // true
// Date / RegExp
isDate(new Date()); // true
isDate(new Date('invalid')); // false
isRegExp(/abc/); // true
// Promise-like / Iterables
isPromiseLike(Promise.resolve()); // true
isPromiseLike({ then() {} }); // true
isIterable(new Set([1, 2, 3])); // true
const asyncGen = (async function* () { yield 1; })();
isAsyncIterable(asyncGen); // true
// Binary data
isArrayBuffer(new ArrayBuffer(8)); // true
isDataView(new DataView(new ArrayBuffer(8))); // true
isTypedArray(new Uint8Array([1, 2])); // true
// Errors and web types
isError(new Error('boom')); // true
isURL(new URL('https://example.com')); // true
isBlob(new Blob(['hi'])); // true