predictype

predictype v0.8.1


predictype / predicates/strings/stringSize / stringSize

Function: stringSize()

stringSize(source, oper, target): boolean

Defined in: predicates/strings/stringSize.ts:29

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

Remarks

Supported Operators: