predictype

predictype v0.13.0


predictype / PredicType / PredicType

Variable: PredicType

const PredicType: object

Defined in: PredicType.ts:18

Type Declaration

array

array: object

array.comparison

comparison: <T>(source, oper, target) => boolean = arrays.arrayComparison

Compares two arrays using a variety of comparison operations.

Type Parameters
T

T

Type of the array elements.

Parameters
source

T[]

The source array to compare.

oper

ArrayComparisonOper

The comparison operation to perform (EQUALS, NOT_EQUALS, SAME_MEMBERS, SET_EQUALS, SET_NOT_EQUALS).

target

T[]

The target array to compare against the source.

Returns

boolean

True if the comparison is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
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
Remarks

Supported operators:

array.indexComparison

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.

Type Parameters
T

T

Type of the array elements.

Parameters
source

T[]

The source array.

oper

ArrayIndexComparisonOper

The comparison operation to perform (e.g. ‘at_index_equals’).

index

number

The index in the array to compare.

target

T

The value to compare against the value at the given index.

Returns

boolean

True if the comparison is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
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
Remarks

Supported Operators:

array.indexMembership

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.

Type Parameters
T

T

Type of the array elements.

Parameters
source

T[]

The source array.

oper

ArrayIndexMembershipOper

The membership operation to perform (e.g. ‘at_index_in’).

index

number

The index in the array to check.

target

T[]

The array of values to check for inclusion/exclusion.

Returns

boolean

True if the membership check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
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
Remarks

Supported Operators:

array.intersection

intersection: <T>(source, oper, target) => boolean = arrays.arrayIntersection

Checks if two arrays are disjoint or intersect, using the specified operation.

Type Parameters
T

T

Type of the array elements.

Parameters
source

T[]

The source array.

oper

ArrayIntersectionOper

The intersection operation to perform (e.g. ‘disjoint’, ‘intersects’).

target

T[]

The target array to check against the source.

Returns

boolean

True if the intersection check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
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
Remarks

Supported Operators:

array.membership

membership: <T>(source, oper, target) => boolean = arrays.arrayMembership

Checks membership conditions for all or some elements in an array, using the specified operation.

Type Parameters
T

T

Type of the array elements.

Parameters
source

T[]

The source array.

oper

ArrayMembershipOper

The membership operation to perform (e.g. ‘every_equals’, ‘includes’).

target

T

The value to check for membership.

Returns

boolean

True if the membership check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
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
Remarks

Supported Operators:

array.relation

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.

Type Parameters
T

T

Type of the array elements.

Parameters
source

T[]

The source array.

oper

ArrayRelationOper

The relation operation to perform (‘subset_of’, ‘superset_of’, ‘strict_subset_of’, ‘strict_superset_of’).

target

T[]

The target array to check against the source.

Returns

boolean

True if the relation check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Examples

Subset and Superset

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)

Strict Subset and Strict Superset

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)
Remarks

Supported Operators:

array.sequence

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.

Type Parameters
T

T

Type of the array elements.

Parameters
source

T[]

The source array.

oper

ArraySequenceOper

The sequence operation to perform (e.g. ‘contains_subsequence’, ‘starts_with’, ‘ends_with’).

target

T[]

The target subsequence array to check against the source.

Returns

boolean

True if the sequence check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
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
Remarks

Supported Operators:

array.size

size: (source, oper, target) => boolean = arrays.arraySize

Checks the size of an array against a target value, using the specified operation.

Parameters
source

any[]

The source array.

oper

ArraySizeOper

The size operation to perform (e.g. ‘size_equals’, ‘size_greater_than’).

target

number

The target size to compare against the array’s length.

Returns

boolean

True if the size check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
const arr = [1, 2, 3];
const len1 = 3;
const len2 = 2;

arraySize(arr, 'size_equals', len1); // true
arraySize(arr, 'size_greater_than', len2); // true
Remarks

Supported Operators:

array.state

state: (source, oper) => boolean = arrays.arrayState

Checks if an array is empty or not, using the specified operation.

Parameters
source

any[]

The source array.

oper

ArrayStateOper

The state operation to perform (e.g. ‘is_empty’, ‘is_not_empty’).

Returns

boolean

True if the state check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
const arr1 = [];
const arr2 = [1, 2, 3];

arrayState(arr1, 'is_empty'); // true
arrayState(arr2, 'is_not_empty'); // true
Remarks

Supported Operators:

bigint

bigint: object

bigint.comparison

comparison: (source, oper, target) => boolean = bigints.bigintComparison

Compares two bigint values using the specified operation.

Parameters
source

bigint

The source bigint value.

oper

BigIntComparisonOper

The comparison operation to perform (e.g. ‘equals’, ‘greater_than’).

target

bigint

The target bigint value to compare against the source.

Returns

boolean

True if the comparison is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
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
Remarks

Supported Operators:

bigint.membership

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.

Parameters
source

bigint

The source bigint value.

oper

BigIntMembershipOper

The membership operation to perform (e.g. ‘in’, ‘not_in’).

target

bigint[]

The array of bigints to check membership against.

Returns

boolean

True if the membership check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
const value1 = BigInt(5);
const value2 = BigInt(3);
const arr = [BigInt(1), BigInt(2), BigInt(5)];

bigintMembership(value1, 'in', arr); // true
bigintMembership(value2, 'not_in', arr); // true
Remarks

Supported Operators:

bigint.range

range: (source, oper, min, max) => boolean = bigints.bigintRange

Checks if a bigint value falls within or outside a specified range using the given operation.

Parameters
source

bigint

The source bigint value.

oper

BigIntRangeOper

The range operation to perform (e.g. ‘between’, ‘not_between’).

min

bigint

The minimum value of the range (inclusive).

max

bigint

The maximum value of the range (inclusive).

Returns

boolean

True if the range check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
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
Remarks

Supported Operators:

bigint.state

state: (source, oper) => boolean = bigints.bigintState

