UNPKG

lodash-omitdeep

Version:

lodash omitDeep/omitByDeep object key/value recursively

86 lines (85 loc) 3.34 kB
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); //#region \0rolldown/runtime.js var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) { key = keys[i]; if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: ((k) => from[k]).bind(null, key), enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod)); //#endregion let lodash = require("lodash"); lodash = __toESM(lodash, 1); //#region src/omitDeep/omitDeep.ts const needOmit = (value) => !lodash.default.isNil(value) && (lodash.default.isPlainObject(value) || Array.isArray(value)); /** * The opposite of `_.pick`; this method creates an object composed of the * own and inherited enumerable properties of `object` that are not omitted. * * @category Function * @param object The source object. * @param [paths] The property names to omit, specified * individually or in arrays. * @returns Returns the new object. * @example * * const object = { 'a': 1, 'b': 2, 'c': { 'a': 1, 'b': 2 } }; * * omitDeep(object, ['b', 'a']); * // => { 'c': {} } */ const omitDeep = (object, ...paths) => { function omitDeepOnOwnProps(object) { if (!Array.isArray(object) && !lodash.default.isPlainObject(object)) return object; if (Array.isArray(object)) return object.map((element) => needOmit(element) ? omitDeep(element, ...paths) : element); const temp = {}; for (const [key, value] of Object.entries(object)) temp[key] = needOmit(value) ? omitDeep(value, ...paths) : value; return lodash.default.omit(temp, ...paths); } return omitDeepOnOwnProps(object); }; //#endregion //#region src/omitDeepBy/omitDeepBy.ts /** * The opposite of `_.pickBy`; this method creates an object composed of the * own and inherited enumerable properties of `object` that `predicate` * doesn't return truthy for. * * @category Function * @param object The source object. * @param [predicate] The function invoked per property. * @returns Returns the new object. * @example * * const object = { 'a': 1, 'b': null, 'c': { 'a': 1, 'b': null } }; * * omitByDeep(object, _.isNil); * // => { 'a': 1, 'c': { 'a': 1 } } */ const omitDeepBy = (object, cb) => { function omitByDeepByOnOwnProps(object) { if (!Array.isArray(object) && !lodash.default.isPlainObject(object)) return object; if (Array.isArray(object)) return object.map((element) => omitDeepBy(element, cb)); const temp = {}; for (const [key, value] of Object.entries(object)) temp[key] = omitDeepBy(value, cb); return lodash.default.omitBy(temp, cb); } return omitByDeepByOnOwnProps(object); }; //#endregion exports.omitDeep = omitDeep; exports.omitDeepBy = omitDeepBy; //# sourceMappingURL=index.cjs.map