UNPKG

typedash

Version:

modern, type-safe collection of utility functions

76 lines (66 loc) 1.81 kB
'use strict'; // src/functions/isArray/isArray.ts var isArray = Array.isArray; // src/functions/castArrayIfDefined/castArrayIfDefined.ts function castArrayIfDefined(value) { if (value == null) { return value; } if (isArray(value)) { return value; } return [value]; } // src/functions/castArray/castArray.ts function castArray(value) { return castArrayIfDefined(value ?? []); } // src/functions/createTypeGuard/createTypeGuard.ts function createTypeGuard(values) { const setValues = new Set(values); return function predicate(v) { return setValues.has(v); }; } // src/functions/_internal/filterObject/createObjectPredicate.ts function createObjectPredicate(propertiesOrPredicate) { return typeof propertiesOrPredicate === "function" ? propertiesOrPredicate : createPropertiesPredicate(propertiesOrPredicate); } function createPropertiesPredicate(properties) { const isKnownProperty = createTypeGuard(castArray(properties)); return (_value, key) => isKnownProperty(key); } // src/functions/objectEntries/objectEntries.ts var objectEntries = Object.entries; // src/functions/_internal/filterObject/filterObject.ts function filterObject(object, predicate) { if (object == null) { return {}; } return Object.fromEntries( objectEntries(object).filter( ([key, value]) => predicate( value, key, object ) ) ); } // src/functions/negate/negate.ts function negate(func) { return (...args) => { const result = func(...args); return !result; }; } // src/functions/omit/omit.ts function omit(object, propertiesOrPredicate) { return filterObject( object, negate(createObjectPredicate(propertiesOrPredicate)) ); } exports.omit = omit; //# sourceMappingURL=out.js.map //# sourceMappingURL=index.cjs.map