predicates
Variables
isBoolean
Checks if the given value is boolean.
This function tests whether the provided value is strictly boolean.
It returns true if the value is boolean, and false otherwise.
This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to boolean.
Param
The Value to test if it is boolean.
Returns
True if the value is boolean, false otherwise.
Example
const value1 = true;
const value2 = 0;
const value3 = 'abc';
console.log(isBoolean(value1)); // true
console.log(isBoolean(value2)); // false
console.log(isBoolean(value3)); // false
See
Powered by es-toolkit (MIT License): https://github.com/toss/es-toolkit
isDate
Checks if value is a Date object.
Param
The value to check.
Returns
Returns true if value is a Date object, false otherwise.
Example
const value1 = new Date();
const value2 = '2024-01-01';
console.log(isDate(value1)); // true
console.log(isDate(value2)); // false
See
Powered by es-toolkit (MIT License): https://github.com/toss/es-toolkit
isEmptyObject
Checks if a value is an empty plain object.
Param
The value to check.
Returns
- True if the value is an empty plain object, otherwise false.
Example
isEmptyObject({}); // true
isEmptyObject({ a: 1 }); // false
isEmptyObject([]); // false
isEmptyObject(null); // false
See
Powered by es-toolkit (MIT License): https://github.com/toss/es-toolkit
isEqual
Checks if two values are equal, including support for Date, RegExp, and deep object comparison.
Param
The first value to compare.
Param
The second value to compare.
Returns
true if the values are equal, otherwise false.
Example
isEqual(1, 1); // true
isEqual({ a: 1 }, { a: 1 }); // true
isEqual(/abc/g, /abc/g); // true
isEqual(new Date('2020-01-01'), new Date('2020-01-01')); // true
isEqual([1, 2, 3], [1, 2, 3]); // true
See
Powered by es-toolkit (MIT License): https://github.com/toss/es-toolkit
isError
Checks if value is an Error object.
Param
The value to check.
Returns
Returns true if value is an Error object, false otherwise.
Example
console.log(isError(new Error())); // true
console.log(isError('Error')); // false
console.log(isError({ name: 'Error', message: '' })); // false
See
Powered by es-toolkit (MIT License): https://github.com/toss/es-toolkit
isFunction
Checks if value is a function.
Param
The value to check.
Returns
Returns true if value is a function, else false.
Example
isFunction(Array.prototype.slice); // true
isFunction(async function () {}); // true
isFunction(function* () {}); // true
isFunction(Proxy); // true
isFunction(Int8Array); // true
See
Powered by es-toolkit (MIT License): https://github.com/toss/es-toolkit
isJSON
Checks if a given value is a valid JSON string.
A valid JSON string is one that can be successfully parsed using JSON.parse(). According to JSON
specifications, valid JSON can represent:
- Objects (with string keys and valid JSON values)
- Arrays (containing valid JSON values)
- Strings
- Numbers
- Booleans
- null
String values like "null", "true", "false", and numeric strings (e.g., "42") are considered
valid JSON and will return true.
This function serves as a type guard in TypeScript, narrowing the type of the argument to string.
Param
The value to check.
Returns
Returns true if value is a valid JSON string, else false.
Example
isJSON('{"name":"John","age":30}'); // true
isJSON('[1,2,3]'); // true
isJSON('true'); // true
isJSON('invalid json'); // false
isJSON({ name: 'John' }); // false (not a string)
isJSON(null); // false (not a string)
See
Powered by es-toolkit (MIT License): https://github.com/toss/es-toolkit
isJSONArray
Checks if a given value is a valid JSON value.
A valid JSON value can be: - null - a JSON object (an object with string keys and valid JSON values) - a JSON array (an array of valid JSON values) - a string - a number - a boolean
Param
The value to check.
Returns
- True if the value is a valid JSON value, otherwise false.
Example
console.log(isJSONValue(null)); // true
console.log(isJSONValue({ key: "value" })); // true
console.log(isJSONValue([1, 2, 3])); // true
console.log(isJSONValue("Hello")); // true
console.log(isJSONValue(42)); // true
console.log(isJSONValue(true)); // true
console.log(isJSONValue(undefined)); // false
console.log(isJSONValue(() => {})); // false
See
Powered by es-toolkit (MIT License): https://github.com/toss/es-toolkit
isJSONObject
Checks if a given value is a valid JSON value.
A valid JSON value can be: - null - a JSON object (an object with string keys and valid JSON values) - a JSON array (an array of valid JSON values) - a string - a number - a boolean
Param
The value to check.
Returns
- True if the value is a valid JSON value, otherwise false.
Example
console.log(isJSONValue(null)); // true
console.log(isJSONValue({ key: "value" })); // true
console.log(isJSONValue([1, 2, 3])); // true
console.log(isJSONValue("Hello")); // true
console.log(isJSONValue(42)); // true
console.log(isJSONValue(true)); // true
console.log(isJSONValue(undefined)); // false
console.log(isJSONValue(() => {})); // false
See
Powered by es-toolkit (MIT License): https://github.com/toss/es-toolkit
isJSONValue
Checks if a given value is a valid JSON value.
A valid JSON value can be: - null - a JSON object (an object with string keys and valid JSON values) - a JSON array (an array of valid JSON values) - a string - a number - a boolean
Param
The value to check.
Returns
- True if the value is a valid JSON value, otherwise false.
Example
console.log(isJSONValue(null)); // true
console.log(isJSONValue({ key: "value" })); // true
console.log(isJSONValue([1, 2, 3])); // true
console.log(isJSONValue("Hello")); // true
console.log(isJSONValue(42)); // true
console.log(isJSONValue(true)); // true
console.log(isJSONValue(undefined)); // false
console.log(isJSONValue(() => {})); // false
See
Powered by es-toolkit (MIT License): https://github.com/toss/es-toolkit
isMap
Checks if a given value is Map.
This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to Map.
Param
The value to check if it is a Map.
Returns
Returns true if value is a Map, else false.
Example
const value1 = new Map();
const value2 = new Set();
const value3 = new WeakMap();
console.log(isMap(value1)); // true
console.log(isMap(value2)); // false
console.log(isMap(value3)); // false
See
Powered by es-toolkit (MIT License): https://github.com/toss/es-toolkit
isNil
Checks if a given value is null or undefined.
This function tests whether the provided value is either null or undefined.
It returns true if the value is null or undefined, and false otherwise.
This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to null or undefined.
Param
The value to test for null or undefined.
Returns
true if the value is null or undefined, false otherwise.
Example
const value1 = null;
const value2 = undefined;
const value3 = 42;
const result1 = isNil(value1); // true
const result2 = isNil(value2); // true
const result3 = isNil(value3); // false
See
Powered by es-toolkit (MIT License): https://github.com/toss/es-toolkit
isNotNil
Checks if the given value is not null nor undefined.
The main use of this function is to be used with TypeScript as a type predicate.
Template
The type of value.
Param
The value to test if it is not null nor undefined.
Returns
True if the value is not null nor undefined, false otherwise.
Example
// Here the type of `arr` is (number | undefined)[]
const arr = [1, undefined, 3];
// Here the type of `result` is number[]
const result = arr.filter(isNotNil);
// result will be [1, 3]
See
Powered by es-toolkit (MIT License): https://github.com/toss/es-toolkit
isNull
Checks if the given value is null.
This function tests whether the provided value is strictly equal to null.
It returns true if the value is null, and false otherwise.
This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to null.
Param
The value to test if it is null.
Returns
True if the value is null, false otherwise.
Example
const value1 = null;
const value2 = undefined;
const value3 = 42;
console.log(isNull(value1)); // true
console.log(isNull(value2)); // false
console.log(isNull(value3)); // false
See
Powered by es-toolkit (MIT License): https://github.com/toss/es-toolkit
isNumber
Checks if the given value is a number.
This function tests whether the provided value is strictly a number.
It returns true if the value is a number, and false otherwise.
This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to number.
Param
The value to test if it is a number.
Returns
True if the value is a number, false otherwise.
Example
const value1 = 123;
const value2 = 'abc';
const value3 = true;
console.log(isNumber(value1)); // true
console.log(isNumber(value2)); // false
console.log(isNumber(value3)); // false
See
Powered by es-toolkit (MIT License): https://github.com/toss/es-toolkit
isPlainObject
Checks if a given value is a plain object.
Param
The value to check.
Returns
- True if the value is a plain object, otherwise false.
Example
// ✅👇 True
isPlainObject({ }); // ✅
isPlainObject({ key: 'value' }); // ✅
isPlainObject({ key: new Date() }); // ✅
isPlainObject(new Object()); // ✅
isPlainObject(Object.create(null)); // ✅
isPlainObject({ nested: { key: true} }); // ✅
isPlainObject(new Proxy({}, {})); // ✅
isPlainObject({ [Symbol('tag')]: 'A' }); // ✅
// ✅👇 (cross-realms, node context, workers, ...)
const runInNewContext = await import('node:vm').then(
(mod) => mod.runInNewContext
);
isPlainObject(runInNewContext('({})')); // ✅
// ❌👇 False
class Test { };
isPlainObject(new Test()) // ❌
isPlainObject(10); // ❌
isPlainObject(null); // ❌
isPlainObject('hello'); // ❌
isPlainObject([]); // ❌
isPlainObject(new Date()); // ❌
isPlainObject(new Uint8Array([1])); // ❌
isPlainObject(Buffer.from('ABC')); // ❌
isPlainObject(Promise.resolve({})); // ❌
isPlainObject(Object.create({})); // ❌
isPlainObject(new (class Cls {})); // ❌
isPlainObject(globalThis); // ❌,
See
Powered by es-toolkit (MIT License): https://github.com/toss/es-toolkit
isPrimitive
Checks whether a value is a JavaScript primitive. JavaScript primitives include null, undefined, strings, numbers, booleans, symbols, and bigints.
Param
The value to check.
Returns
Returns true if value is a primitive, false otherwise.
Example
isPrimitive(null); // true
isPrimitive(undefined); // true
isPrimitive('123'); // true
isPrimitive(false); // true
isPrimitive(true); // true
isPrimitive(Symbol('a')); // true
isPrimitive(123n); // true
isPrimitive({}); // false
isPrimitive(new Date()); // false
isPrimitive(new Map()); // false
isPrimitive(new Set()); // false
isPrimitive([1, 2, 3]); // false
See
Powered by es-toolkit (MIT License): https://github.com/toss/es-toolkit
isRegExp
Checks if value is a RegExp.
Param
The value to check.
Returns
Returns true if value is a RegExp, false otherwise.
Example
const value1 = /abc/;
const value2 = '/abc/';
console.log(isRegExp(value1)); // true
console.log(isRegExp(value2)); // false
See
Powered by es-toolkit (MIT License): https://github.com/toss/es-toolkit
isSet
Checks if a given value is Set.
This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to Set.
Param
The value to check if it is a Set.
Returns
Returns true if value is a Set, else false.
Example
const value1 = new Set();
const value2 = new Map();
const value3 = new WeakSet();
console.log(isSet(value1)); // true
console.log(isSet(value2)); // false
console.log(isSet(value3)); // false
See
Powered by es-toolkit (MIT License): https://github.com/toss/es-toolkit
isString
Checks if a given value is string.
This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to string.
Param
The value to check if it is string.
Returns
Returns true if value is a string, else false.
Example
const value1 = 'abc';
const value2 = 123;
const value3 = true;
console.log(isString(value1)); // true
console.log(isString(value2)); // false
console.log(isString(value3)); // false
See
Powered by es-toolkit (MIT License): https://github.com/toss/es-toolkit
isUndefined
Checks if the given value is undefined.
This function tests whether the provided value is strictly equal to undefined.
It returns true if the value is undefined, and false otherwise.
This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to undefined.
Param
The value to test if it is undefined.
Returns
true if the value is undefined, false otherwise.
Example
const value1 = undefined;
const value2 = null;
const value3 = 42;
console.log(isUndefined(value1)); // true
console.log(isUndefined(value2)); // false
console.log(isUndefined(value3)); // false
See
Powered by es-toolkit (MIT License): https://github.com/toss/es-toolkit