Checks the state of a bigint value (zero, positive, negative, even, odd) using the specified operation.

Parameters
source

bigint

The source bigint value.

oper

BigIntStateOper

The state operation to perform (e.g. ‘is_zero’, ‘is_even’).

Returns

boolean

True if the state check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
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
Remarks

Supported Operators:

boolean

boolean: object

boolean.comparison

comparison: (value, oper, target) => boolean = booleans.booleanComparison

Compares a boolean value to a target boolean using the specified comparison operation.

Parameters
value

boolean

The boolean value to compare.

oper

BooleanComparisonOper

The comparison operation to perform (e.g. ‘equals’, ‘not_equals’).

target

boolean

The boolean value to compare against.

Returns

boolean

True if the comparison is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
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
Remarks

Supported Operators:

boolean.state

state: (source, oper) => boolean = booleans.booleanState

Checks the state of a boolean value (true or false) using the specified operation.

Parameters
source

boolean

The boolean value to check.

oper

BooleanStateOper

The operation to perform (e.g. ‘is_true’, ‘is_false’).

Returns

boolean

True if the state check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
const valueTrue = true;
const valueFalse = false;

booleanState(valueTrue, 'is_true'); // true
booleanState(valueFalse, 'is_false'); // true
Remarks

Supported Operators:

date

date: object

date.calendar

calendar: (source, oper, today) => boolean = dates.dateCalendar

Checks calendar-based properties of a date (UTC) using the specified operation.

Parameters
source

Date

The date to check.

oper

DateCalendarOper

The calendar operation to perform (e.g. ‘is_today’, ‘is_weekend’, ‘is_past’).

today?

Date = ...

(optional) The reference date to use as “today” (defaults to new Date()). Useful for testing.

Returns

boolean

True if the calendar check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
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
Remarks

Supported Operators:

date.comparison

comparison: (source, oper, target) => boolean = dates.dateComparison

Compares two dates in UTC using the specified comparison operation.

Parameters
source

Date

The first date to compare.

oper

DateComparisonOper

The comparison operation to perform (e.g. ‘after’, ‘before’, ‘equals’).

target

Date

The second date to compare against.

Returns

boolean

True if the comparison is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
const d1 = new Date('2025-01-01');
const d2 = new Date('2025-01-02');
dateComparison(d1, 'before', d2); // true
dateComparison(d1, 'equals', d1); // true
Remarks

Supported Operators:

date.range

range: (source, oper, min, max) => boolean = dates.dateRange

Checks if a date is in or outside a UTC date range using the specified operation.

Parameters
source

Date

The date to check.

oper

DateRangeOper

The range operation to perform (e.g. ‘between’, ‘strict_between’).

min

Date

The minimum date (inclusive or exclusive depending on operation).

max

Date

The maximum date (inclusive or exclusive depending on operation).

Returns

boolean

True if the range check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
const date = new Date('2025-01-10');
const start = new Date('2025-01-01');
const end = new Date('2025-01-31');

dateRange(date, 'between', start, end); // true
Remarks

Supported Operators:

date.state

state: (source, oper) => boolean = dates.dateState

Checks the state of a date (valid or invalid) in UTC using the specified operation.

Parameters
source

Date

The date to check.

oper

DateStateOper

The state operation to perform (e.g. ‘is_valid’, ‘is_invalid’).

Returns

boolean

True if the state check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
const validDate = new Date('2025-01-01');
const invalidDate = new Date('invalid');

dateState(validDate, 'is_valid'); // true
dateState(invalidDate, 'is_invalid'); // true
Remarks

Supported Operators:

error

error: object

error.message

message: (source, oper, target) => boolean = errors.errorMessage

Checks the message of an Error using the specified operation.

Parameters
source

Error

The Error to check.

oper

ErrorMessageOper

The message operation to perform (e.g. ‘equals’, ‘includes’).

target

string

The string to compare the error message against.

Returns

boolean

True if the message check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
const err = new Error('Network timeout');

errorMessage(err, 'includes', 'timeout'); // true
errorMessage(err, 'starts_with', 'Network'); // true
Remarks

Supported Operators:

error.messagePattern

messagePattern: (source, oper, pattern) => boolean = errors.errorMessagePattern

Evaluates an error message against a pattern operation (matches or not matches a RegExp) using the specified operation.

Parameters
source

Error

The Error whose message will be tested.

oper

ErrorMessagePatternOper

The pattern operation to perform (e.g. ‘matches’, ‘not_matches’).

pattern

RegExp

The RegExp to test against.

Returns

boolean

True if the operation matches, false otherwise.

Throws

If the operation is not recognized.

Example
const err = new Error('Network timeout');

errorMessagePattern(err, 'matches', /timeout$/); // true
errorMessagePattern(err, 'not_matches', /syntax/i); // true
Remarks

Supported Operators:

error.name

name: (source, oper, target) => boolean = errors.errorName

Checks the name of an Error using the specified operation.

Parameters
source

Error

The Error to check.

oper

ErrorNameOper

The name operation to perform (e.g. ‘equals’, ‘starts_with’).

target

string

The string to compare the error name against.

Returns

boolean

True if the name check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
const err = new TypeError('boom');

errorName(err, 'equals', 'TypeError'); // true
errorName(err, 'ends_with', 'Error'); // true
errorName(err, 'equals', 'TypeError'); // true
Remarks

Supported Operators:

error.namePattern

namePattern: (source, oper, pattern) => boolean = errors.errorNamePattern

Evaluates an error name against a pattern operation (matches or not matches a RegExp) using the specified operation.

Parameters
source

Error

The Error whose name will be tested.

oper

ErrorNamePatternOper

The pattern operation to perform (e.g. ‘matches’, ‘not_matches’).

pattern

RegExp

The RegExp to test against.

Returns

boolean

True if the operation matches, false otherwise.

Throws

If the operation is not recognized.

Example
const err = new TypeError('boom');

errorNamePattern(err, 'matches', /Type/); // true
errorNamePattern(err, 'not_matches', /Range/); // true
Remarks

