UNPKG

lodash-omitdeep

Version:

lodash omitDeep/omitByDeep object key/value recursively

1 lines 2.27 kB
{"version":3,"file":"omitDeepBy.cjs","sources":["../../../src/omitDeepBy/omitDeepBy.ts"],"sourcesContent":["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"],"names":["omitDeepBy","object","cb","omitByDeepByOnOwnProps","lodash","element","temp","key","value"],"mappings":"0GAsCaA,EAAyB,CAACC,EAAaC,IAAY,CAC9D,SAASC,EAAuBF,EAAa,CAC3C,GAAI,CAAC,MAAM,QAAQA,CAAM,GAAK,CAACG,EAAO,cAAcH,CAAM,EACxD,OAAOA,EAGT,GAAI,MAAM,QAAQA,CAAM,EACtB,OAAOA,EAAO,IAAKI,GAAYL,EAAWK,EAASH,CAAE,CAAC,EAGxD,MAAMI,EAAO,CAAA,EAEb,SAAW,CAACC,EAAKC,CAAK,IAAK,OAAO,QAE/BP,CAAM,EACNK,EAAaC,CAAG,EAAIP,EAAWQ,EAAON,CAAE,EAE3C,OAAOE,EAAO,OAAOE,EAAMJ,CAAE,CAC/B,CAEA,OAAOC,EAAuBF,CAAM,CACtC"}