UNPKG

predictype

Version:

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

39 lines (38 loc) 1.46 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.bigintMembership = bigintMembership; const bigints_js_1 = require("../../enums/bigints.js"); /** * Checks if a bigint value is (or is not) a member of a set of bigints using the specified operation. * * @param source The source bigint value. * @param oper The membership operation to perform (e.g. 'is_one_of', 'is_not_one_of'). * @param target The array of bigints to check membership against. * @returns True if the membership check is valid according to the operator, otherwise false. * * @throws {Error} If the operation is not recognized. * * @example * const value1 = BigInt(5); * const value2 = BigInt(3); * const arr = [BigInt(1), BigInt(2), BigInt(5)]; * * bigintMembership(value1, 'is_one_of', arr); // true * bigintMembership(value2, 'is_not_one_of', arr); // true * * @remarks * Supported Operators: * - **IN**: value is in the target array * - **NOT_IN**: value is not in the target array */ function bigintMembership(source, oper, target) { const operators = { [bigints_js_1.BigIntMembershipEnum.IN]: (a, b) => b.includes(a), [bigints_js_1.BigIntMembershipEnum.NOT_IN]: (a, b) => !b.includes(a), }; const enumOper = typeof oper === 'string' ? oper : oper; const fn = operators[enumOper]; if (!fn) throw new Error(`Unknown BigIntMembership operation: ${oper}`); return fn(source, target); }