predictype / PredicType / PredicType
const
PredicType:object
Defined in: PredicType.ts:14
array:
object
comparison: <
T
>(source
,oper
,target
) =>boolean
=arrays.arrayComparison
Compares two arrays using a variety of comparison operations.
T
Type of the array elements.
T
[]
The source array to compare.
The comparison operation to perform (EQUALS, NOT_EQUALS, SAME_MEMBERS, SET_EQUALS, SET_NOT_EQUALS).
T
[]
The target array to compare against the source.
boolean
True if the comparison is valid according to the operator, otherwise false.
If the operation is not recognized.
arrayComparison([1, 2, 3], 'equals', [1, 2, 3]); // true
arrayComparison([1, 2, 3], 'equals', [3, 2, 1]); // false
arrayComparison([1, 2, 3], 'not_equals', [1, 2, 4]); // true
arrayComparison([1, 2, 2], 'same_members', [2, 1, 2]); // true
arrayComparison([1, 2, 2], 'same_members', [2, 1]); // false
arrayComparison([1, 2, 2], 'set_equals', [2, 1]); // true
arrayComparison([1, 2, 2], 'set_equals', [2, 1, 3]); // false
arrayComparison([1, 2, 2], 'set_not_equals', [2, 1, 3]); // true
arrayComparison([1, 2, 2], 'set_not_equals', [2, 1]); // false
Supported operators:
indexComparison: <
T
>(source
,oper
,index
,target
) =>boolean
=arrays.arrayIndexComparison
Compares the value at a specific index in an array with a target value, using the specified operation.
T
Type of the array elements.
T
[]
The source array.
The comparison operation to perform (e.g. ‘at_index_equals’).
number
The index in the array to compare.
T
The value to compare against the value at the given index.
boolean
True if the comparison is valid according to the operator, otherwise false.
If the operation is not recognized.
const arr = [10, 20, 30];
const idx1 = 1;
const idx2 = 2;
const val1 = 20;
const val2 = 25;
arrayIndexComparison(arr, 'at_index_equals', idx1, val1); // true
arrayIndexComparison(arr, 'at_index_greater_than', idx2, val2); // true
Supported Operators:
indexMembership: <
T
>(source
,oper
,index
,target
) =>boolean
=arrays.arrayIndexMembership
Checks if the value at a specific index in an array is (or is not) included in a target array, using the specified operation.
T
Type of the array elements.
T
[]
The source array.
The membership operation to perform (e.g. ‘at_index_in’).
number
The index in the array to check.
T
[]
The array of values to check for inclusion/exclusion.
boolean
True if the membership check is valid according to the operator, otherwise false.
If the operation is not recognized.
const arr = [10, 20, 30];
const idx1 = 1;
const idx2 = 2;
const values = [10, 20];
arrayIndexMembership(arr, 'at_index_in', idx1, values); // true
arrayIndexMembership(arr, 'at_index_not_in', idx2, values); // true
Supported Operators:
intersection: <
T
>(source
,oper
,target
) =>boolean
=arrays.arrayIntersection
Checks if two arrays are disjoint or intersect, using the specified operation.
T
Type of the array elements.
T
[]
The source array.
The intersection operation to perform (e.g. ‘disjoint’, ‘intersects’).
T
[]
The target array to check against the source.
boolean
True if the intersection check is valid according to the operator, otherwise false.
If the operation is not recognized.
const arr1 = [1, 2, 3];
const arr2 = [4, 5, 6];
const arr3 = [2, 4, 6];
arrayIntersection(arr1, 'disjoint', arr2); // true
arrayIntersection(arr1, 'intersects', arr3); // true
Supported Operators:
membership: <
T
>(source
,oper
,target
) =>boolean
=arrays.arrayMembership
Checks membership conditions for all or some elements in an array, using the specified operation.
T
Type of the array elements.
T
[]
The source array.
The membership operation to perform (e.g. ‘every_equals’, ‘includes’).
T
The value to check for membership.
boolean
True if the membership check is valid according to the operator, otherwise false.
If the operation is not recognized.
const arr1 = [1, 1, 1];
const arr2 = [1, 2, 3];
const value1 = 1;
const value2 = 2;
arrayMembership(arr1, 'every_equals', value1); // true
arrayMembership(arr2, 'includes', value2); // true
Supported Operators:
relation: <
T
>(source
,oper
,target
) =>boolean
=arrays.arrayRelation
Checks if the source array is a subset, strict subset, superset, or strict superset of the target array, using the specified operation.
T
Type of the array elements.
T
[]
The source array.
The relation operation to perform (‘subset_of’, ‘superset_of’, ‘strict_subset_of’, ‘strict_superset_of’).
T
[]
The target array to check against the source.
boolean
True if the relation check is valid according to the operator, otherwise false.
If the operation is not recognized.
arrayRelation([1, 2], 'subset_of', [1, 2, 3]); // true
arrayRelation([1, 2], 'subset_of', [1, 2]); // true (equality allowed)
arrayRelation([1, 2, 3], 'superset_of', [2, 3]); // true
arrayRelation([1, 2], 'superset_of', [1, 2]); // true (equality allowed)
arrayRelation([1, 2], 'strict_subset_of', [1, 2, 3]); // true
arrayRelation([1, 2], 'strict_subset_of', [1, 2]); // false (equality not allowed)
arrayRelation([1, 2, 3], 'strict_superset_of', [2, 3]); // true
arrayRelation([1, 2], 'strict_superset_of', [1, 2]); // false (equality not allowed)
Supported Operators:
sequence: <
T
>(source
,oper
,target
) =>boolean
=arrays.arraySequence
Checks if the source array contains, starts with, or ends with a given subsequence, using the specified operation.
T
Type of the array elements.
T
[]
The source array.
The sequence operation to perform (e.g. ‘contains_subsequence’, ‘starts_with’, ‘ends_with’).
T
[]
The target subsequence array to check against the source.
boolean
True if the sequence check is valid according to the operator, otherwise false.
If the operation is not recognized.
const arr1 = [1, 2, 3, 4];
const arr2 = [2, 3];
const arr3 = [1, 2, 3];
const arr4 = [1, 2];
arraySequence(arr1, 'contains_subsequence', arr2); // true
arraySequence(arr3, 'starts_with', arr4); // true
Supported Operators:
size: (
source
,oper
,target
) =>boolean
=arrays.arraySize
Checks the size of an array against a target value, using the specified operation.
any
[]
The source array.
The size operation to perform (e.g. ‘length_equals’, ‘length_greater_than’).
number
The target size to compare against the array’s length.
boolean
True if the size check is valid according to the operator, otherwise false.
If the operation is not recognized.
const arr = [1, 2, 3];
const len1 = 3;
const len2 = 2;
arraySize(arr, 'length_equals', len1); // true
arraySize(arr, 'length_greater_than', len2); // true
Supported Operators:
state: (
source
,oper
) =>boolean
=arrays.arrayState
Checks if an array is empty or not, using the specified operation.
any
[]
The source array.
The state operation to perform (e.g. ‘is_empty’, ‘is_not_empty’).
boolean
True if the state check is valid according to the operator, otherwise false.
If the operation is not recognized.
const arr1 = [];
const arr2 = [1, 2, 3];
arrayState(arr1, 'is_empty'); // true
arrayState(arr2, 'is_not_empty'); // true
Supported Operators:
bigint:
object
comparison: (
source
,oper
,target
) =>boolean
=bigints.bigintComparison
Compares two bigint values using the specified operation.
bigint
The source bigint value.
The comparison operation to perform (e.g. ‘equals’, ‘greater_than’).
bigint
The target bigint value to compare against the source.
boolean
True if the comparison is valid according to the operator, otherwise false.
If the operation is not recognized.
const a = BigInt(10);
const b = BigInt(5);
const c = BigInt(20);
bigintComparison(a, 'equals', a); // true
bigintComparison(a, 'greater_than', b); // true
bigintComparison(a, 'less_than', c); // true
Supported Operators:
membership: (
source
,oper
,target
) =>boolean
=bigints.bigintMembership
Checks if a bigint value is (or is not) a member of a set of bigints using the specified operation.
bigint
The source bigint value.
The membership operation to perform (e.g. ‘is_one_of’, ‘is_not_one_of’).
bigint
[]
The array of bigints to check membership against.
boolean
True if the membership check is valid according to the operator, otherwise false.
If the operation is not recognized.
const value1 = BigInt(5);
const value2 = BigInt(3);
const arr = [BigInt(1), BigInt(2), BigInt(5)];
bigintMembership(value1, 'is_one_of', arr); // true
bigintMembership(value2, 'is_not_one_of', arr); // true
Supported Operators:
range: (
source
,oper
,min
,max
) =>boolean
=bigints.bigintRange
Checks if a bigint value falls within or outside a specified range using the given operation.
bigint
The source bigint value.
The range operation to perform (e.g. ‘between’, ‘not_between’).
bigint
The minimum value of the range (inclusive).
bigint
The maximum value of the range (inclusive).
boolean
True if the range check is valid according to the operator, otherwise false.
If the operation is not recognized.
const value1 = BigInt(5);
const value2 = BigInt(15);
const min = BigInt(1);
const max = BigInt(10);
bigintRange(value1, 'between', min, max); // true
bigintRange(value2, 'not_between', min, max); // true
Supported Operators:
state: (
source
,oper
) =>boolean
=bigints.bigintState
Checks the state of a bigint value (zero, positive, negative, even, odd) using the specified operation.
bigint
The source bigint value.
The state operation to perform (e.g. ‘is_zero’, ‘is_even’).
boolean
True if the state check is valid according to the operator, otherwise false.
If the operation is not recognized.
const zero = BigInt(0);
const even = BigInt(10);
const negative = BigInt(-5);
bigintState(zero, 'is_zero'); // true
bigintState(even, 'is_even'); // true
bigintState(negative, 'is_negative'); // true
Supported Operators:
boolean:
object
comparison: (
value
,oper
,target
) =>boolean
=booleans.booleanComparison
Compares a boolean value to a target boolean using the specified comparison operation.
boolean
The boolean value to compare.
The comparison operation to perform (e.g. ‘equals’, ‘not_equals’).
boolean
The boolean value to compare against.
boolean
True if the comparison is valid according to the operator, otherwise false.
If the operation is not recognized.
const valueTrue = true;
const valueFalse = false;
booleanComparison(valueTrue, 'equals', true); // true
booleanComparison(valueFalse, 'equals', true); // false
booleanComparison(valueTrue, 'not_equals', false); // true
booleanComparison(valueFalse, 'not_equals', false); // false
Supported Operators:
state: (
source
,oper
) =>boolean
=booleans.booleanState
Checks the state of a boolean value (true or false) using the specified operation.
boolean
The boolean value to check.
The operation to perform (e.g. ‘is_true’, ‘is_false’).
boolean
True if the state check is valid according to the operator, otherwise false.
If the operation is not recognized.
const valueTrue = true;
const valueFalse = false;
booleanState(valueTrue, 'is_true'); // true
booleanState(valueFalse, 'is_false'); // true
Supported Operators:
date:
object
calendar: (
source
,oper
,today
) =>boolean
=dates.dateCalendar
Checks calendar-based properties of a date (UTC) using the specified operation.
Date
The date to check.
The calendar operation to perform (e.g. ‘is_today’, ‘is_weekend’, ‘is_past’).
Date
= ...
(optional) The reference date to use as “today” (defaults to new Date()). Useful for testing.
boolean
True if the calendar check is valid according to the operator, otherwise false.
If the operation is not recognized.
const today = new Date();
const janFirst = new Date('2025-01-01');
dateCalendar(today, 'is_today'); // true (if run today)
dateCalendar(janFirst, 'is_first_day_of_month'); // true
Supported Operators:
comparison: (
source
,oper
,target
) =>boolean
=dates.dateComparison
Compares two dates in UTC using the specified comparison operation.
Date
The first date to compare.
The comparison operation to perform (e.g. ‘after’, ‘before’, ‘equals’).
Date
The second date to compare against.
boolean
True if the comparison is valid according to the operator, otherwise false.
If the operation is not recognized.
const d1 = new Date('2025-01-01');
const d2 = new Date('2025-01-02');
dateComparison(d1, 'before', d2); // true
dateComparison(d1, 'equals', d1); // true
Supported Operators:
range: (
source
,oper
,min
,max
) =>boolean
=dates.dateRange
Checks if a date is in or outside a UTC date range using the specified operation.
Date
The date to check.
The range operation to perform (e.g. ‘in_range’, ‘strict_in_range’).
Date
The minimum date (inclusive or exclusive depending on operation).
Date
The maximum date (inclusive or exclusive depending on operation).
boolean
True if the range check is valid according to the operator, otherwise false.
If the operation is not recognized.
const date = new Date('2025-01-10');
const start = new Date('2025-01-01');
const end = new Date('2025-01-31');
dateRange(date, 'in_range', start, end); // true
Supported Operators:
state: (
source
,oper
) =>boolean
=dates.dateState
Checks the state of a date (valid or invalid) in UTC using the specified operation.
Date
The date to check.
The state operation to perform (e.g. ‘is_valid’, ‘is_invalid’).
boolean
True if the state check is valid according to the operator, otherwise false.
If the operation is not recognized.
const validDate = new Date('2025-01-01');
const invalidDate = new Date('invalid');
dateState(validDate, 'is_valid'); // true
dateState(invalidDate, 'is_invalid'); // true
Supported Operators:
function:
object
arity: (
source
,oper
,arity
) =>boolean
=functions.functionArity
Checks the arity (number of parameters) of a function using the specified operation.
Function
The function to check.
The arity operation to perform (e.g. ‘arity_equals’, ‘arity_greater_than’).
number
The arity (number of parameters) to compare against.
boolean
True if the arity check is valid according to the operator, otherwise false.
If the operation is not recognized.
const fn1 = function(a, b) {};
const fn2 = function(a, b, c) {};
const arity2 = 2;
functionArity(fn1, 'arity_equals', arity2); // true
functionArity(fn2, 'arity_greater_than', arity2); // true
Supported Operators:
name: (
source
,oper
,target
) =>boolean
=functions.functionName
Checks the name of a function using the specified operation.
Function
The function to check.
The name operation to perform (e.g. ‘equals’, ‘starts_with’).
string
The string to compare the function name against.
boolean
True if the name check is valid according to the operator, otherwise false.
If the operation is not recognized.
const fn1 = function foo() {};
const fn2 = function barTest() {};
const name1 = 'foo';
const name2 = 'bar';
functionName(fn1, 'equals', name1); // true
functionName(fn2, 'starts_with', name2); // true
Supported Operators:
namePattern: (
source
,oper
,pattern
) =>boolean
=functions.functionNamePattern
Checks if the function name matches a given regular expression pattern using the specified operation.
Function
The function to check.
The pattern operation to perform (e.g. ‘matches’).
RegExp
The regular expression to test against the function name.
boolean
True if the pattern check is valid according to the operator, otherwise false.
If the operation is not recognized.
const fn = function fooBar() {};
const pattern = /^foo/;
functionPattern(fn, 'matches', pattern); // true
Supported Operators:
state: (
source
,oper
) =>boolean
=functions.functionState
Checks the state of a function (e.g. async, generator, constructor, arrow, anonymous, has name) using the specified operation.
Function
The function to check.
The state operation to perform (e.g. ‘is_async’, ‘is_arrow’).
boolean
True if the state check is valid according to the operator, otherwise false.
If the operation is not recognized.
const asyncFn = async function foo() {};
const genFn = function* gen() {};
functionState(asyncFn, 'is_async'); // true
functionState(genFn, 'is_generator'); // true
functionState(() => {}, 'is_arrow'); // true
functionState(function() {}, 'is_anonymous'); // true
functionState(function named() {}, 'has_name'); // true
Supported Operators:
map:
object
entry: <
K
,V
>(source
,oper
,entry
) =>boolean
=maps.mapEntry
Checks if a Map contains (or lacks) a specific entry (key-value pair) using the specified operation.
K
V
Map
<K
, V
>
The Map to check.
The entry operation to perform (e.g. ‘has_entry’, ‘lacks_entry’).
[K
, V
]
The [key, value] pair to check for.
boolean
True if the entry check is valid according to the operator, otherwise false.
If the operation is not recognized.
const m = new Map([[1, 'a']]);
const entry1 = [1, 'a'];
const entry2 = [2, 'b'];
mapEntry(m, 'has_entry', entry1); // true
mapEntry(m, 'lacks_entry', entry2); // true
Supported Operators:
key: <
K
,V
>(source
,oper
,key
) =>boolean
=maps.mapKey
Checks if a Map contains (or lacks) a specific key using the specified operation.
K
V
Map
<K
, V
>
The Map to check.
The key operation to perform (e.g. ‘has_key’, ‘lacks_key’).
K
The key to check for.
boolean
True if the key check is valid according to the operator, otherwise false.
If the operation is not recognized.
const m = new Map([[1, 'a']]);
const key1 = 1;
const key2 = 2;
mapKey(m, 'has_key', key1); // true
mapKey(m, 'lacks_key', key2); // true
Supported Operators:
size: <
K
,V
>(source
,oper
,target
) =>boolean
=maps.mapSize
Checks the size of a Map using the specified operation.
K
V
Map
<K
, V
>
The Map to check.
The size operation to perform (e.g. ‘size_equals’, ‘size_greater_than’).
number
The size to compare against.
boolean
True if the size check is valid according to the operator, otherwise false.
If the operation is not recognized.
const m1 = new Map([[1, 'a'], [2, 'b']]);
const m2 = new Map([[1, 'a']]);
const size2 = 2;
const size0 = 0;
mapSize(m1, 'size_equals', size2); // true
mapSize(m2, 'size_greater_than', size0); // true
Supported Operators:
state: <
K
,V
>(source
,oper
) =>boolean
=maps.mapState
Checks the state of a Map (empty or not) using the specified operation.
K
V
Map
<K
, V
>
The Map to check.
The state operation to perform (e.g. ‘is_empty’, ‘is_not_empty’).
boolean
True if the state check is valid according to the operator, otherwise false.
If the operation is not recognized.
const m1 = new Map();
const m2 = new Map([[1, 'a']]);
mapState(m1, 'is_empty'); // true
mapState(m2, 'is_not_empty'); // true
Supported Operators:
value: <
K
,V
>(source
,oper
,target
) =>boolean
=maps.mapValue
Checks if a Map contains (or lacks) a specific value using the specified operation.
K
V
Map
<K
, V
>
The Map to check.
The value operation to perform (e.g. ‘has_value’, ‘lacks_value’).
V
The value to check for.
boolean
True if the value check is valid according to the operator, otherwise false.
If the operation is not recognized.
const m1 = new Map([[1, 'a'], [2, 'b']]);
const m2 = new Map([[1, 'a']]);
const valueA = 'a';
const valueB = 'b';
mapValue(m1, 'has_value', valueA); // true
mapValue(m2, 'lacks_value', valueB); // true
Supported Operators:
number:
object
comparison: (
source
,oper
,target
) =>boolean
=numbers.numberComparison
Compares two numbers using the specified operation.
number
The first number.
The comparison operation to perform (e.g. ‘greater_than’, ‘equals’).
number
The second number.
boolean
True if the comparison is valid according to the operator, otherwise false.
If the operation is not recognized.
const a = 5;
const b = 10;
numberComparison(a, 'less_than', b); // true
numberComparison(a, 'greater_than', b); // false
numberComparison(a, 'equals', 5); // true
Supported Operators:
range: (
source
,oper
,min
,max
) =>boolean
=numbers.numberRange
Checks if a number is in or outside a range using the specified operation.
number
The number to check.
The range operation to perform (e.g. ‘in_range’, ‘strict_in_range’).
number
The minimum value (inclusive or exclusive depending on operation).
number
The maximum value (inclusive or exclusive depending on operation).
boolean
True if the range check is valid according to the operator, otherwise false.
If the operation is not recognized.
const n = 5;
numberRange(n, 'in_range', 1, 10); // true
numberRange(n, 'strict_in_range', 5, 10); // false
Supported Operators:
state: (
source
,oper
) =>boolean
=numbers.numberState
Checks the state of a number (integer, float, finite, positive, negative, zero) using the specified operation.
number
The number to check.
The state operation to perform (e.g. ‘is_integer’, ‘is_float’).
boolean
True if the state check is valid according to the operator, otherwise false.
If the operation is not recognized.
const n = 5;
numberState(n, 'is_integer'); // true
numberState(3.14, 'is_float'); // true
numberState(0, 'is_zero'); // true
Supported Operators:
object:
object
attributes: (
source
,oper
,key
) =>boolean
=objects.objectAttributes
Checks object property attributes (writable, enumerable, configurable, accessor, data property) using the specified operation.
object
The object to check.
The attribute operation to perform (e.g. ‘is_writable’, ‘is_accessor’).
The property key to check.
string |
symbol |
boolean
True if the attribute check is valid according to the operator, otherwise false.
If the operation is not recognized.
const obj = { foo: 42 };
const obj2 = {};
const sym = Symbol('bar');
Object.defineProperty(obj2, sym, { value: 1, writable: false });
objectAttributes(obj, 'is_writable', 'foo'); // true
objectAttributes(obj2, 'is_writable', sym); // false
Supported Operators:
instanceType: (
source
,oper
) =>boolean
=objects.objectInstanceType
Checks the type of an instance using the specified operation.
any
The value to check.
The type operation to perform.
boolean
True if the type check is valid according to the operator, otherwise false.
If the operation is not recognized.
Supported Operators:
instanceRelation: (
source
,oper
,target
) =>boolean
=objects.objectInstanceRelation
Checks instance or prototype relation between two values using the specified operation.
any
The value to check.
The relation operation to perform (e.g. ‘instance_of’, ‘prototype_of’).
any
The target to compare against.
boolean
True if the relation check is valid according to the operator, otherwise false.
If the operation is not recognized.
Supported Operators:
key: (
source
,oper
,key
) =>boolean
=objects.objectKey
Checks if an object has or lacks a specific key (string or symbol) using the specified operation.
object
The object to check.
The key operation to perform (e.g. ‘has_key’, ‘lacks_key’).
The key to check.
string |
symbol |
boolean
True if the key check is valid according to the operator, otherwise false.
If the operation is not recognized.
const obj = { foo: 1 };
const obj2 = {};
const sym = Symbol('baz');
Object.defineProperty(obj2, sym, { value: 2 });
objectKey(obj, 'has_key', 'foo'); // true
objectKey(obj, 'lacks_key', 'bar'); // true
objectKey(obj2, 'has_key', sym); // true
Supported Operators:
keyMembership: (
source
,oper
,keys
) =>boolean
=objects.objectKeyMembership
Checks if a key is (or is not) in a list of possible keys using the specified operation.
object
The object to check.
The membership operation to perform (e.g. ‘key_in’, ‘key_not_in’).
(string
| symbol
)[]
The array of possible keys.
boolean
True if the membership check is valid according to the operator, otherwise false.
If the operation is not recognized or keys is missing.
Supported Operators:
keys: (
source
,oper
,keys
) =>boolean
=objects.objectKeysCompare
Checks object keys for key-comparison operations (CONTAINS_, LACKS_, EQUALS_, etc.).
object
The object to check.
The key operation to perform (e.g. ‘contains_all_keys’, ‘lacks_all_keys’, ‘equals_keys’, …).
The array of keys to check (string[] | symbol[]). |
string [] |
symbol [] |
boolean
True if the key check is valid according to the operator, otherwise false.
If the operation is not recognized or keys is missing.
Supported Operators:
keysState: (
obj
,oper
) =>boolean
=objects.objectKeysState
Checks state-related properties of an object’s keys (e.g. has_symbol_keys, has_numeric_keys).
object
The object to check.
The state operation to perform (ObjectKeysStateOper).
boolean
True if the state check is valid according to the operator, otherwise false.
If the operation is not recognized.
Supported Operators:
property: (
source
,oper
,key
) =>boolean
=objects.objectProperty
Checks if an object has or lacks a property (own or inherited) using the specified operation.
object
The object to check.
The property operation to perform (e.g. ‘contains_property’, ‘lacks_own_property’).
The property key to check.
string |
symbol |
boolean
True if the property check is valid according to the operator, otherwise false.
If the operation is not recognized.
Supported Operators:
prototypeRelation: (
source
,oper
,proto
) =>boolean
=objects.objectPrototypeRelation
Checks prototype relation between objects (contains_prototype, is_prototype_of).
object
The object to check.
The prototype operation to perform (e.g. ‘is_prototype_of’, ‘prototype_is_null’).
any
The prototype to compare against.
boolean
True if the relation check is valid according to the operator, otherwise false.
If the operation is not recognized.
Supported Operators:
prototypeState: (
source
,oper
) =>boolean
=objects.objectPrototypeState
Checks state-related properties of an object’s prototype (e.g. prototype_is_null).
object
The object to check.
The prototype state operation to perform.
boolean
True if the state check is valid according to the operator, otherwise false.
If the operation is not recognized.
Supported Operators:
state: (
source
,oper
) =>boolean
=objects.objectState
Checks state-related properties of an object (is_empty, is_not_empty, is_plain, is_frozen, is_sealed).
object
The object to check.
The state operation to perform.
boolean
True if the state check is valid according to the operator, otherwise false.
If the operation is not recognized.
objectState({}, 'is_empty'); // true
objectState({ a: 1 }, 'is_not_empty'); // true
objectState(Object.freeze({}), 'is_frozen'); // true
promise:
object
state: <
T
>(wrapper
,oper
) =>boolean
=promises.promiseState
Checks the state of a wrapped Promise using the specified operation.
Note: This predicate requires a wrapper or custom Promise implementation that exposes state. Standard JS Promises do not expose their state synchronously.
T
The wrapped Promise with state.
The state operation to perform (e.g. ‘is_pending’, ‘is_fulfilled’).
boolean
True if the state check is valid according to the operator, otherwise false.
If the operation is not recognized.
const p = Promise.resolve(42);
const wrapped = wrapPromise(p);
promiseState(wrapped, 'is_pending'); // true (immediately after wrapping)
Supported Operators:
type: (
source
,oper
) =>boolean
=promises.promiseType
Checks if a value is a Promise or an async function using the specified operation.
unknown
The value to check.
The type operation to perform (e.g. ‘is_promise’, ‘is_async_function’).
boolean
True if the type check is valid according to the operator, otherwise false.
If the operation is not recognized.
const p = Promise.resolve(42);
async function foo() {}
promiseType(p, 'is_promise'); // true
promiseType(foo, 'is_async_function'); // true
Supported Operators:
set:
object
arrayMembership: <
T
>(source
,oper
,target
) =>boolean
=sets.setArrayMembership
Checks membership conditions for multiple elements in a set using the specified operation.
T
Set
<T
>
The set to check.
The membership operation to perform (e.g. ‘contains_all’, ‘contains_any’).
T
[]
The array of values to check for membership.
boolean
True if the membership check is valid according to the operator, otherwise false.
If the operation is not recognized.
const s = new Set([1, 2, 3]);
const values = [2, 4];
setArrayMembership(s, 'contains_any', values); // true (contains 2)
setArrayMembership(s, 'contains_all', values); // false (missing 4)
setArrayMembership(s, 'excludes_all', [5, 6]); // true (excludes both)
Supported Operators:
comparison: <
T
>(source
,oper
,target
) =>boolean
=sets.setComparison
Compares two sets for equality or inequality using the specified operation.
T
Set
<T
>
The first set to compare.
The comparison operation to perform (e.g. ‘equals’, ‘not_equals’).
Set
<T
>
The second set to compare.
boolean
True if the comparison is valid according to the operator, otherwise false.
If the operation is not recognized.
const a = new Set([1, 2, 3]);
const b = new Set([1, 2, 3]);
const c = new Set([4, 5]);
setComparison(a, 'equals', b); // true
setComparison(a, 'not_equals', c); // true
Supported Operators:
intersection: <
T
>(source
,oper
,target
) =>boolean
=sets.setIntersection
Checks intersection properties between two sets using the specified operation.
T
Set
<T
>
The first set.
The intersection operation to perform (e.g. ‘disjoint’, ‘intersects’).
Set
<T
>
The second set.
boolean
True if the intersection check is valid according to the operator, otherwise false.
If the operation is not recognized.
const a = new Set([1, 2]);
const b = new Set([2, 3]);
const c = new Set([4, 5]);
setIntersection(a, 'intersects', b); // true
setIntersection(a, 'disjoint', c); // true
Supported Operators:
membership: <
T
>(source
,oper
,target
) =>boolean
=sets.setMembership
Checks membership conditions for elements in a set using the specified operation.
T
Set
<T
>
The set to check.
The membership operation to perform (e.g. ‘contains’, ‘excludes’).
T
The value to check for membership.
boolean
True if the membership check is valid according to the operator, otherwise false.
If the operation is not recognized.
const s = new Set([1, 2, 3]);
setMembership(s, 'contains', 2); // true
setMembership(s, 'excludes', 4); // true
Supported Operators:
relation: <
T
>(source
,oper
,target
) =>boolean
=sets.setRelation
Checks the relation between two sets (disjoint, intersects, subset, superset) using the specified operation.
T
Set
<T
>
The first set.
The relation operation to perform (e.g. ‘disjoint’, ‘subset_of’).
Set
<T
>
The second set.
boolean
True if the relation check is valid according to the operator, otherwise false.
If the operation is not recognized.
const a = new Set([1, 2]);
const b = new Set([2, 3]);
const c = new Set([4, 5]);
setRelation(a, 'intersects', b); // true
setRelation(a, 'disjoint', c); // true
setRelation(a, 'subset_of', b); // true
setRelation(a, 'superset_of', b); // false
Supported Operators:
size: <
T
>(source
,oper
,target
) =>boolean
=sets.setSize
Checks the size of a set using the specified operation.
T
Set
<T
>
The set to check.
The size operation to perform (e.g. ‘size_equals’, ‘size_greater_than’).
number
The size to compare against.
boolean
True if the size check is valid according to the operator, otherwise false.
If the operation is not recognized.
const a = new Set([1, 2, 3]);
setSize(a, 'size_equals', 3); // true
setSize(a, 'size_greater_than', 2); // true
Supported Operators:
state: <
T
>(source
,oper
) =>boolean
=sets.setState
Checks the state of a set using the specified operation.
T
Set
<T
>
The set to check.
The state operation to perform (e.g. ‘is_empty’, ‘has_primitives’).
boolean
True if the state check is valid according to the operator, otherwise false.
If the operation is not recognized.
const a = new Set();
const b = new Set([1]);
const c = new Set([1, 'hello', { id: 1 }]);
setState(a, 'is_empty'); // true
setState(b, 'is_not_empty'); // true
setState(c, 'has_primitives'); // true
setState(c, 'has_objects'); // true
Supported Operators:
string:
object
comparison: (
source
,oper
,target
) =>boolean
=strings.stringComparison
Compares two strings using the specified operation.
string
The first string.
The comparison operation to perform (e.g. ‘equals’, ‘greater_than’).
string
The second string.
boolean
True if the comparison is valid according to the operator, otherwise false.
If the operation is not recognized.
const a = 'foo';
const b = 'bar';
stringComparison(a, 'greater_than', b); // true
stringComparison(a, 'equals', a); // true
Supported Operators:
membership: (
source
,oper
,target
) =>boolean
=strings.stringMembership
Checks if a string is (or is not) a member of a set of strings using the specified operation.
string
The string to check.
The membership operation to perform (e.g. ‘in’, ‘not_in’).
string
[]
The array of strings to check membership against.
boolean
True if the membership check is valid according to the operator, otherwise false.
If the operation is not recognized.
const arr = ['foo', 'bar'];
const value1 = 'foo';
const value2 = 'baz';
stringMembership(value1, 'in', arr); // true
stringMembership(value2, 'not_in', arr); // true
Supported Operators:
pattern: (
source
,oper
,pattern
) =>boolean
=strings.stringPattern
Evaluates a string against a pattern operation (matches or not matches a RegExp) using the specified operation.
string
The string to test.
The pattern operation to perform (e.g. ‘matches’, ‘not_matches’).
RegExp
The RegExp to test against.
boolean
True if the operation matches, false otherwise.
If the operation is not recognized.
const str = 'foobar';
const pattern1 = /^foo/;
const pattern2 = /baz/;
stringPattern(str, 'matches', pattern1); // true
stringPattern(str, 'not_matches', pattern2); // true
Supported Operators:
size: (
source
,oper
,target
) =>boolean
=strings.stringSize
Checks the size (length) of a string using the specified operation.
string
The string to check.
The size operation to perform (e.g. ‘length_equals’, ‘length_greater_than’).
number
The length to compare against.
boolean
True if the size check is valid according to the operator, otherwise false.
If the operation is not recognized.
const str = 'hello';
const len1 = 5;
const len2 = 3;
stringSize(str, 'length_equals', len1); // true
stringSize(str, 'length_greater_than', len2); // true
Supported Operators:
state: (
source
,oper
) =>boolean
=strings.stringState
Checks the state of a string (empty, not empty, blank, not blank) using the specified operation.
string
The string to check.
The state operation to perform (e.g. ‘is_empty’, ‘is_not_blank’).
boolean
True if the state check is valid according to the operator, otherwise false.
If the operation is not recognized.
const str = '';
const str2 = ' ';
stringState(str, 'is_empty'); // true
stringState(str2, 'is_blank'); // true
Supported Operators:
substring: (
source
,oper
,target
) =>boolean
=strings.stringSubstring
Checks if a string contains, excludes, starts with, or ends with a substring using the specified operation.
string
The string to check.
The substring operation to perform (e.g. ‘includes’, ‘starts_with’).
string
The substring to check for.
boolean
True if the substring check is valid according to the operator, otherwise false.
If the operation is not recognized.
const str = 'foobar';
stringSubstring(str, 'includes', sub); // true
stringSubstring(str, 'starts_with', sub); // true
Supported Operators:
symbol:
object
comparison: (
source
,oper
,target
) =>boolean
=symbols.symbolComparison
Compares two symbols for equality or inequality using the specified operation.
symbol
The first symbol to compare.
The comparison operation to perform (e.g. ‘equals’, ‘not_equals’).
symbol
The second symbol to compare.
boolean
True if the comparison is valid according to the operator, otherwise false.
If the operation is not recognized.
const a = Symbol('foo');
const b = Symbol('foo');
symbolComparison(a, 'equals', a); // true
symbolComparison(a, 'not_equals', b); // true
Supported Operators:
state: (
source
,oper
) =>boolean
=symbols.symbolState
Checks the state of a symbol (global or local) using the specified operation.
symbol
The symbol to check.
The state operation to perform (e.g. ‘is_global’, ‘is_local’).
boolean
True if the state check is valid according to the operator, otherwise false.
If the operation is not recognized.
const globalSym = Symbol.for('foo');
const localSym = Symbol('bar');
symbolState(globalSym, 'is_global'); // true
symbolState(localSym, 'is_local'); // true
Supported Operators: