Osmium project - Type detector
npm install @osmium/isnull, undefined, array, object, string, boolean, number, symbol, function, async function, etc.
empty, iterable, plain object, native object, etc.
JSON, GUID, RegExp, Map, Set, WeakMap, WeakSet, Date, Error, Promise, TypedArray, etc.
bash
npm install @osmium/is
`
or
`bash
yarn add @osmium/is
`
API Reference
$3
Checks if value is null.
`typescript
import { isNull } from '@osmium/is';
isNull(null); // true
isNull(undefined); // false
`
$3
Checks if value is undefined.
`typescript
import { isUndefined } from '@osmium/is';
isUndefined(undefined); // true
isUndefined(null); // false
`
$3
Checks if value is a function (including async functions).
`typescript
import { isFunction } from '@osmium/is';
isFunction(() => {}); // true
isFunction(async () => {}); // true
`
$3
Checks if value is an async function. Optionally accepts a RegExp or string pattern for custom detection (e.g., for transpiled async functions).
`typescript
import { isAsyncFunction } from '@osmium/is';
isAsyncFunction(async () => {}); // true
isAsyncFunction(() => {}); // false
`
$3
Checks if value is an array.
`typescript
import { isArray } from '@osmium/is';
isArray([1, 2, 3]); // true
isArray({}); // false
`
$3
Checks if value is an empty array.
`typescript
import { isArrayEmpty } from '@osmium/is';
isArrayEmpty([]); // true
isArrayEmpty([1]); // false
`
$3
Checks if value is a plain object.
`typescript
import { isObject } from '@osmium/is';
isObject({ a: 1 }); // true
isObject(new Date()); // false
`
$3
Checks if value is an empty object.
`typescript
import { isObjectEmpty } from '@osmium/is';
isObjectEmpty({}); // true
isObjectEmpty({ a: 1 }); // false
`
$3
Checks if value is a string.
`typescript
import { isString } from '@osmium/is';
isString('hello'); // true
isString(123); // false
`
$3
Checks if value is a boolean.
`typescript
import { isBoolean } from '@osmium/is';
isBoolean(true); // true
isBoolean(0); // false
`
$3
Checks if value is a finite number (not NaN, not Infinity).
`typescript
import { isNumber } from '@osmium/is';
isNumber(42); // true
isNumber(Infinity); // false
`
$3
Checks if value is a number (including Infinity, -Infinity).
`typescript
import { isNumeric } from '@osmium/is';
isNumeric(42); // true
isNumeric(Infinity); // true
`
$3
Checks if value is a safe integer.
`typescript
import { isInteger } from '@osmium/is';
isInteger(10); // true
isInteger(10.5); // false
`
$3
Checks if value is a float (not an integer).
`typescript
import { isFloat } from '@osmium/is';
isFloat(3.14); // true
isFloat(10); // false
`
$3
Checks if value is a positive integer (>= 0).
`typescript
import { isPositiveInteger } from '@osmium/is';
isPositiveInteger(5); // true
isPositiveInteger(-5); // false
`
$3
Checks if value is a positive number (>= 0).
`typescript
import { isPositiveNumber } from '@osmium/is';
isPositiveNumber(0.1); // true
isPositiveNumber(-1); // false
`
$3
Checks if value is a symbol, optionally with a specific description.
`typescript
import { isSymbol } from '@osmium/is';
isSymbol(Symbol('x')); // true
isSymbol(Symbol('x'), 'x'); // true
`
$3
Checks if value is a regular expression.
`typescript
import { isRegExp } from '@osmium/is';
isRegExp(/abc/); // true
isRegExp('/abc/'); // false
`
$3
Checks if value is a Map.
`typescript
import { isMap } from '@osmium/is';
isMap(new Map()); // true
`
$3
Checks if value is a Set.
`typescript
import { isSet } from '@osmium/is';
isSet(new Set()); // true
`
$3
Checks if value is a WeakMap.
`typescript
import { isWeakMap } from '@osmium/is';
isWeakMap(new WeakMap()); // true
`
$3
Checks if value is a WeakSet.
`typescript
import { isWeakSet } from '@osmium/is';
isWeakSet(new WeakSet()); // true
`
$3
Checks if value is a Promise.
`typescript
import { isPromise } from '@osmium/is';
isPromise(Promise.resolve()); // true
`
$3
Checks if value is a valid Date object.
`typescript
import { isDate } from '@osmium/is';
isDate(new Date()); // true
`
$3
Checks if value is an Error object.
`typescript
import { isError } from '@osmium/is';
isError(new Error('fail')); // true
`
$3
Checks if value is a plain object (its prototype is Object or null).
`typescript
import { isPlainObject } from '@osmium/is';
isPlainObject({}); // true
isPlainObject(Object.create(null)); // true
`
$3
Checks if value is a TypedArray.
`typescript
import { isTypedArray } from '@osmium/is';
isTypedArray(new Uint8Array()); // true
`
$3
Checks if value is null, undefined, or an empty string.
`typescript
import { isNilOrEmpty } from '@osmium/is';
isNilOrEmpty(null); // true
isNilOrEmpty(''); // true
`
$3
Checks if value is empty (array, string, object, Map, or Set).
`typescript
import { isEmpty } from '@osmium/is';
isEmpty([]); // true
isEmpty({}); // true
isEmpty(''); // true
`
$3
Checks if value is iterable (a non-empty array, Map, Set, or an object with keys).
`typescript
import { isIterable } from '@osmium/is';
isIterable([1, 2, 3]); // true
isIterable([]); // false
`
$3
Checks if value is async iterable.
`typescript
import { isAsyncIterable } from '@osmium/is';
isAsyncIterable({ async *[Symbol.asyncIterator]() {} }); // true
`
$3
Checks if value is a valid JSON string.
`typescript
import { isJSON } from '@osmium/is';
isJSON('{"a":1}'); // true
isJSON('not json'); // false
`
$3
Checks if value is a valid GUID.
`typescript
import { isGUID } from '@osmium/is';
isGUID('123e4567-e89b-12d3-a456-426614174000'); // true
`
$3
Checks if value is a valid GUID v4.
`typescript
import { isGUIDv4 } from '@osmium/is';
isGUIDv4('123e4567-e89b-42d3-a456-426614174000'); // true
`
$3
Checks if value is a native object (not an array, function, or other special objects).
`typescript
import { isNativeObject } from '@osmium/is';
isNativeObject({}); // true
isNativeObject([]); // false
`
Testing
To run all tests, use your favorite package manager:
`bash
npm test
`
or
`bash
yarn test
``