@domql/utils 2.5.116 → 2.5.119
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/array.js +0 -20
- package/dist/cjs/array.js +0 -17
- package/dist/cjs/node.js +4 -0
- package/dist/cjs/object.js +74 -26
- package/node.js +9 -0
- package/object.js +118 -27
- package/package.json +2 -2
package/array.js
CHANGED
|
@@ -67,26 +67,6 @@ export const cutArrayAfterValue = (arr, value) => {
|
|
|
67
67
|
return arr
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
export const createNestedObject = (arr, lastValue) => {
|
|
71
|
-
const nestedObject = {}
|
|
72
|
-
|
|
73
|
-
if (arr.length === 0) {
|
|
74
|
-
return lastValue
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
arr.reduce((obj, value, index) => {
|
|
78
|
-
if (!obj[value]) {
|
|
79
|
-
obj[value] = {}
|
|
80
|
-
}
|
|
81
|
-
if (index === arr.length - 1 && lastValue) {
|
|
82
|
-
obj[value] = lastValue
|
|
83
|
-
}
|
|
84
|
-
return obj[value]
|
|
85
|
-
}, nestedObject)
|
|
86
|
-
|
|
87
|
-
return nestedObject
|
|
88
|
-
}
|
|
89
|
-
|
|
90
70
|
export const removeValueFromArray = (arr, value) => {
|
|
91
71
|
const index = arr.indexOf(value)
|
|
92
72
|
if (index > -1) {
|
package/dist/cjs/array.js
CHANGED
|
@@ -21,7 +21,6 @@ __export(array_exports, {
|
|
|
21
21
|
addItemAfterEveryElement: () => addItemAfterEveryElement,
|
|
22
22
|
arrayContainsOtherArray: () => arrayContainsOtherArray,
|
|
23
23
|
arraysEqual: () => arraysEqual,
|
|
24
|
-
createNestedObject: () => createNestedObject,
|
|
25
24
|
cutArrayAfterValue: () => cutArrayAfterValue,
|
|
26
25
|
cutArrayBeforeValue: () => cutArrayBeforeValue,
|
|
27
26
|
getFrequencyInArray: () => getFrequencyInArray,
|
|
@@ -88,22 +87,6 @@ const cutArrayAfterValue = (arr, value) => {
|
|
|
88
87
|
}
|
|
89
88
|
return arr;
|
|
90
89
|
};
|
|
91
|
-
const createNestedObject = (arr, lastValue) => {
|
|
92
|
-
const nestedObject = {};
|
|
93
|
-
if (arr.length === 0) {
|
|
94
|
-
return lastValue;
|
|
95
|
-
}
|
|
96
|
-
arr.reduce((obj, value, index) => {
|
|
97
|
-
if (!obj[value]) {
|
|
98
|
-
obj[value] = {};
|
|
99
|
-
}
|
|
100
|
-
if (index === arr.length - 1 && lastValue) {
|
|
101
|
-
obj[value] = lastValue;
|
|
102
|
-
}
|
|
103
|
-
return obj[value];
|
|
104
|
-
}, nestedObject);
|
|
105
|
-
return nestedObject;
|
|
106
|
-
};
|
|
107
90
|
const removeValueFromArray = (arr, value) => {
|
|
108
91
|
const index = arr.indexOf(value);
|
|
109
92
|
if (index > -1) {
|
package/dist/cjs/node.js
CHANGED
|
@@ -18,6 +18,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var node_exports = {};
|
|
20
20
|
__export(node_exports, {
|
|
21
|
+
isDOMNode: () => isDOMNode,
|
|
21
22
|
isHtmlElement: () => isHtmlElement,
|
|
22
23
|
isNode: () => isNode
|
|
23
24
|
});
|
|
@@ -29,3 +30,6 @@ const isNode = (obj) => {
|
|
|
29
30
|
const isHtmlElement = (obj) => {
|
|
30
31
|
return (typeof HTMLElement === "object" ? obj instanceof import_globals.window.HTMLElement : obj && typeof obj === "object" && obj !== null && obj.nodeType === 1 && typeof obj.nodeName === "string") || false;
|
|
31
32
|
};
|
|
33
|
+
const isDOMNode = (obj) => {
|
|
34
|
+
return typeof import_globals.window !== "undefined" && (obj instanceof import_globals.window.Node || obj instanceof import_globals.window.Window || obj === import_globals.window || obj === document);
|
|
35
|
+
};
|
package/dist/cjs/object.js
CHANGED
|
@@ -20,6 +20,7 @@ var object_exports = {};
|
|
|
20
20
|
__export(object_exports, {
|
|
21
21
|
checkIfKeyIsComponent: () => checkIfKeyIsComponent,
|
|
22
22
|
clone: () => clone,
|
|
23
|
+
createNestedObject: () => createNestedObject,
|
|
23
24
|
createObjectWithoutPrototype: () => createObjectWithoutPrototype,
|
|
24
25
|
deepClone: () => deepClone,
|
|
25
26
|
deepCloneExclude: () => deepCloneExclude,
|
|
@@ -51,6 +52,7 @@ __export(object_exports, {
|
|
|
51
52
|
overwriteDeep: () => overwriteDeep,
|
|
52
53
|
overwriteShallow: () => overwriteShallow,
|
|
53
54
|
removeFromObject: () => removeFromObject,
|
|
55
|
+
removeNestedKeyByPath: () => removeNestedKeyByPath,
|
|
54
56
|
stringToObject: () => stringToObject
|
|
55
57
|
});
|
|
56
58
|
module.exports = __toCommonJS(object_exports);
|
|
@@ -58,6 +60,7 @@ var import_globals = require("./globals.js");
|
|
|
58
60
|
var import_types = require("./types.js");
|
|
59
61
|
var import_array = require("./array.js");
|
|
60
62
|
var import_string = require("./string.js");
|
|
63
|
+
var import_node = require("./node.js");
|
|
61
64
|
const exec = (param, element, state, context) => {
|
|
62
65
|
if ((0, import_types.isFunction)(param)) {
|
|
63
66
|
return param(
|
|
@@ -136,27 +139,28 @@ const deepCloneExclude = (obj, excludeFrom = []) => {
|
|
|
136
139
|
const mergeArrayExclude = (arr, excl = []) => {
|
|
137
140
|
return arr.reduce((acc, curr) => deepMerge(acc, deepCloneExclude(curr, excl)), {});
|
|
138
141
|
};
|
|
139
|
-
const deepClone = (obj,
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
142
|
+
const deepClone = (obj, exclude = [], cleanUndefined = false, visited = /* @__PURE__ */ new WeakMap()) => {
|
|
143
|
+
if (!(0, import_types.isObjectLike)(obj) || (0, import_node.isDOMNode)(obj))
|
|
144
|
+
return obj;
|
|
145
|
+
if (visited.has(obj))
|
|
146
|
+
return visited.get(obj);
|
|
147
|
+
const clone2 = (0, import_types.isArray)(obj) ? [] : {};
|
|
148
|
+
visited.set(obj, clone2);
|
|
149
|
+
for (const key in obj) {
|
|
150
|
+
if (Object.prototype.hasOwnProperty.call(obj, key) && !exclude.includes(key)) {
|
|
151
|
+
const value = obj[key];
|
|
152
|
+
if ((0, import_node.isDOMNode)(value)) {
|
|
153
|
+
clone2[key] = value;
|
|
154
|
+
} else if (key === "extend" && (0, import_types.isArray)(value)) {
|
|
155
|
+
clone2[key] = (0, import_array.mergeArray)(value, exclude);
|
|
156
|
+
} else if ((0, import_types.isObjectLike)(value)) {
|
|
157
|
+
clone2[key] = deepClone(value, exclude, cleanUndefined, visited);
|
|
158
|
+
} else {
|
|
159
|
+
clone2[key] = value;
|
|
160
|
+
}
|
|
153
161
|
}
|
|
154
|
-
if ((0, import_types.isObjectLike)(objProp)) {
|
|
155
|
-
o[prop] = deepClone(objProp, excludeFrom, cleanUndefined);
|
|
156
|
-
} else
|
|
157
|
-
o[prop] = objProp;
|
|
158
162
|
}
|
|
159
|
-
return
|
|
163
|
+
return clone2;
|
|
160
164
|
};
|
|
161
165
|
const deepCloneWithExtend = (obj, excludeFrom = ["node"], options = {}) => {
|
|
162
166
|
const o = options.window ? (0, import_types.isArray)(obj) ? new options.window.Array([]) : new options.window.Object({}) : (0, import_types.isArray)(obj) ? [] : {};
|
|
@@ -411,16 +415,23 @@ const overwriteShallow = (obj, params, excludeFrom = []) => {
|
|
|
411
415
|
}
|
|
412
416
|
return obj;
|
|
413
417
|
};
|
|
414
|
-
const overwriteDeep = (obj, params, excludeFrom = []) => {
|
|
418
|
+
const overwriteDeep = (obj, params, excludeFrom = [], visited = /* @__PURE__ */ new WeakMap()) => {
|
|
419
|
+
if (!(0, import_types.isObjectLike)(obj) || !(0, import_types.isObjectLike)(params) || (0, import_node.isDOMNode)(obj) || (0, import_node.isDOMNode)(params)) {
|
|
420
|
+
return params;
|
|
421
|
+
}
|
|
422
|
+
if (visited.has(obj)) {
|
|
423
|
+
return visited.get(obj);
|
|
424
|
+
}
|
|
425
|
+
visited.set(obj, obj);
|
|
415
426
|
for (const e in params) {
|
|
416
|
-
if (e === "__ref")
|
|
417
|
-
continue;
|
|
418
|
-
if (excludeFrom.includes(e) || e.startsWith("__"))
|
|
427
|
+
if (e === "__ref" || excludeFrom.includes(e) || e.startsWith("__"))
|
|
419
428
|
continue;
|
|
420
429
|
const objProp = obj[e];
|
|
421
430
|
const paramsProp = params[e];
|
|
422
|
-
if ((0,
|
|
423
|
-
|
|
431
|
+
if ((0, import_node.isDOMNode)(paramsProp)) {
|
|
432
|
+
obj[e] = paramsProp;
|
|
433
|
+
} else if ((0, import_types.isObjectLike)(objProp) && (0, import_types.isObjectLike)(paramsProp)) {
|
|
434
|
+
obj[e] = overwriteDeep(objProp, paramsProp, excludeFrom, visited);
|
|
424
435
|
} else if (paramsProp !== void 0) {
|
|
425
436
|
obj[e] = paramsProp;
|
|
426
437
|
}
|
|
@@ -472,6 +483,8 @@ const deepContains = (obj1, obj2, ignoredKeys = ["node", "__ref"]) => {
|
|
|
472
483
|
return true;
|
|
473
484
|
if (!(0, import_types.isObjectLike)(obj1) || !(0, import_types.isObjectLike)(obj2))
|
|
474
485
|
return false;
|
|
486
|
+
if ((0, import_node.isDOMNode)(obj1) || (0, import_node.isDOMNode)(obj2))
|
|
487
|
+
return obj1 === obj2;
|
|
475
488
|
const stack = [[obj1, obj2]];
|
|
476
489
|
const visited = /* @__PURE__ */ new WeakSet();
|
|
477
490
|
while (stack.length > 0) {
|
|
@@ -488,7 +501,10 @@ const deepContains = (obj1, obj2, ignoredKeys = ["node", "__ref"]) => {
|
|
|
488
501
|
return false;
|
|
489
502
|
const value1 = current1[key];
|
|
490
503
|
const value2 = current2[key];
|
|
491
|
-
if ((0,
|
|
504
|
+
if ((0, import_node.isDOMNode)(value1) || (0, import_node.isDOMNode)(value2)) {
|
|
505
|
+
if (value1 !== value2)
|
|
506
|
+
return false;
|
|
507
|
+
} else if ((0, import_types.isObjectLike)(value1) && (0, import_types.isObjectLike)(value2)) {
|
|
492
508
|
if (value1 !== value2) {
|
|
493
509
|
stack.push([value1, value2]);
|
|
494
510
|
}
|
|
@@ -571,3 +587,35 @@ const getExtendsInElement = (obj) => {
|
|
|
571
587
|
traverse(obj);
|
|
572
588
|
return result;
|
|
573
589
|
};
|
|
590
|
+
const createNestedObject = (arr, lastValue) => {
|
|
591
|
+
const nestedObject = {};
|
|
592
|
+
if (arr.length === 0) {
|
|
593
|
+
return lastValue;
|
|
594
|
+
}
|
|
595
|
+
arr.reduce((obj, value, index) => {
|
|
596
|
+
if (!obj[value]) {
|
|
597
|
+
obj[value] = {};
|
|
598
|
+
}
|
|
599
|
+
if (index === arr.length - 1 && lastValue) {
|
|
600
|
+
obj[value] = lastValue;
|
|
601
|
+
}
|
|
602
|
+
return obj[value];
|
|
603
|
+
}, nestedObject);
|
|
604
|
+
return nestedObject;
|
|
605
|
+
};
|
|
606
|
+
const removeNestedKeyByPath = (obj, path) => {
|
|
607
|
+
if (!Array.isArray(path)) {
|
|
608
|
+
throw new Error("Path must be an array.");
|
|
609
|
+
}
|
|
610
|
+
let current = obj;
|
|
611
|
+
for (let i = 0; i < path.length - 1; i++) {
|
|
612
|
+
if (current[path[i]] === void 0) {
|
|
613
|
+
return;
|
|
614
|
+
}
|
|
615
|
+
current = current[path[i]];
|
|
616
|
+
}
|
|
617
|
+
const lastKey = path[path.length - 1];
|
|
618
|
+
if (current && Object.hasOwnProperty.call(current, lastKey)) {
|
|
619
|
+
delete current[lastKey];
|
|
620
|
+
}
|
|
621
|
+
};
|
package/node.js
CHANGED
|
@@ -18,3 +18,12 @@ export const isHtmlElement = obj => {
|
|
|
18
18
|
: obj && typeof obj === 'object' && obj !== null && obj.nodeType === 1 && typeof obj.nodeName === 'string'
|
|
19
19
|
) || false
|
|
20
20
|
}
|
|
21
|
+
|
|
22
|
+
export const isDOMNode = (obj) => {
|
|
23
|
+
return typeof window !== 'undefined' && (
|
|
24
|
+
obj instanceof window.Node ||
|
|
25
|
+
obj instanceof window.Window ||
|
|
26
|
+
obj === window ||
|
|
27
|
+
obj === document
|
|
28
|
+
)
|
|
29
|
+
}
|
package/object.js
CHANGED
|
@@ -4,6 +4,7 @@ import { window } from './globals.js'
|
|
|
4
4
|
import { isFunction, isObjectLike, isObject, isArray, isString, is, isUndefined, isDate, isNull } from './types.js'
|
|
5
5
|
import { mergeAndCloneIfArray, mergeArray } from './array.js'
|
|
6
6
|
import { stringIncludesAny } from './string.js'
|
|
7
|
+
import { isDOMNode } from './node.js'
|
|
7
8
|
|
|
8
9
|
export const exec = (param, element, state, context) => {
|
|
9
10
|
if (isFunction(param)) {
|
|
@@ -95,29 +96,62 @@ export const mergeArrayExclude = (arr, excl = []) => {
|
|
|
95
96
|
/**
|
|
96
97
|
* Deep cloning of object
|
|
97
98
|
*/
|
|
98
|
-
export const deepClone = (obj,
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
99
|
+
export const deepClone = (obj, exclude = [], cleanUndefined = false, visited = new WeakMap()) => {
|
|
100
|
+
// Handle non-object types, null, and ignored types
|
|
101
|
+
if (!isObjectLike(obj) || isDOMNode(obj)) return obj
|
|
102
|
+
|
|
103
|
+
// Check for circular references
|
|
104
|
+
if (visited.has(obj)) return visited.get(obj)
|
|
105
|
+
|
|
106
|
+
// Create a new object or array
|
|
107
|
+
const clone = isArray(obj) ? [] : {}
|
|
108
|
+
|
|
109
|
+
// Store the clone in the WeakMap to handle circular references
|
|
110
|
+
visited.set(obj, clone)
|
|
111
|
+
|
|
112
|
+
// Iterate over the properties of the object
|
|
113
|
+
for (const key in obj) {
|
|
114
|
+
if (Object.prototype.hasOwnProperty.call(obj, key) && !exclude.includes(key)) {
|
|
115
|
+
const value = obj[key]
|
|
116
|
+
|
|
117
|
+
if (isDOMNode(value)) {
|
|
118
|
+
// Skip cloning for DOM nodes
|
|
119
|
+
clone[key] = value
|
|
120
|
+
} else if (key === 'extend' && isArray(value)) {
|
|
121
|
+
clone[key] = mergeArray(value, exclude)
|
|
122
|
+
} else if (isObjectLike(value)) {
|
|
123
|
+
clone[key] = deepClone(value, exclude, cleanUndefined, visited)
|
|
124
|
+
} else {
|
|
125
|
+
clone[key] = value
|
|
126
|
+
}
|
|
112
127
|
}
|
|
113
|
-
if (isObjectLike(objProp)) {
|
|
114
|
-
// queueMicrotask(() => {
|
|
115
|
-
o[prop] = deepClone(objProp, excludeFrom, cleanUndefined)
|
|
116
|
-
// })
|
|
117
|
-
} else o[prop] = objProp
|
|
118
128
|
}
|
|
119
|
-
|
|
129
|
+
|
|
130
|
+
return clone
|
|
120
131
|
}
|
|
132
|
+
// export const deepClone = (obj, excludeFrom = [], cleanUndefined = false) => {
|
|
133
|
+
// const o = isArray(obj) ? [] : {}
|
|
134
|
+
// for (const prop in obj) {
|
|
135
|
+
// if (!Object.prototype.hasOwnProperty.call(obj, prop)) continue
|
|
136
|
+
// // if (prop === 'node' || prop === 'parent' || prop === 'root' || prop === '__element') {
|
|
137
|
+
// // console.warn('recursive clonning is called', obj)
|
|
138
|
+
// // continue
|
|
139
|
+
// // }
|
|
140
|
+
// if (prop === '__proto__') continue
|
|
141
|
+
// if (excludeFrom.includes(prop) || prop.startsWith('__')) continue
|
|
142
|
+
// let objProp = obj[prop]
|
|
143
|
+
// if (cleanUndefined && isUndefined(objProp)) continue
|
|
144
|
+
// if (prop === 'extend' && isArray(objProp)) {
|
|
145
|
+
// objProp = mergeArray(objProp)
|
|
146
|
+
// }
|
|
147
|
+
// if (isObjectLike(objProp)) {
|
|
148
|
+
// // queueMicrotask(() => {
|
|
149
|
+
// o[prop] = deepClone(objProp, excludeFrom, cleanUndefined)
|
|
150
|
+
// // })
|
|
151
|
+
// } else o[prop] = objProp
|
|
152
|
+
// }
|
|
153
|
+
// return o
|
|
154
|
+
// }
|
|
121
155
|
|
|
122
156
|
/**
|
|
123
157
|
* Deep cloning of object
|
|
@@ -426,18 +460,32 @@ export const overwriteShallow = (obj, params, excludeFrom = []) => {
|
|
|
426
460
|
/**
|
|
427
461
|
* Overwrites DEEPLY object properties with another
|
|
428
462
|
*/
|
|
429
|
-
export const overwriteDeep = (obj, params, excludeFrom = []) => {
|
|
463
|
+
export const overwriteDeep = (obj, params, excludeFrom = [], visited = new WeakMap()) => {
|
|
464
|
+
if (!isObjectLike(obj) || !isObjectLike(params) || isDOMNode(obj) || isDOMNode(params)) {
|
|
465
|
+
return params
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
if (visited.has(obj)) {
|
|
469
|
+
return visited.get(obj)
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
visited.set(obj, obj)
|
|
473
|
+
|
|
430
474
|
for (const e in params) {
|
|
431
|
-
if (e === '__ref') continue
|
|
432
|
-
|
|
475
|
+
if (e === '__ref' || excludeFrom.includes(e) || e.startsWith('__')) continue
|
|
476
|
+
|
|
433
477
|
const objProp = obj[e]
|
|
434
478
|
const paramsProp = params[e]
|
|
435
|
-
|
|
436
|
-
|
|
479
|
+
|
|
480
|
+
if (isDOMNode(paramsProp)) {
|
|
481
|
+
obj[e] = paramsProp
|
|
482
|
+
} else if (isObjectLike(objProp) && isObjectLike(paramsProp)) {
|
|
483
|
+
obj[e] = overwriteDeep(objProp, paramsProp, excludeFrom, visited)
|
|
437
484
|
} else if (paramsProp !== undefined) {
|
|
438
485
|
obj[e] = paramsProp
|
|
439
486
|
}
|
|
440
487
|
}
|
|
488
|
+
|
|
441
489
|
return obj
|
|
442
490
|
}
|
|
443
491
|
|
|
@@ -541,6 +589,7 @@ export const isEqualDeep = (param, element, visited = new Set()) => {
|
|
|
541
589
|
export const deepContains = (obj1, obj2, ignoredKeys = ['node', '__ref']) => {
|
|
542
590
|
if (obj1 === obj2) return true
|
|
543
591
|
if (!isObjectLike(obj1) || !isObjectLike(obj2)) return false
|
|
592
|
+
if (isDOMNode(obj1) || isDOMNode(obj2)) return obj1 === obj2
|
|
544
593
|
|
|
545
594
|
const stack = [[obj1, obj2]]
|
|
546
595
|
const visited = new WeakSet()
|
|
@@ -562,7 +611,9 @@ export const deepContains = (obj1, obj2, ignoredKeys = ['node', '__ref']) => {
|
|
|
562
611
|
const value1 = current1[key]
|
|
563
612
|
const value2 = current2[key]
|
|
564
613
|
|
|
565
|
-
if (
|
|
614
|
+
if (isDOMNode(value1) || isDOMNode(value2)) {
|
|
615
|
+
if (value1 !== value2) return false
|
|
616
|
+
} else if (isObjectLike(value1) && isObjectLike(value2)) {
|
|
566
617
|
if (value1 !== value2) {
|
|
567
618
|
stack.push([value1, value2])
|
|
568
619
|
}
|
|
@@ -573,7 +624,7 @@ export const deepContains = (obj1, obj2, ignoredKeys = ['node', '__ref']) => {
|
|
|
573
624
|
}
|
|
574
625
|
|
|
575
626
|
return true
|
|
576
|
-
}
|
|
627
|
+
}
|
|
577
628
|
|
|
578
629
|
export const removeFromObject = (obj, props) => {
|
|
579
630
|
if (props === undefined || props === null) return obj
|
|
@@ -663,3 +714,43 @@ export const getExtendsInElement = (obj) => {
|
|
|
663
714
|
traverse(obj)
|
|
664
715
|
return result
|
|
665
716
|
}
|
|
717
|
+
|
|
718
|
+
export const createNestedObject = (arr, lastValue) => {
|
|
719
|
+
const nestedObject = {}
|
|
720
|
+
|
|
721
|
+
if (arr.length === 0) {
|
|
722
|
+
return lastValue
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
arr.reduce((obj, value, index) => {
|
|
726
|
+
if (!obj[value]) {
|
|
727
|
+
obj[value] = {}
|
|
728
|
+
}
|
|
729
|
+
if (index === arr.length - 1 && lastValue) {
|
|
730
|
+
obj[value] = lastValue
|
|
731
|
+
}
|
|
732
|
+
return obj[value]
|
|
733
|
+
}, nestedObject)
|
|
734
|
+
|
|
735
|
+
return nestedObject
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
export const removeNestedKeyByPath = (obj, path) => {
|
|
739
|
+
if (!Array.isArray(path)) {
|
|
740
|
+
throw new Error('Path must be an array.')
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
let current = obj
|
|
744
|
+
|
|
745
|
+
for (let i = 0; i < path.length - 1; i++) {
|
|
746
|
+
if (current[path[i]] === undefined) {
|
|
747
|
+
return // Path does not exist, so nothing to remove.
|
|
748
|
+
}
|
|
749
|
+
current = current[path[i]]
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
const lastKey = path[path.length - 1]
|
|
753
|
+
if (current && Object.hasOwnProperty.call(current, lastKey)) {
|
|
754
|
+
delete current[lastKey]
|
|
755
|
+
}
|
|
756
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domql/utils",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.119",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "index.js",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"build": "yarn build:cjs",
|
|
24
24
|
"prepublish": "rimraf -I dist && yarn build && yarn copy:package:cjs"
|
|
25
25
|
},
|
|
26
|
-
"gitHead": "
|
|
26
|
+
"gitHead": "930d02cd05b1fa9cbfe3da9b1eea3f1baafdab6b",
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@babel/core": "^7.12.0"
|
|
29
29
|
}
|