{"version":3,"file":"omitDeep.mjs","sources":["../../../src/omitDeep/omitDeep.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"],"names":["needOmit","value","lodash","omitDeep","object","paths","omitDeepOnOwnProps","element","temp","key"],"mappings":";AAIO,MAAMA,IAAW,CAACC,MACvB,CAACC,EAAO,MAAMD,CAAK,MAAMC,EAAO,cAAcD,CAAK,KAAK,MAAM,QAAQA,CAAK,IAiChEE,IAAqB,CAACC,MAAgBC,MAAe;AAChE,WAASC,EAAmBF,GAAa;AACnC,QAAA,CAAC,MAAM,QAAQA,CAAM,KAAK,CAACF,EAAO,cAAcE,CAAM;AACjDA,aAAAA;AAGL,QAAA,MAAM,QAAQA,CAAM;AACtB,aAAOA,EAAO,IAAI,CAACG,MAAaP,EAASO,CAAO,IAAIJ,EAASI,GAAS,GAAGF,CAAK,IAAIE,CAAQ;AAG5F,UAAMC,IAAO,CAAC;AAEd,eAAW,CAACC,GAAKR,CAAK,KAAK,OAAO,QAE/BG,CAAM;AACN,MAAAI,EAAaC,CAAG,IAAIT,EAASC,CAAK,IAAIE,EAASF,GAAO,GAAGI,CAAK,IAAIJ;AAErE,WAAOC,EAAO,KAAKM,GAAM,GAAGH,CAAK;AAAA,EAAA;AAGnC,SAAOC,EAAmBF,CAAM;AAClC;"}