UNPKG

lodash-omitdeep

Version:

lodash omitDeep/omitByDeep object key/value recursively

1 lines 4.5 kB
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/omitDeep/omitDeep.ts","../../src/omitDeepBy/omitDeepBy.ts"],"sourcesContent":["import type { Many, PartialObject, PropertyName } from 'lodash';\n\nimport lodash from 'lodash';\n\nexport const needOmit = (value: any) =>\n !lodash.isNil(value) && (lodash.isPlainObject(value) || Array.isArray(value));\n\ninterface OmitDeep {\n <T extends object, K extends PropertyName[]>(\n object: T | null | undefined,\n ...paths: K\n ): Pick<T, Exclude<keyof T, K[number]>>;\n <T extends object, K extends keyof T>(\n object: T | null | undefined,\n ...paths: Many<K>[]\n ): Omit<T, K>;\n <T extends object>(\n object: T | null | undefined,\n ...paths: Many<PropertyName>[]\n ): PartialObject<T>;\n}\n\n/**\n * The opposite of `_.pick`; this method creates an object composed of the\n * own and inherited enumerable properties of `object` that are not omitted.\n *\n * @category Function\n * @param object The source object.\n * @param [paths] The property names to omit, specified\n * individually or in arrays.\n * @returns Returns the new object.\n * @example\n *\n * const object = { 'a': 1, 'b': 2, 'c': { 'a': 1, 'b': 2 } };\n *\n * omitDeep(object, ['b', 'a']);\n * // => { 'c': {} }\n */\nexport const omitDeep: OmitDeep = (object: any, ...paths: any) => {\n function omitDeepOnOwnProps(object: any) {\n if (!Array.isArray(object) && !lodash.isPlainObject(object)) {\n return object;\n }\n\n if (Array.isArray(object)) {\n return object.map((element) => (needOmit(element) ? omitDeep(element, ...paths) : element));\n }\n\n const temp = {};\n\n for (const [key, value] of Object.entries<{\n [x: string]: object | PropertyName;\n }>(object)) {\n (temp as any)[key] = needOmit(value) ? omitDeep(value, ...paths) : value;\n }\n return lodash.omit(temp, ...paths);\n }\n\n return omitDeepOnOwnProps(object);\n};\n","import type {\n Dictionary,\n NumericDictionary,\n PartialObject,\n PropertyName,\n ValueKeyIteratee\n} from 'lodash';\n\nimport lodash from 'lodash';\n\ninterface OmitDeepBy {\n <T>(object: Dictionary<T> | null | undefined, predicate?: ValueKeyIteratee<T>): Dictionary<T>;\n <T>(\n object: NumericDictionary<T> | null | undefined,\n predicate?: ValueKeyIteratee<T>\n ): NumericDictionary<T>;\n <T extends object>(\n object: T | null | undefined,\n predicate: ValueKeyIteratee<T[keyof T]>\n ): PartialObject<T>;\n}\n\n/**\n * The opposite of `_.pickBy`; this method creates an object composed of the\n * own and inherited enumerable properties of `object` that `predicate`\n * doesn't return truthy for.\n *\n * @category Function\n * @param object The source object.\n * @param [predicate] The function invoked per property.\n * @returns Returns the new object.\n * @example\n *\n * const object = { 'a': 1, 'b': null, 'c': { 'a': 1, 'b': null } };\n *\n * omitByDeep(object, _.isNil);\n * // => { 'a': 1, 'c': { 'a': 1 } }\n */\nexport const omitDeepBy: OmitDeepBy = (object: any, cb: any) => {\n function omitByDeepByOnOwnProps(object: any) {\n if (!Array.isArray(object) && !lodash.isPlainObject(object)) {\n return object;\n }\n\n if (Array.isArray(object)) {\n return object.map((element) => omitDeepBy(element, cb));\n }\n\n const temp = {};\n\n for (const [key, value] of Object.entries<{\n [x: string]: object | PropertyName;\n }>(object)) {\n (temp as any)[key] = omitDeepBy(value, cb);\n }\n return lodash.omitBy(temp, cb);\n }\n\n return omitByDeepByOnOwnProps(object);\n};\n"],"mappings":";;AAIA,MAAa,YAAY,UACvB,CAAC,OAAO,MAAM,KAAK,MAAM,OAAO,cAAc,KAAK,KAAK,MAAM,QAAQ,KAAK;;;;;;;;;;;;;;;;;AAiC7E,MAAa,YAAsB,QAAa,GAAG,UAAe;CAChE,SAAS,mBAAmB,QAAa;EACvC,IAAI,CAAC,MAAM,QAAQ,MAAM,KAAK,CAAC,OAAO,cAAc,MAAM,GACxD,OAAO;EAGT,IAAI,MAAM,QAAQ,MAAM,GACtB,OAAO,OAAO,KAAK,YAAa,SAAS,OAAO,IAAI,SAAS,SAAS,GAAG,KAAK,IAAI,OAAQ;EAG5F,MAAM,OAAO,CAAC;EAEd,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAE/B,MAAM,GACP,KAAc,OAAO,SAAS,KAAK,IAAI,SAAS,OAAO,GAAG,KAAK,IAAI;EAErE,OAAO,OAAO,KAAK,MAAM,GAAG,KAAK;CACnC;CAEA,OAAO,mBAAmB,MAAM;AAClC;;;;;;;;;;;;;;;;;;;ACrBA,MAAa,cAA0B,QAAa,OAAY;CAC9D,SAAS,uBAAuB,QAAa;EAC3C,IAAI,CAAC,MAAM,QAAQ,MAAM,KAAK,CAAC,OAAO,cAAc,MAAM,GACxD,OAAO;EAGT,IAAI,MAAM,QAAQ,MAAM,GACtB,OAAO,OAAO,KAAK,YAAY,WAAW,SAAS,EAAE,CAAC;EAGxD,MAAM,OAAO,CAAC;EAEd,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAE/B,MAAM,GACP,KAAc,OAAO,WAAW,OAAO,EAAE;EAE3C,OAAO,OAAO,OAAO,MAAM,EAAE;CAC/B;CAEA,OAAO,uBAAuB,MAAM;AACtC"}