predictype

predictype v0.13.0


predictype / predicates/objects/objectKeys / objectKeysCompare

Function: objectKeysCompare()

objectKeysCompare(source, oper, keys): boolean

Defined in: predicates/objects/objectKeys.ts:33

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: