Skip to main content

Value Assertions Utilities Functions

A collection of utility functions for checking the type and validity of values.


isActive(value: any, ...expectedValues: any[]): boolean

Checks if a value is considered "active" (matches predefined keywords or matches one of the expected values).

Active values include:

  • "active", "yes", "true", "current", "selected", "checked", 1, true

Parameters:

  • value: The value to evaluate.
  • expectedValues: Optional list of values to compare against.

Returns:

  • true if value is "active", otherwise false.

Example:

untitled
isActive("yes"); // true
isActive("inactive", "pending", "inactive"); // true
isActive("disabled"); // false

empty(value: any): boolean

isEmpty(value: any): boolean

Checks if a value is considered empty (null, undefined, empty string, empty array, or empty object).

Example:

untitled
empty(""); // true
empty([]); // true
empty({}); // true
empty(null); // true
empty("text"); // false

isSet(value: any): boolean

Returns true if the value is neither undefined nor null.

Example:

untitled
isSet("hello"); // true
isSet(null); // false

isBoolean(value: any): boolean

Checks if a value is of type boolean.

Example:

untitled
isBoolean(true); // true
isBoolean("true"); // false

isString(value: any): boolean

Checks if a value is a string.

Example:

untitled
isString("hello"); // true

isNumber(value: any): boolean

Checks if a value is a finite number.

Example:

untitled
isNumber(123); // true
isNumber(Infinity); // false

isObject(value: any): boolean

Checks if a value is an object (but not null or an array).

Example:

untitled
isObject({}); // true
isObject([]); // false

isArray(value: any): boolean

Checks if a value is an array.

Example:

untitled
isArray([1, 2]); // true

isFunction(value: any): boolean

Checks if a value is a function.

Example:

untitled
isFunction(() => {}); // true

isDate(value: any): boolean

Checks if a value is a valid Date object.

Example:

untitled
isDate(new Date()); // true
isDate("2023-01-01"); // false

isRegExp(value: any): boolean

Checks if a value is a RegExp.

Example:

untitled
isRegExp(/abc/); // true

isNull(value: any): boolean

Checks if a value is null.


isUndefined(value: any): boolean

Checks if a value is undefined.


isInteger(value: any): boolean

Checks if a value is an integer.

Example:

untitled
isInteger(42); // true
isInteger(42.1); // false

isPlainObject(value: any): boolean

Checks if a value is a plain object ({}), not an instance of a custom class, array, or built-in type.

Example:

untitled
isPlainObject({}); // true
isPlainObject(new Date()); // false

isPromise(value: any): boolean

Checks if a value is a Promise (i.e., has a .then() method).

Example:

untitled
isPromise(Promise.resolve()); // true

isSymbol(value: any): boolean

Checks if a value is a Symbol.


isBigInt(value: any): boolean

Checks if a value is a BigInt.

Example:

untitled
isBigInt(10n); // true

isMap(value: any): boolean

Checks if a value is a Map.


isSetType(value: any): boolean

Checks if a value is a Set.

note

Named isSetType to avoid conflict with isSet.

isError(value: any): boolean

Checks if a value is an instance of Error.

Example:

untitled
isError(new Error("Oops")); // true

isURL(value: any): boolean

Checks if a string is a valid URL.

Example:

untitled
isURL("https://example.com"); // true
isURL("not a url"); // false

isValidJSON(value: any): boolean

Checks if a string is a valid JSON.

Example:

untitled
isValidJSON('{"name":"John"}'); // true
isValidJSON("{bad json}"); // false

isIdentifier(value: string): boolean

Checks if a string is a valid JavaScript identifier.

Example:

untitled
isIdentifier("myVar"); // true
isIdentifier("123abc"); // false