UNPKG

1.24 kBJavaScriptView Raw
1import { isPlainObject } from "./objects.js";
2export function omitDeep(value, key) {
3 return __omitDeep(value, key);
4}
5function __omitDeep(value, key, known) {
6 if (known === void 0) { known = new Map(); }
7 if (known.has(value)) {
8 return known.get(value);
9 }
10 var modified = false;
11 if (Array.isArray(value)) {
12 var array_1 = [];
13 known.set(value, array_1);
14 value.forEach(function (value, index) {
15 var result = __omitDeep(value, key, known);
16 modified || (modified = result !== value);
17 array_1[index] = result;
18 });
19 if (modified) {
20 return array_1;
21 }
22 }
23 else if (isPlainObject(value)) {
24 var obj_1 = Object.create(Object.getPrototypeOf(value));
25 known.set(value, obj_1);
26 Object.keys(value).forEach(function (k) {
27 if (k === key) {
28 modified = true;
29 return;
30 }
31 var result = __omitDeep(value[k], key, known);
32 modified || (modified = result !== value[k]);
33 obj_1[k] = result;
34 });
35 if (modified) {
36 return obj_1;
37 }
38 }
39 return value;
40}
41//# sourceMappingURL=omitDeep.js.map
\No newline at end of file