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", otherwisefalse
.
Example:
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:
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:
isSet("hello"); // true
isSet(null); // false
isBoolean(value: any): boolean
Checks if a value is of type boolean
.
Example:
isBoolean(true); // true
isBoolean("true"); // false
isString(value: any): boolean
Checks if a value is a string.
Example:
isString("hello"); // true
isNumber(value: any): boolean
Checks if a value is a finite number.
Example:
isNumber(123); // true
isNumber(Infinity); // false
isObject(value: any): boolean
Checks if a value is an object (but not null
or an array).
Example:
isObject({}); // true
isObject([]); // false
isArray(value: any): boolean
Checks if a value is an array.
Example:
isArray([1, 2]); // true
isFunction(value: any): boolean
Checks if a value is a function.
Example:
isFunction(() => {}); // true
isDate(value: any): boolean
Checks if a value is a valid Date
object.
Example:
isDate(new Date()); // true
isDate("2023-01-01"); // false
isRegExp(value: any): boolean
Checks if a value is a RegExp
.
Example:
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:
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:
isPlainObject({}); // true
isPlainObject(new Date()); // false
isPromise(value: any): boolean
Checks if a value is a Promise (i.e., has a .then()
method).
Example:
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:
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
.
Named
isSetType
to avoid conflict withisSet
.
isError(value: any): boolean
Checks if a value is an instance of Error
.
Example:
isError(new Error("Oops")); // true
isURL(value: any): boolean
Checks if a string is a valid URL.
Example:
isURL("https://example.com"); // true
isURL("not a url"); // false
isValidJSON(value: any): boolean
Checks if a string is a valid JSON.
Example:
isValidJSON('{"name":"John"}'); // true
isValidJSON("{bad json}"); // false
isIdentifier(value: string): boolean
Checks if a string is a valid JavaScript identifier.
Example:
isIdentifier("myVar"); // true
isIdentifier("123abc"); // false