Supported Operators:

error.state

state: (source, oper) => boolean = errors.errorState

Checks the state of an Error using the specified operation.

Parameters
source

Error

The Error to check.

oper

ErrorStateOper

The state operation to perform (e.g. ‘has_stack’, ‘has_cause’).

Returns

boolean

True if the state check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
const err = new Error('boom');

errorState(err, 'has_stack'); // true
errorState(new AggregateError([], 'many'), 'is_aggregate_error'); // true
Remarks

Supported Operators:

function

function: object

function.arity

arity: (source, oper, arity) => boolean = functions.functionArity

Checks the arity (number of parameters) of a function using the specified operation.

Parameters
source

Function

The function to check.

oper

FunctionArityOper

The arity operation to perform (e.g. ‘equals’, ‘greater_than’).

arity

number

The arity (number of parameters) to compare against.

Returns

boolean

True if the arity check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
const fn1 = function(a, b) {};
const fn2 = function(a, b, c) {};
const arity2 = 2;

functionArity(fn1, 'equals', arity2); // true
functionArity(fn2, 'greater_than', arity2); // true
Remarks

Supported Operators:

function.name

name: (source, oper, target) => boolean = functions.functionName

Checks the name of a function using the specified operation.

Parameters
source

Function

The function to check.

oper

FunctionNameOper

The name operation to perform (e.g. ‘equals’, ‘starts_with’).

target

string

The string to compare the function name against.

Returns

boolean

True if the name check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
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
Remarks

Supported Operators:

function.namePattern

namePattern: (source, oper, pattern) => boolean = functions.functionNamePattern

Checks if the function name matches a given regular expression pattern using the specified operation.

Parameters
source

Function

The function to check.

oper

FunctionNamePatternOper

The pattern operation to perform (e.g. ‘matches’).

pattern

RegExp

The regular expression to test against the function name.

Returns

boolean

True if the pattern check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
const fn = function fooBar() {};
const pattern = /^foo/;

functionPattern(fn, 'matches', pattern); // true
Remarks

Supported Operators:

function.state

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.

Parameters
source

Function

The function to check.

oper

FunctionStateOper

The state operation to perform (e.g. ‘is_async’, ‘is_arrow’).

Returns

boolean

True if the state check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
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
Remarks

Supported Operators:

map

map: object

map.entry

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.

Type Parameters
K

K

Type of the Map keys.

V

V

Type of the Map values.

Parameters
source

Map<K, V>

The Map to check.

oper

MapEntryOper

The entry operation to perform (e.g. ‘contains_entry’, ‘lacks_entry’).

entry

[K, V]

The [key, value] pair to check for.

Returns

boolean

True if the entry check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
const m = new Map([[1, 'a']]);
const entry1 = [1, 'a'];
const entry2 = [2, 'b'];

mapEntry(m, 'contains_entry', entry1); // true
mapEntry(m, 'lacks_entry', entry2); // true
Remarks

Supported Operators:

map.key

key: <K, V>(source, oper, key) => boolean = maps.mapKey

Checks if a Map contains (or lacks) a specific key using the specified operation.

Type Parameters
K

K

Type of the Map keys.

V

V

Type of the Map values.

Parameters
source

Map<K, V>

The Map to check.

oper

MapKeyOper

The key operation to perform (e.g. ‘contains_key’, ‘lacks_key’).

key

K

The key to check for.

Returns

boolean

True if the key check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
const m = new Map([[1, 'a']]);
const key1 = 1;
const key2 = 2;

mapKey(m, 'contains_key', key1); // true
mapKey(m, 'lacks_key', key2); // true
Remarks

Supported Operators:

map.size

size: <K, V>(source, oper, target) => boolean = maps.mapSize

Checks the size of a Map using the specified operation.

Type Parameters
K

K

Type of the Map keys.

V

V

Type of the Map values.

Parameters
source

Map<K, V>

The Map to check.

oper

MapSizeOper

The size operation to perform (e.g. ‘size_equals’, ‘size_greater_than’).

target

number

The size to compare against.

Returns

boolean

True if the size check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
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
Remarks

Supported Operators:

map.state

state: <K, V>(source, oper) => boolean = maps.mapState

Checks the state of a Map (empty or not) using the specified operation.

Type Parameters
K

K

Type of the Map keys.

V

V

Type of the Map values.

Parameters
source

Map<K, V>

The Map to check.

oper

MapStateOper

The state operation to perform (e.g. ‘is_empty’, ‘is_not_empty’).

Returns

boolean

True if the state check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
const m1 = new Map();
const m2 = new Map([[1, 'a']]);

mapState(m1, 'is_empty'); // true
mapState(m2, 'is_not_empty'); // true
Remarks

Supported Operators:

map.value

value: <K, V>(source, oper, target) => boolean = maps.mapValue

Checks if a Map contains (or lacks) a specific value using the specified operation.

Type Parameters
K

K

Type of the Map keys.

V

V

Type of the Map values.

Parameters
source

Map<K, V>

The Map to check.

oper

MapValueOper

The value operation to perform (e.g. ‘contains_value’, ‘lacks_value’).

target

V

The value to check for.

Returns

boolean

True if the value check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
const m1 = new Map([[1, 'a'], [2, 'b']]);
const m2 = new Map([[1, 'a']]);
const valueA = 'a';
const valueB = 'b';

mapValue(m1, 'contains_value', valueA); // true
mapValue(m2, 'lacks_value', valueB); // true
Remarks

Supported Operators:

number

number: object

number.comparison

comparison: (source, oper, target) => boolean = numbers.numberComparison

Compares two numbers using the specified operation.

Parameters
source

number

The first number.

oper

NumberComparisonOper

The comparison operation to perform (e.g. ‘greater_than’, ‘equals’).

target

number

The second number.

Returns

boolean

True if the comparison is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
const a = 5;
const b = 10;

numberComparison(a, 'less_than', b); // true
numberComparison(a, 'greater_than', b); // false
numberComparison(a, 'equals', 5); // true
Remarks

Supported Operators:

number.range

range: (source, oper, min, max) => boolean = numbers.numberRange

Checks if a number is in or outside a range using the specified operation.

Parameters
source

number

The number to check.

oper

NumberRangeOper

The range operation to perform (e.g. ‘between’, ‘strict_between’).

min

number

The minimum value (inclusive or exclusive depending on operation).

max

number

The maximum value (inclusive or exclusive depending on operation).

Returns

boolean

True if the range check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
const n = 5;

numberRange(n, 'between', 1, 10); // true
numberRange(n, 'strict_between', 5, 10); // false
Remarks

Supported Operators:

number.state

state: (source, oper) => boolean = numbers.numberState

Checks the state of a number (integer, float, finite, positive, negative, zero) using the specified operation.

Parameters
source

number

The number to check.

oper

NumberStateOper

The state operation to perform (e.g. ‘is_integer’, ‘is_float’).

Returns

boolean

True if the state check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
const n = 5;

numberState(n, 'is_integer'); // true
numberState(3.14, 'is_float'); // true
numberState(0, 'is_zero'); // true
Remarks

Supported Operators:

object

object: object

object.attributes

attributes: (source, oper, key) => boolean = objects.objectAttributes

Checks object property attributes (writable, enumerable, configurable, accessor, data property) using the specified operation.

Parameters
source

object

The object to check.

oper

ObjectAttributesOper

The attribute operation to perform (e.g. ‘is_writable’, ‘is_accessor’).

key

string | symbol

The property key to check.

Returns

boolean

True if the attribute check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
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
Remarks

Supported Operators:

object.instanceType

instanceType: (source, oper) => boolean = objects.objectInstanceType

Checks the type of an instance using the specified operation.

Parameters
source

any

The value to check.

oper

ObjectInstanceTypeOper

The type operation to perform.

Returns

boolean

True if the type check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
class User {}
const classCtor = User;
const plain = { id: 1 };

objectInstanceType(classCtor, 'instance_of_class'); // true
objectInstanceType(classCtor, 'instance_of_function'); // true
objectInstanceType(plain, 'instance_of_object'); // true
Remarks

Supported Operators:

object.instanceRelation

instanceRelation: (source, oper, target) => boolean = objects.objectInstanceRelation

Checks instance or prototype relation between two values using the specified operation.

Parameters
source

any

The value to check.

oper

ObjectInstanceRelationOper

The relation operation to perform (e.g. ‘instance_of’, ‘prototype_of’).

target

any

The target to compare against.

Returns

boolean

True if the relation check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
class User {}
const sourceA = new User();
const targetA = User;
const proto = { kind: 'base' };
const child = Object.create(proto);

objectInstanceRelation(sourceA, 'instance_of', targetA); // true
objectInstanceRelation(proto, 'prototype_of', child); // true
Remarks

Supported Operators:

object.key

key: (source, oper, key) => boolean = objects.objectKey

Checks if an object has or lacks a specific key (string or symbol) using the specified operation.

Parameters
source

object

The object to check.

oper

ObjectKeyOper

The key operation to perform (e.g. ‘contains_key’, ‘lacks_key’).

key

string | symbol

The key to check.

Returns

boolean

True if the key check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
const obj = { foo: 1 };
const obj2 = {};
const sym = Symbol('baz');
Object.defineProperty(obj2, sym, { value: 2 });

objectKey(obj, 'contains_key', 'foo'); // true
objectKey(obj, 'lacks_key', 'bar'); // true
objectKey(obj2, 'contains_key', sym); // true
Remarks

Supported Operators:

object.keyMembership

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.

Parameters
source

object

The object to check.

oper

ObjectKeyMembershipOper

The membership operation to perform (e.g. ‘in’, ‘not_in’).

keys

(string | symbol)[]

The array of possible keys.

Returns

boolean

True if the membership check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized or keys is missing.

Example
const idSymbol = Symbol('id');
const source = { name: 'Ada', [idSymbol]: 1 };
const keysA = ['name', 'missing'];
const keysB = ['missing'];

objectKeyMembership(source, 'in', keysA); // true
objectKeyMembership(source, 'not_in', keysB); // true
Remarks

Supported Operators:

object.keys

keys: (source, oper, keys) => boolean = objects.objectKeysCompare

Checks object keys for key-comparison operations (CONTAINS_, LACKS_, EQUALS_, etc.).

Parameters
source

object

The object to check.

oper

ObjectKeysOper

The key operation to perform (e.g. ‘contains_all_keys’, ‘lacks_all_keys’, ‘equals_keys’, …).

keys

string[] | symbol[]

The array of keys to check (string[] symbol[]).
Returns

boolean

True if the key check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized or keys is missing.

Example
const source = { a: 1, b: 2, c: 3 };
const keysA = ['a', 'b'];
const keysB = ['a', 'b', 'c'];

objectKeysCompare(source, 'contains_all_keys', keysA); // true
objectKeysCompare(source, 'equals_keys', keysB); // true
objectKeysCompare(source, 'lacks_all_keys', ['z']); // true
Remarks

Supported Operators:

object.keysState

keysState: (obj, oper) => boolean = objects.objectKeysState

Checks state-related properties of an object’s keys (e.g. has_symbol_keys, has_numeric_keys).

Parameters
obj

object

The object to check.

oper

ObjectKeysStateOper

The state operation to perform (ObjectKeysStateOper).

Returns

boolean

True if the state check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
const sourceA = { userName: 'Ada', 42: 'x' };
const sourceB = { a: 1, b: 2 };

objectKeysState(sourceA, 'has_camelcase_keys'); // true
objectKeysState(sourceA, 'has_numeric_keys'); // true
objectKeysState(sourceB, 'has_homogeneous_keys'); // true
Remarks

Supported Operators:

object.property

property: (source, oper, key) => boolean = objects.objectProperty

Checks if an object has or lacks a property (own or inherited) using the specified operation.

Parameters
source

object

The object to check.

oper

ObjectPropertyOper

The property operation to perform (e.g. ‘contains_property’, ‘lacks_own_property’).

key

string | symbol

The property key to check.

Returns

boolean

True if the property check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
const source = Object.create({ inherited: true });
source.own = 42;

objectProperty(source, 'contains_property', 'inherited'); // true
objectProperty(source, 'contains_own_property', 'own'); // true
objectProperty(source, 'lacks_own_property', 'inherited'); // true
Remarks

Supported Operators:

object.prototypeRelation

prototypeRelation: (source, oper, proto) => boolean = objects.objectPrototypeRelation

Checks prototype relation between objects (contains_prototype, is_prototype_of).

Parameters
source

object

The object to check.

oper

ObjectPrototypeRelationOper

The prototype relation operation to perform (e.g. ‘contains_prototype’, ‘is_prototype_of’).

proto

any

The prototype to compare against.

Returns

boolean

True if the relation check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
const proto = { kind: 'base' };
const source = Object.create(proto);
const target = Object.create(source);

objectPrototypeRelation(source, 'contains_prototype', proto); // true
objectPrototypeRelation(source, 'is_prototype_of', target); // true
Remarks

Supported Operators:

object.prototypeState

prototypeState: (source, oper) => boolean = objects.objectPrototypeState

Checks state-related properties of an object’s prototype (e.g. prototype_is_null).

Parameters
source

object

The object to check.

oper

ObjectPrototypeStateOper

The prototype state operation to perform.

Returns

boolean

True if the state check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
const sourceA = Object.create(null);
const sourceB = { id: 1 };

objectPrototypeState(sourceA, 'prototype_is_null'); // true
objectPrototypeState(sourceB, 'prototype_is_null'); // false
Remarks

Supported Operators:

object.state

state: (source, oper) => boolean = objects.objectState

Checks state-related properties of an object (is_empty, is_not_empty, is_plain, is_frozen, is_sealed).

Parameters
source

object

The object to check.

oper

ObjectStateOper

The state operation to perform.

Returns

boolean

True if the state check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
const empty = {};
const frozen = Object.freeze({ a: 1 });

objectState(empty, 'is_empty'); // true
objectState(frozen, 'is_frozen'); // true
Remarks

Supported Operators:

promise

promise: object

promise.state

state: <T>(wrapper, oper) => boolean = promises.promiseState

Checks the state of a wrapped Promise using the specified operation.

Type Parameters
T

T

Type resolved by the Promise. Note: This predicate requires a wrapper or custom Promise implementation that exposes state. Standard JS Promises do not expose their state synchronously.

Parameters
wrapper

PromiseWithState<T>

The wrapped Promise with state.

oper

PromiseStateOper

The state operation to perform (e.g. ‘is_pending’, ‘is_fulfilled’).

Returns

boolean

True if the state check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
const p = Promise.resolve(42);
const wrapped = wrapPromise(p);

promiseState(wrapped, 'is_pending'); // true (immediately after wrapping)
Remarks

Supported Operators:

promise.type

type: (source, oper) => boolean = promises.promiseType

Checks if a value is a Promise or an async function using the specified operation.

Parameters
source

unknown

The value to check.

oper

PromiseTypeOper

The type operation to perform (e.g. ‘is_promise’, ‘is_async_function’).

Returns

boolean

True if the type check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
const p = Promise.resolve(42);
async function foo() {}

promiseType(p, 'is_promise'); // true
promiseType(foo, 'is_async_function'); // true
Remarks

Supported Operators:

query

query: object

query.entry

entry: (source, oper, entry) => boolean = queries.queryEntry

Checks whether query parameters contain or lack a specific [key, value] entry.

Parameters
source

URL | URLSearchParams

The query source to inspect (URL or URLSearchParams).

oper

QueryEntryOper

The entry operation to perform (‘contains_entry’ or ‘lacks_entry’).

entry

[string, string]

The [key, value] pair to check.

Returns

boolean

True if the entry check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
const source = new URLSearchParams('tag=ts&tag=ai&sort=desc');
const entryA: [string, string] = ['tag', 'ai'];
const entryB: [string, string] = ['tag', 'rust'];

queryEntry(source, 'contains_entry', entryA); // true
queryEntry(source, 'lacks_entry', entryB); // true
Remarks

Supported Operators:

query.key

key: (source, oper, key) => boolean = queries.queryKey

Checks whether query parameters contain or lack a key.

Parameters
source

URL | URLSearchParams

The query source to inspect (URL or URLSearchParams).

oper

QueryKeyOper

The key operation to perform (‘contains_key’ or ‘lacks_key’).

key

string

The key to check.

Returns

boolean

True if the key check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
const source = new URLSearchParams('q=predicates&page=2');
const keyA = 'q';
const keyB = 'lang';

queryKey(source, 'contains_key', keyA); // true
queryKey(source, 'lacks_key', keyB); // true
Remarks

Supported Operators:

query.size

size: (source, oper, size) => boolean = queries.querySize

Checks the number of query entries against a numeric threshold.

Parameters
source

URL | URLSearchParams

The query source to inspect (URL or URLSearchParams).

oper

QuerySizeOper

The size operation to perform (e.g. ‘size_equals’, ‘size_greater_than’).

size

number

The numeric threshold to compare against.

Returns

boolean

True if the size comparison is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
const source = new URLSearchParams('tag=ts&tag=ai&sort=desc');
const sizeA = 3;
const sizeB = 2;

querySize(source, 'size_equals', sizeA); // true
querySize(source, 'size_greater_than', sizeB); // true
Remarks

Supported Operators:

query.state

state: (source, oper) => boolean = queries.queryState

Checks whether query parameters are empty or not empty.

Parameters
source

URL | URLSearchParams

The query source to inspect (URL or URLSearchParams).

oper

QueryStateOper

The state operation to perform (‘is_empty’ or ‘is_not_empty’).

Returns

boolean

True if the state check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
const sourceA = new URLSearchParams('q=predicate');
const sourceB = new URLSearchParams('');

queryState(sourceA, 'is_not_empty'); // true
queryState(sourceB, 'is_empty'); // true
Remarks

Supported Operators:

query.value

value: (source, oper, value) => boolean = queries.queryValue

Checks whether query parameters contain or lack a value.

Parameters
source

URL | URLSearchParams

The query source to inspect (URL or URLSearchParams).

oper

QueryValueOper

The value operation to perform (‘contains_value’ or ‘lacks_value’).

value

string

The value to check.

Returns

boolean

True if the value check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
const source = new URLSearchParams('status=active&role=admin&role=editor');
const valueA = 'editor';
const valueB = 'guest';

queryValue(source, 'contains_value', valueA); // true
queryValue(source, 'lacks_value', valueB); // true
Remarks

Supported Operators:

regexp

regexp: object

regexp.pattern

pattern: (pattern, oper, target) => boolean = regexps.regexpPattern

Checks the pattern string of a RegExp using the specified operation.

Parameters
pattern

RegExp

The RegExp pattern to check.

oper

RegExpPatternOper

The pattern operation to perform (e.g. ‘equals’, ‘includes’).

target

string

The string to compare against the RegExp pattern source.

Returns

boolean

True if the pattern check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
const pattern = /^user_[a-z]+$/;
const targetA = '^user_';
const targetB = 'admin';

regexpPattern(pattern, 'starts_with', targetA); // true
regexpPattern(pattern, 'excludes', targetB); // true
Remarks

Supported Operators:

regexp.result

result: (pattern, oper, target) => boolean = regexps.regexpResult

Evaluates a RegExp against a target string and validates the result using the specified operation.

Parameters
pattern

RegExp

The RegExp pattern to apply.

oper

RegExpResultOper

The result operation to perform (e.g. ‘tests’, ‘matches’).

target

string

The candidate string to validate.

Returns

boolean

True if the result operation is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
const pattern = /cat/i;
const targetA = 'My Cat is sleeping';
const targetB = 'dog only';

regexpResult(pattern, 'tests', targetA); // true
regexpResult(pattern, 'not_matches', targetB); // true
Remarks

Supported Operators:

regexp.resultRange

resultRange: (pattern, oper, target, min, max) => boolean = regexps.regexpResultRange

Counts RegExp matches on a target string and validates whether the count is within a range.

Parameters
pattern

RegExp

The RegExp pattern to apply.

oper

RegExpResultRangeOper

The range operation to perform (e.g. ‘between’, ‘strict_between’).

target

string

The candidate string to validate.

min

number

The lower bound of the range.

max

number

The upper bound of the range.

Returns

boolean

True if the range comparison is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
const pattern = /item/g;
const target = 'item,item,item';
const minA = 2;
const maxA = 4;
const minB = 3;
const maxB = 5;

regexpResultRange(pattern, 'between', target, minA, maxA); // true
regexpResultRange(pattern, 'strict_between', target, minB, maxB); // false
Remarks

Supported Operators:

regexp.resultSize

resultSize: (pattern, oper, target, count) => boolean = regexps.regexpResultSize

Counts RegExp matches on a target string and compares the count against a threshold.

Parameters
pattern

RegExp

The RegExp pattern to apply.

oper

RegExpResultSizeOper

The size operation to perform (e.g. ‘size_equals’, ‘size_greater_than’).

target

string

The candidate string to validate.

count

number

The numeric threshold to compare against.

Returns

boolean

True if the count comparison is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
const pattern = /foo/g;
const target = 'foo-bar-foo';
const countA = 2;
const countB = 1;

regexpResultSize(pattern, 'size_equals', target, countA); // true
regexpResultSize(pattern, 'size_greater_than', target, countB); // true
Remarks

Supported Operators:

regexp.state

state: (source, oper) => boolean = regexps.regexpState

Checks the state of a RegExp (flags and pattern shape) using the specified operation.

Parameters
source

RegExp

The RegExp to check.

oper

RegExpStateOper

The state operation to perform (e.g. ‘is_global’, ‘has_indices’).

Returns

boolean

True if the state check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
const sourceA = /foo/gi;
const sourceB = new RegExp('');

regexpState(sourceA, 'is_global'); // true
regexpState(sourceA, 'is_ignore_case'); // true
regexpState(sourceB, 'is_empty_pattern'); // true
Remarks

Supported Operators:

url

url: object

url.hash

hash: (source, oper, target) => boolean = urls.urlHash

Checks the hash component of a URL against a string operation.

Parameters
source

URL

The URL to inspect.

oper

UrlHashOper

The hash operation to perform (e.g. ‘equals’, ‘starts_with’).

target

string

The string to compare against source.hash.

Returns

boolean

True if the hash comparison is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
const source = new URL('https://example.com/docs#install');
const targetA = '#install';
const targetB = '#guide';

urlHash(source, 'equals', targetA); // true
urlHash(source, 'not_equals', targetB); // true
Remarks

Supported Operators:

url.host

host: (source, oper, target) => boolean = urls.urlHost

Checks the host component of a URL against a string operation.

Parameters
source

URL

The URL to inspect.

oper

UrlHostOper

The host operation to perform (e.g. ‘equals’, ‘ends_with’).

target

string

The string to compare against source.host.

Returns

boolean

True if the host comparison is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
const source = new URL('https://portal.example.com:8080/dashboard');
const targetA = 'portal.example.com:8080';
const targetB = ':8080';

urlHost(source, 'equals', targetA); // true
urlHost(source, 'ends_with', targetB); // true
Remarks

Supported Operators:

url.href

href: (source, oper, target) => boolean = urls.urlHref

Checks the href component of a URL against a string operation.

Parameters
source

URL

The URL to inspect.

oper

UrlHrefOper

The href operation to perform (e.g. ‘equals’, ‘includes’).

target

string

The string to compare against source.href.

Returns

boolean

True if the href comparison is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
const source = new URL('https://docs.example.com:443/path?q=1#intro');
const targetA = 'https://docs.example.com/path?q=1#intro';
const targetB = 'docs.example.com';

urlHref(source, 'equals', targetA); // true
urlHref(source, 'includes', targetB); // true
Remarks

Supported Operators:

url.hostname

hostname: (source, oper, target) => boolean = urls.urlHostname

Checks the hostname component of a URL against a string operation.

Parameters
source

URL

The URL to inspect.

oper

UrlHostnameOper

The hostname operation to perform (e.g. ‘equals’, ‘excludes’).

target

string

The string to compare against source.hostname.

Returns

boolean

True if the hostname comparison is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
const source = new URL('https://blog.example.com/posts');
const targetA = 'blog.example.com';
const targetB = 'internal';

urlHostname(source, 'equals', targetA); // true
urlHostname(source, 'excludes', targetB); // true
Remarks

Supported Operators:

url.origin

origin: (source, oper, target) => boolean = urls.urlOrigin

Checks the origin component of a URL against a string operation.

Parameters
source

URL

The URL to inspect.

oper

UrlOriginOper

The origin operation to perform (e.g. ‘equals’, ‘starts_with’).

target

string

The string to compare against source.origin.

Returns

boolean

True if the origin comparison is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
const source = new URL('https://api.example.com:8443/v1/users');
const targetA = 'https://api.example.com:8443';
const targetB = 'https://api.';

urlOrigin(source, 'equals', targetA); // true
urlOrigin(source, 'starts_with', targetB); // true
Remarks

Supported Operators:

url.pathname

pathname: (source, oper, target) => boolean = urls.urlPathname

Checks the pathname component of a URL against a string operation.

Parameters
source

URL

The URL to inspect.

oper

UrlPathnameOper

The pathname operation to perform (e.g. ‘starts_with’, ‘includes’).

target

string

The string to compare against source.pathname.

Returns

boolean

True if the pathname comparison is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
const source = new URL('https://example.com/products/books/42');
const targetA = '/products';
const targetB = '/42';

urlPathname(source, 'starts_with', targetA); // true
urlPathname(source, 'ends_with', targetB); // true
Remarks

Supported Operators:

url.port

port: (source, oper, target) => boolean = urls.urlPort

Checks the port component of a URL against a string operation.

Parameters
source

URL

The URL to inspect.

oper

UrlPortOper

The port operation to perform (e.g. ‘equals’, ‘not_equals’).

target

string

The string to compare against source.port.

Returns

boolean

True if the port comparison is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
const source = new URL('https://localhost:3000/health');
const targetA = '3000';
const targetB = '8080';

urlPort(source, 'equals', targetA); // true
urlPort(source, 'not_equals', targetB); // true
Remarks

Supported Operators:

url.protocol

protocol: (source, oper, target) => boolean = urls.urlProtocol

Checks the protocol component of a URL against a string operation.

Parameters
source

URL

The URL to inspect.

oper

UrlProtocolOper

The protocol operation to perform (e.g. ‘equals’, ‘includes’).

target

string

The string to compare against source.protocol.

Returns

boolean

True if the protocol comparison is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
const source = new URL('https://example.com/docs');
const targetA = 'https:';
const targetB = 'http';

urlProtocol(source, 'equals', targetA); // true
urlProtocol(source, 'includes', targetB); // true
Remarks

Supported Operators:

url.state

state: (source, oper) => boolean = urls.urlState

Checks state flags of a URL (presence and protocol checks).

Parameters
source

URL

The URL to inspect.

oper

UrlStateOper

The state operation to perform (e.g. ‘has_hash’, ‘is_https’).

Returns

boolean

True if the state check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
const source = new URL('https://user:pass@example.com:8443/docs?q=1#intro');

urlState(source, 'has_hash'); // true
urlState(source, 'has_search'); // true
urlState(source, 'has_port'); // true
urlState(source, 'is_https'); // true
Remarks

Supported Operators:

set

set: object

set.arrayMembership

arrayMembership: <T>(source, oper, target) => boolean = sets.setArrayMembership

Checks membership conditions for multiple elements in a set using the specified operation.

Type Parameters
T

T

Type of the Set elements.

Parameters
source

Set<T>

The set to check.

oper

SetArrayMembershipOper

The membership operation to perform (e.g. ‘contains_all’, ‘contains_any’).

target

T[]

The array of values to check for membership.

Returns

boolean

True if the membership check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
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)
Remarks

Supported Operators:

set.comparison

comparison: <T>(source, oper, target) => boolean = sets.setComparison

Compares two sets for equality or inequality using the specified operation.

Type Parameters
T

T

Type of the Set elements.

Parameters
source

Set<T>

The first set to compare.

oper

SetComparisonOper

The comparison operation to perform (e.g. ‘equals’, ‘not_equals’).

target

Set<T>

The second set to compare.

Returns

boolean

True if the comparison is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
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
Remarks

Supported Operators:

set.intersection

intersection: <T>(source, oper, target) => boolean = sets.setIntersection

Checks intersection properties between two sets using the specified operation.

Type Parameters
T

T

Type of the Set elements.

Parameters
source

Set<T>

The first set.

oper

SetIntersectionOper

The intersection operation to perform (e.g. ‘disjoint’, ‘intersects’).

target

Set<T>

The second set.

Returns

boolean

True if the intersection check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
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
Remarks

Supported Operators:

set.membership

membership: <T>(source, oper, target) => boolean = sets.setMembership

Checks membership conditions for elements in a set using the specified operation.

Type Parameters
T

T

Type of the Set elements.

Parameters
source

Set<T>

The set to check.

oper

SetMembershipOper

The membership operation to perform (e.g. ‘includes’, ‘excludes’).

target

T

The value to check for membership.

Returns

boolean

True if the membership check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
const s = new Set([1, 2, 3]);

setMembership(s, 'includes', 2); // true
setMembership(s, 'excludes', 4); // true
Remarks

Supported Operators:

set.relation

relation: <T>(source, oper, target) => boolean = sets.setRelation

Checks the relation between two sets (disjoint, intersects, subset, superset) using the specified operation.

Type Parameters
T

T

Type of the Set elements.

Parameters
source

Set<T>

The first set.

oper

SetRelationOper

The relation operation to perform (e.g. ‘disjoint’, ‘subset_of’).

target

Set<T>

The second set.

Returns

boolean

True if the relation check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
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
Remarks

Supported Operators:

set.size

size: <T>(source, oper, target) => boolean = sets.setSize

Checks the size of a set using the specified operation.

Type Parameters
T

T

Type of the Set elements.

Parameters
source

Set<T>

The set to check.

oper

SetSizeOper

The size operation to perform (e.g. ‘size_equals’, ‘size_greater_than’).

target

number

The size to compare against.

Returns

boolean

True if the size check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
const a = new Set([1, 2, 3]);

setSize(a, 'size_equals', 3); // true
setSize(a, 'size_greater_than', 2); // true
Remarks

Supported Operators:

set.state

state: <T>(source, oper) => boolean = sets.setState

Checks the state of a set using the specified operation.

Type Parameters
T

T

Type of the Set elements.

Parameters
source

Set<T>

The set to check.

oper

SetStateOper

The state operation to perform (e.g. ‘is_empty’, ‘has_primitives’).

Returns

boolean

True if the state check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
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
Remarks

Supported Operators:

string

string: object

string.comparison

comparison: (source, oper, target) => boolean = strings.stringComparison

Compares two strings using the specified operation.

Parameters
source

string

The first string.

oper

StringComparisonOper

The comparison operation to perform (e.g. ‘equals’, ‘greater_than’).

target

string

The second string.

Returns

boolean

True if the comparison is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
const a = 'foo';
const b = 'bar';

stringComparison(a, 'greater_than', b); // true
stringComparison(a, 'equals', a); // true
Remarks

Supported Operators:

string.membership

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.

Parameters
source

string

The string to check.

oper

StringMembershipOper

The membership operation to perform (e.g. ‘in’, ‘not_in’).

target

string[]

The array of strings to check membership against.

Returns

boolean

True if the membership check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
const arr = ['foo', 'bar'];
const value1 = 'foo';
const value2 = 'baz';

stringMembership(value1, 'in', arr); // true
stringMembership(value2, 'not_in', arr); // true
Remarks

Supported Operators:

string.pattern

pattern: (source, oper, pattern) => boolean = strings.stringPattern

Evaluates a string against a pattern operation (matches or not matches a RegExp) using the specified operation.

Parameters
source

string

The string to test.

oper

StringPatternOper

The pattern operation to perform (e.g. ‘matches’, ‘not_matches’).

pattern

RegExp

The RegExp to test against.

Returns

boolean

True if the operation matches, false otherwise.

Throws

If the operation is not recognized.

Example
const str = 'foobar';
const pattern1 = /^foo/;
const pattern2 = /baz/;

stringPattern(str, 'matches', pattern1); // true
stringPattern(str, 'not_matches', pattern2); // true
Remarks

Supported Operators:

string.size

size: (source, oper, target) => boolean = strings.stringSize

Checks the size (length) of a string using the specified operation.

Parameters
source

string

The string to check.

oper

StringSizeOper

The size operation to perform (e.g. ‘size_equals’, ‘size_greater_than’).

target

number

The length to compare against.

Returns

boolean

True if the size check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
const str = 'hello';
const len1 = 5;
const len2 = 3;

stringSize(str, 'size_equals', len1); // true
stringSize(str, 'size_greater_than', len2); // true
Remarks

Supported Operators:

string.state

state: (source, oper) => boolean = strings.stringState

Checks the state of a string (empty, not empty, blank, not blank) using the specified operation.

Parameters
source

string

The string to check.

oper

StringStateOper

The state operation to perform (e.g. ‘is_empty’, ‘is_not_blank’).

Returns

boolean

True if the state check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
const str = '';
const str2 = '   ';

stringState(str, 'is_empty'); // true
stringState(str2, 'is_blank'); // true
Remarks

Supported Operators:

string.substring

substring: (source, oper, target) => boolean = strings.stringSubstring

Checks if a string contains, excludes, starts with, or ends with a substring using the specified operation.

Parameters
source

string

The string to check.

oper

StringSubstringOper

The substring operation to perform (e.g. ‘includes’, ‘starts_with’).

target

string

The substring to check for.

Returns

boolean

True if the substring check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
const str = 'foobar';

stringSubstring(str, 'includes', sub); // true
stringSubstring(str, 'starts_with', sub); // true
Remarks

Supported Operators:

symbol

symbol: object

symbol.comparison

comparison: (source, oper, target) => boolean = symbols.symbolComparison

Compares two symbols for equality or inequality using the specified operation.

Parameters
source

symbol

The first symbol to compare.

oper

SymbolComparisonOper

The comparison operation to perform (e.g. ‘equals’, ‘not_equals’).

target

symbol

The second symbol to compare.

Returns

boolean

True if the comparison is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
const a = Symbol('foo');
const b = Symbol('foo');

symbolComparison(a, 'equals', a); // true
symbolComparison(a, 'not_equals', b); // true
Remarks

Supported Operators:

symbol.state

state: (source, oper) => boolean = symbols.symbolState

Checks the state of a symbol (global or local) using the specified operation.

Parameters
source

symbol

The symbol to check.

oper

SymbolStateOper

The state operation to perform (e.g. ‘is_global’, ‘is_local’).

Returns

boolean

True if the state check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example
const globalSym = Symbol.for('foo');
const localSym = Symbol('bar');

symbolState(globalSym, 'is_global'); // true
symbolState(localSym, 'is_local'); // true
Remarks

Supported Operators: