UNPKG

softkave-js-utils

Version:

JavaScript & Typescript utility functions, types, and classes

24 lines 639 B
import assert from 'assert'; import { isArray, isObject } from 'lodash-es'; export function omitDeep(data, /** Called with value and key. Should return `true` to omit, and `false` to * keep. */ omitFn) { const result = isArray(data) ? [] : isObject(data) ? {} : undefined; assert(result); for (const key in data) { let value = data[key]; if (!omitFn(value, key)) { if (isObject(value)) { value = omitDeep(value, omitFn); } result[key] = value; } } return result; } //# sourceMappingURL=omitDeep.js.map