UNPKG

predictype

Version:

PredicType is a library of pre-built and tested predicates for TypeScript, covering various data types and operations.

28 lines (27 loc) 973 B
import { ObjectKeyOper } from '../../enums/objects.js'; /** * Checks if an object has or lacks a specific key (string or symbol) using the specified operation. * * @param source The object to check. * @param oper The key operation to perform (e.g. 'has_key', 'lacks_key'). * @param key The key to check. * @returns True if the key check is valid according to the operator, otherwise false. * * @throws {Error} If the operation is not recognized. * * @example * const obj = { foo: 1 }; * const obj2 = {}; * const sym = Symbol('baz'); * Object.defineProperty(obj2, sym, { value: 2 }); * * objectKey(obj, 'has_key', 'foo'); // true * objectKey(obj, 'lacks_key', 'bar'); // true * objectKey(obj2, 'has_key', sym); // true * * @remarks * Supported Operators: * - **CONTAINS_KEY**: Object has the key * - **LACKS_KEY**: Object does not have the key */ export declare function objectKey(source: object, oper: ObjectKeyOper, key: string | symbol): boolean;