predictype

predictype v0.8.1


predictype / predicates/arrays/arraySize / arraySize

Function: arraySize()

arraySize(source, oper, target): boolean

Defined in: predicates/arrays/arraySize.ts:29

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. ‘length_equals’, ‘length_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, 'length_equals', len1); // true
arraySize(arr, 'length_greater_than', len2); // true

Remarks

Supported Operators: