UNPKG

predictype

Version:

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

26 lines (25 loc) 831 B
import { MapKeyOper } from '../../enums/maps.js'; /** * Checks if a Map contains (or lacks) a specific key using the specified operation. * * @param source The Map to check. * @param oper The key operation to perform (e.g. 'has_key', 'lacks_key'). * @param key The key to check for. * @returns True if the key check is valid according to the operator, otherwise false. * * @throws {Error} If the operation is not recognized. * * @example * const m = new Map([[1, 'a']]); * const key1 = 1; * const key2 = 2; * * mapKey(m, 'has_key', key1); // true * mapKey(m, 'lacks_key', key2); // true * * @remarks * Supported Operators: * - **CONTAINS_KEY**: Map contains the key * - **LACKS_KEY**: Map does not contain the key */ export declare function mapKey<K, V>(source: Map<K, V>, oper: MapKeyOper, key: K): boolean;