predictype

predictype v0.8.1


predictype / predicates/strings / stringMembership

Function: stringMembership()

stringMembership(source, oper, target): boolean

Defined in: predicates/strings/stringMembership.ts:26

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: