predictype

predictype v0.13.0


predictype / predicates/objects / objectKeyMembership

Function: objectKeyMembership()

objectKeyMembership(source, oper, keys): boolean

Defined in: predicates/objects/objectKeyMembership.ts:27

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: