@domql/utils 2.5.159 → 2.5.161
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 +4 -4
- package/component.js +2 -2
- package/dist/cjs/array.js +3 -3
- package/dist/cjs/component.js +1 -1
- package/dist/cjs/object.js +39 -63
- package/dist/esm/array.js +4 -4
- package/dist/esm/component.js +2 -2
- package/dist/esm/object.js +41 -63
- package/object.js +67 -113
- package/package.json +2 -2
package/array.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { deepClone, deepMerge } from './object'
|
|
4
4
|
import { isArray, isNumber, isString } from './types'
|
|
5
5
|
|
|
6
6
|
export const arrayContainsOtherArray = (arr1, arr2) => {
|
|
@@ -39,15 +39,15 @@ export const joinArrays = (...arrays) => {
|
|
|
39
39
|
/**
|
|
40
40
|
* Merges array extendtypes
|
|
41
41
|
*/
|
|
42
|
-
export const mergeArray = (arr,
|
|
43
|
-
return arr.reduce((a, c) => deepMerge(a,
|
|
42
|
+
export const mergeArray = (arr, exclude = []) => {
|
|
43
|
+
return arr.reduce((a, c) => deepMerge(a, deepClone(c, { exclude }), exclude), {})
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
/**
|
|
47
47
|
* Merges array extends
|
|
48
48
|
*/
|
|
49
49
|
export const mergeAndCloneIfArray = obj => {
|
|
50
|
-
return isArray(obj) ? mergeArray(obj) :
|
|
50
|
+
return isArray(obj) ? mergeArray(obj) : deepClone(obj)
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
export const cutArrayBeforeValue = (arr, value) => {
|
package/component.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
|
-
|
|
4
|
+
deepClone,
|
|
5
5
|
exec,
|
|
6
6
|
isArray,
|
|
7
7
|
isFunction,
|
|
@@ -116,7 +116,7 @@ export const addChildrenIfNotInOriginal = (element, parent, key) => {
|
|
|
116
116
|
|
|
117
117
|
if (newChild?.ignoreExtend) continue
|
|
118
118
|
if (newChild === null) assignChild(null)
|
|
119
|
-
else if (!childElem) assignChild(
|
|
119
|
+
else if (!childElem) assignChild(deepClone(newChild))
|
|
120
120
|
else {
|
|
121
121
|
const isSugarChildElem = checkIfSugar(childElem, parent, key)
|
|
122
122
|
if (isSugarChildElem) continue
|
package/dist/cjs/array.js
CHANGED
|
@@ -67,11 +67,11 @@ const swapItemsInArray = (arr, i, j) => {
|
|
|
67
67
|
const joinArrays = (...arrays) => {
|
|
68
68
|
return [].concat(...arrays);
|
|
69
69
|
};
|
|
70
|
-
const mergeArray = (arr,
|
|
71
|
-
return arr.reduce((a, c) => (0, import_object.deepMerge)(a, (0, import_object.
|
|
70
|
+
const mergeArray = (arr, exclude = []) => {
|
|
71
|
+
return arr.reduce((a, c) => (0, import_object.deepMerge)(a, (0, import_object.deepClone)(c, { exclude }), exclude), {});
|
|
72
72
|
};
|
|
73
73
|
const mergeAndCloneIfArray = (obj) => {
|
|
74
|
-
return (0, import_types.isArray)(obj) ? mergeArray(obj) : (0, import_object.
|
|
74
|
+
return (0, import_types.isArray)(obj) ? mergeArray(obj) : (0, import_object.deepClone)(obj);
|
|
75
75
|
};
|
|
76
76
|
const cutArrayBeforeValue = (arr, value) => {
|
|
77
77
|
const index = arr.indexOf(value);
|
package/dist/cjs/component.js
CHANGED
|
@@ -135,7 +135,7 @@ const addChildrenIfNotInOriginal = (element, parent, key) => {
|
|
|
135
135
|
if (newChild === null)
|
|
136
136
|
assignChild(null);
|
|
137
137
|
else if (!childElem)
|
|
138
|
-
assignChild((0, import__.
|
|
138
|
+
assignChild((0, import__.deepClone)(newChild));
|
|
139
139
|
else {
|
|
140
140
|
const isSugarChildElem = checkIfSugar(childElem, parent, key);
|
|
141
141
|
if (isSugarChildElem)
|
package/dist/cjs/object.js
CHANGED
|
@@ -22,8 +22,6 @@ __export(object_exports, {
|
|
|
22
22
|
createNestedObject: () => createNestedObject,
|
|
23
23
|
createObjectWithoutPrototype: () => createObjectWithoutPrototype,
|
|
24
24
|
deepClone: () => deepClone,
|
|
25
|
-
deepCloneExclude: () => deepCloneExclude,
|
|
26
|
-
deepCloneWithExtend: () => deepCloneWithExtend,
|
|
27
25
|
deepContains: () => deepContains,
|
|
28
26
|
deepDestringify: () => deepDestringify,
|
|
29
27
|
deepDiff: () => deepDiff,
|
|
@@ -117,78 +115,56 @@ const clone = (obj, excludeFrom = []) => {
|
|
|
117
115
|
}
|
|
118
116
|
return o;
|
|
119
117
|
};
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
if ((0, import_types.isArray)(v)) {
|
|
134
|
-
o[k] = v.map((x) => deepCloneExclude(x, excludeFrom));
|
|
135
|
-
} else if ((0, import_types.isObject)(v)) {
|
|
136
|
-
o[k] = deepCloneExclude(v, excludeFrom);
|
|
137
|
-
} else
|
|
138
|
-
o[k] = v;
|
|
139
|
-
}
|
|
140
|
-
return o;
|
|
141
|
-
};
|
|
142
|
-
const mergeArrayExclude = (arr, excl = []) => {
|
|
143
|
-
return arr.reduce((acc, curr) => deepMerge(acc, deepCloneExclude(curr, excl)), {});
|
|
144
|
-
};
|
|
145
|
-
const deepClone = (obj, exclude = [], cleanUndefined = false, visited = /* @__PURE__ */ new WeakMap()) => {
|
|
146
|
-
if (!(0, import_types.isObjectLike)(obj) || (0, import_node.isDOMNode)(obj))
|
|
118
|
+
const mergeArrayExclude = (arr, exclude = []) => {
|
|
119
|
+
return arr.reduce((acc, curr) => deepMerge(acc, deepClone(curr, { exclude })), {});
|
|
120
|
+
};
|
|
121
|
+
const deepClone = (obj, options = {}) => {
|
|
122
|
+
const {
|
|
123
|
+
exclude = [],
|
|
124
|
+
cleanUndefined = false,
|
|
125
|
+
cleanNull = false,
|
|
126
|
+
window: targetWindow,
|
|
127
|
+
visited = /* @__PURE__ */ new WeakMap(),
|
|
128
|
+
handleExtend = false
|
|
129
|
+
} = options;
|
|
130
|
+
if (!(0, import_types.isObjectLike)(obj) || (0, import_node.isDOMNode)(obj)) {
|
|
147
131
|
return obj;
|
|
148
|
-
|
|
132
|
+
}
|
|
133
|
+
if (visited.has(obj)) {
|
|
149
134
|
return visited.get(obj);
|
|
150
|
-
|
|
135
|
+
}
|
|
136
|
+
const clone2 = targetWindow ? (0, import_types.isArray)(obj) ? new targetWindow.Array() : new targetWindow.Object() : (0, import_types.isArray)(obj) ? [] : {};
|
|
151
137
|
visited.set(obj, clone2);
|
|
152
138
|
for (const key in obj) {
|
|
153
|
-
if (Object.prototype.hasOwnProperty.call(obj, key)
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
return clone2;
|
|
167
|
-
};
|
|
168
|
-
const deepCloneWithExtend = (obj, excludeFrom = ["node"], options = {}, visited = /* @__PURE__ */ new WeakSet()) => {
|
|
169
|
-
if ((0, import_types.isObjectLike)(obj)) {
|
|
170
|
-
if (visited.has(obj)) {
|
|
171
|
-
return obj;
|
|
139
|
+
if (!Object.prototype.hasOwnProperty.call(obj, key))
|
|
140
|
+
continue;
|
|
141
|
+
if (exclude.includes(key) || key.startsWith("__") || key === "__proto__")
|
|
142
|
+
continue;
|
|
143
|
+
const value = obj[key];
|
|
144
|
+
if (cleanUndefined && (0, import_types.isUndefined)(value) || cleanNull && (0, import_types.isNull)(value))
|
|
145
|
+
continue;
|
|
146
|
+
if ((0, import_node.isDOMNode)(value)) {
|
|
147
|
+
clone2[key] = value;
|
|
148
|
+
continue;
|
|
172
149
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
const o = options.window ? (0, import_types.isArray)(obj) ? new options.window.Array([]) : new options.window.Object({}) : (0, import_types.isArray)(obj) ? [] : {};
|
|
176
|
-
for (const prop in obj) {
|
|
177
|
-
if (!Object.prototype.hasOwnProperty.call(obj, prop))
|
|
150
|
+
if (handleExtend && key === "extend" && (0, import_types.isArray)(value)) {
|
|
151
|
+
clone2[key] = (0, import_array.mergeArray)(value, exclude);
|
|
178
152
|
continue;
|
|
179
|
-
|
|
180
|
-
if (
|
|
153
|
+
}
|
|
154
|
+
if ((0, import_types.isFunction)(value) && targetWindow) {
|
|
155
|
+
clone2[key] = targetWindow.eval("(" + value.toString() + ")");
|
|
181
156
|
continue;
|
|
182
157
|
}
|
|
183
|
-
if ((0, import_types.isObjectLike)(
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
158
|
+
if ((0, import_types.isObjectLike)(value)) {
|
|
159
|
+
clone2[key] = deepClone(value, {
|
|
160
|
+
...options,
|
|
161
|
+
visited
|
|
162
|
+
});
|
|
187
163
|
} else {
|
|
188
|
-
|
|
164
|
+
clone2[key] = value;
|
|
189
165
|
}
|
|
190
166
|
}
|
|
191
|
-
return
|
|
167
|
+
return clone2;
|
|
192
168
|
};
|
|
193
169
|
const deepStringify = (obj, stringified = {}) => {
|
|
194
170
|
var _a, _b;
|
package/dist/esm/array.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { deepClone, deepMerge } from "./object";
|
|
2
2
|
import { isArray, isNumber, isString } from "./types";
|
|
3
3
|
const arrayContainsOtherArray = (arr1, arr2) => {
|
|
4
4
|
return arr2.every((val) => arr1.includes(val));
|
|
@@ -29,11 +29,11 @@ const swapItemsInArray = (arr, i, j) => {
|
|
|
29
29
|
const joinArrays = (...arrays) => {
|
|
30
30
|
return [].concat(...arrays);
|
|
31
31
|
};
|
|
32
|
-
const mergeArray = (arr,
|
|
33
|
-
return arr.reduce((a, c) => deepMerge(a,
|
|
32
|
+
const mergeArray = (arr, exclude = []) => {
|
|
33
|
+
return arr.reduce((a, c) => deepMerge(a, deepClone(c, { exclude }), exclude), {});
|
|
34
34
|
};
|
|
35
35
|
const mergeAndCloneIfArray = (obj) => {
|
|
36
|
-
return isArray(obj) ? mergeArray(obj) :
|
|
36
|
+
return isArray(obj) ? mergeArray(obj) : deepClone(obj);
|
|
37
37
|
};
|
|
38
38
|
const cutArrayBeforeValue = (arr, value) => {
|
|
39
39
|
const index = arr.indexOf(value);
|
package/dist/esm/component.js
CHANGED
|
@@ -18,7 +18,7 @@ var __spreadValues = (a, b) => {
|
|
|
18
18
|
};
|
|
19
19
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
20
|
import {
|
|
21
|
-
|
|
21
|
+
deepClone,
|
|
22
22
|
exec,
|
|
23
23
|
isArray,
|
|
24
24
|
isFunction,
|
|
@@ -125,7 +125,7 @@ const addChildrenIfNotInOriginal = (element, parent, key) => {
|
|
|
125
125
|
if (newChild === null)
|
|
126
126
|
assignChild(null);
|
|
127
127
|
else if (!childElem)
|
|
128
|
-
assignChild(
|
|
128
|
+
assignChild(deepClone(newChild));
|
|
129
129
|
else {
|
|
130
130
|
const isSugarChildElem = checkIfSugar(childElem, parent, key);
|
|
131
131
|
if (isSugarChildElem)
|
package/dist/esm/object.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
2
4
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
6
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
@@ -14,6 +16,7 @@ var __spreadValues = (a, b) => {
|
|
|
14
16
|
}
|
|
15
17
|
return a;
|
|
16
18
|
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
17
20
|
import { window } from "./globals.js";
|
|
18
21
|
import {
|
|
19
22
|
isFunction,
|
|
@@ -84,78 +87,55 @@ const clone = (obj, excludeFrom = []) => {
|
|
|
84
87
|
}
|
|
85
88
|
return o;
|
|
86
89
|
};
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
if (isArray(v)) {
|
|
101
|
-
o[k] = v.map((x) => deepCloneExclude(x, excludeFrom));
|
|
102
|
-
} else if (isObject(v)) {
|
|
103
|
-
o[k] = deepCloneExclude(v, excludeFrom);
|
|
104
|
-
} else
|
|
105
|
-
o[k] = v;
|
|
106
|
-
}
|
|
107
|
-
return o;
|
|
108
|
-
};
|
|
109
|
-
const mergeArrayExclude = (arr, excl = []) => {
|
|
110
|
-
return arr.reduce((acc, curr) => deepMerge(acc, deepCloneExclude(curr, excl)), {});
|
|
111
|
-
};
|
|
112
|
-
const deepClone = (obj, exclude = [], cleanUndefined = false, visited = /* @__PURE__ */ new WeakMap()) => {
|
|
113
|
-
if (!isObjectLike(obj) || isDOMNode(obj))
|
|
90
|
+
const mergeArrayExclude = (arr, exclude = []) => {
|
|
91
|
+
return arr.reduce((acc, curr) => deepMerge(acc, deepClone(curr, { exclude })), {});
|
|
92
|
+
};
|
|
93
|
+
const deepClone = (obj, options = {}) => {
|
|
94
|
+
const {
|
|
95
|
+
exclude = [],
|
|
96
|
+
cleanUndefined = false,
|
|
97
|
+
cleanNull = false,
|
|
98
|
+
window: targetWindow,
|
|
99
|
+
visited = /* @__PURE__ */ new WeakMap(),
|
|
100
|
+
handleExtend = false
|
|
101
|
+
} = options;
|
|
102
|
+
if (!isObjectLike(obj) || isDOMNode(obj)) {
|
|
114
103
|
return obj;
|
|
115
|
-
|
|
104
|
+
}
|
|
105
|
+
if (visited.has(obj)) {
|
|
116
106
|
return visited.get(obj);
|
|
117
|
-
|
|
107
|
+
}
|
|
108
|
+
const clone2 = targetWindow ? isArray(obj) ? new targetWindow.Array() : new targetWindow.Object() : isArray(obj) ? [] : {};
|
|
118
109
|
visited.set(obj, clone2);
|
|
119
110
|
for (const key in obj) {
|
|
120
|
-
if (Object.prototype.hasOwnProperty.call(obj, key)
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
return clone2;
|
|
134
|
-
};
|
|
135
|
-
const deepCloneWithExtend = (obj, excludeFrom = ["node"], options = {}, visited = /* @__PURE__ */ new WeakSet()) => {
|
|
136
|
-
if (isObjectLike(obj)) {
|
|
137
|
-
if (visited.has(obj)) {
|
|
138
|
-
return obj;
|
|
111
|
+
if (!Object.prototype.hasOwnProperty.call(obj, key))
|
|
112
|
+
continue;
|
|
113
|
+
if (exclude.includes(key) || key.startsWith("__") || key === "__proto__")
|
|
114
|
+
continue;
|
|
115
|
+
const value = obj[key];
|
|
116
|
+
if (cleanUndefined && isUndefined(value) || cleanNull && isNull(value))
|
|
117
|
+
continue;
|
|
118
|
+
if (isDOMNode(value)) {
|
|
119
|
+
clone2[key] = value;
|
|
120
|
+
continue;
|
|
139
121
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
const o = options.window ? isArray(obj) ? new options.window.Array([]) : new options.window.Object({}) : isArray(obj) ? [] : {};
|
|
143
|
-
for (const prop in obj) {
|
|
144
|
-
if (!Object.prototype.hasOwnProperty.call(obj, prop))
|
|
122
|
+
if (handleExtend && key === "extend" && isArray(value)) {
|
|
123
|
+
clone2[key] = mergeArray(value, exclude);
|
|
145
124
|
continue;
|
|
146
|
-
|
|
147
|
-
if (
|
|
125
|
+
}
|
|
126
|
+
if (isFunction(value) && targetWindow) {
|
|
127
|
+
clone2[key] = targetWindow.eval("(" + value.toString() + ")");
|
|
148
128
|
continue;
|
|
149
129
|
}
|
|
150
|
-
if (isObjectLike(
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
130
|
+
if (isObjectLike(value)) {
|
|
131
|
+
clone2[key] = deepClone(value, __spreadProps(__spreadValues({}, options), {
|
|
132
|
+
visited
|
|
133
|
+
}));
|
|
154
134
|
} else {
|
|
155
|
-
|
|
135
|
+
clone2[key] = value;
|
|
156
136
|
}
|
|
157
137
|
}
|
|
158
|
-
return
|
|
138
|
+
return clone2;
|
|
159
139
|
};
|
|
160
140
|
const deepStringify = (obj, stringified = {}) => {
|
|
161
141
|
var _a, _b;
|
|
@@ -651,8 +631,6 @@ export {
|
|
|
651
631
|
createNestedObject,
|
|
652
632
|
createObjectWithoutPrototype,
|
|
653
633
|
deepClone,
|
|
654
|
-
deepCloneExclude,
|
|
655
|
-
deepCloneWithExtend,
|
|
656
634
|
deepContains,
|
|
657
635
|
deepDestringify,
|
|
658
636
|
deepDiff,
|
package/object.js
CHANGED
|
@@ -74,142 +74,96 @@ export const clone = (obj, excludeFrom = []) => {
|
|
|
74
74
|
return o
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
// Clone anything deeply but excludeFrom keys given in 'excludeFrom'
|
|
78
|
-
export const deepCloneExclude = (obj, excludeFrom = []) => {
|
|
79
|
-
if (isArray(obj)) {
|
|
80
|
-
return obj.map(x => deepCloneExclude(x, excludeFrom))
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const o = {}
|
|
84
|
-
for (const k in obj) {
|
|
85
|
-
const hasOwnProperty = Object.prototype.hasOwnProperty.call(obj, k)
|
|
86
|
-
if (!hasOwnProperty || excludeFrom.includes(k) || k.startsWith('__')) continue
|
|
87
|
-
|
|
88
|
-
let v = obj[k]
|
|
89
|
-
|
|
90
|
-
if (k === 'extend' && isArray(v)) {
|
|
91
|
-
v = mergeArrayExclude(v, excludeFrom)
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
if (isArray(v)) {
|
|
95
|
-
o[k] = v.map(x => deepCloneExclude(x, excludeFrom))
|
|
96
|
-
} else if (isObject(v)) {
|
|
97
|
-
o[k] = deepCloneExclude(v, excludeFrom)
|
|
98
|
-
} else o[k] = v
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
return o
|
|
102
|
-
}
|
|
103
|
-
|
|
104
77
|
// Merge array, but exclude keys listed in 'excl'z
|
|
105
|
-
export const mergeArrayExclude = (arr,
|
|
106
|
-
return arr.reduce((acc, curr) => deepMerge(acc,
|
|
78
|
+
export const mergeArrayExclude = (arr, exclude = []) => {
|
|
79
|
+
return arr.reduce((acc, curr) => deepMerge(acc, deepClone(curr, { exclude })), {})
|
|
107
80
|
}
|
|
108
|
-
|
|
109
81
|
/**
|
|
110
|
-
*
|
|
82
|
+
* Enhanced deep clone function that combines features from multiple implementations
|
|
83
|
+
* @param {any} obj - Object to clone
|
|
84
|
+
* @param {Object} options - Configuration options
|
|
85
|
+
* @param {string[]} options.exclude - Properties to exclude from cloning
|
|
86
|
+
* @param {boolean} options.cleanUndefined - Remove undefined values
|
|
87
|
+
* @param {boolean} options.cleanNull - Remove null values
|
|
88
|
+
* @param {Window} options.window - Window object for cross-frame cloning
|
|
89
|
+
* @param {WeakMap} options.visited - WeakMap for tracking circular references
|
|
90
|
+
* @param {boolean} options.handleExtend - Whether to handle 'extend' arrays specially
|
|
91
|
+
* @returns {any} Cloned object
|
|
111
92
|
*/
|
|
112
|
-
export const deepClone = (obj,
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
93
|
+
export const deepClone = (obj, options = {}) => {
|
|
94
|
+
const {
|
|
95
|
+
exclude = [],
|
|
96
|
+
cleanUndefined = false,
|
|
97
|
+
cleanNull = false,
|
|
98
|
+
window: targetWindow,
|
|
99
|
+
visited = new WeakMap(),
|
|
100
|
+
handleExtend = false
|
|
101
|
+
} = options
|
|
121
102
|
|
|
122
|
-
//
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
// Iterate over the properties of the object
|
|
126
|
-
for (const key in obj) {
|
|
127
|
-
if (Object.prototype.hasOwnProperty.call(obj, key) && !exclude.includes(key)) {
|
|
128
|
-
const value = obj[key]
|
|
129
|
-
|
|
130
|
-
if (isDOMNode(value)) {
|
|
131
|
-
// Skip cloning for DOM nodes
|
|
132
|
-
clone[key] = value
|
|
133
|
-
} else if (key === 'extend' && isArray(value)) {
|
|
134
|
-
clone[key] = mergeArray(value, exclude)
|
|
135
|
-
} else if (isObjectLike(value)) {
|
|
136
|
-
clone[key] = deepClone(value, exclude, cleanUndefined, visited)
|
|
137
|
-
} else {
|
|
138
|
-
clone[key] = value
|
|
139
|
-
}
|
|
140
|
-
}
|
|
103
|
+
// Handle non-object types and special cases
|
|
104
|
+
if (!isObjectLike(obj) || isDOMNode(obj)) {
|
|
105
|
+
return obj
|
|
141
106
|
}
|
|
142
107
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
// const o = isArray(obj) ? [] : {}
|
|
147
|
-
// for (const prop in obj) {
|
|
148
|
-
// if (!Object.prototype.hasOwnProperty.call(obj, prop)) continue
|
|
149
|
-
// // if (prop === 'node' || prop === 'parent' || prop === 'root' || prop === '__element') {
|
|
150
|
-
// // console.warn('recursive clonning is called', obj)
|
|
151
|
-
// // continue
|
|
152
|
-
// // }
|
|
153
|
-
// if (prop === '__proto__') continue
|
|
154
|
-
// if (excludeFrom.includes(prop) || prop.startsWith('__')) continue
|
|
155
|
-
// let objProp = obj[prop]
|
|
156
|
-
// if (cleanUndefined && isUndefined(objProp)) continue
|
|
157
|
-
// if (prop === 'extend' && isArray(objProp)) {
|
|
158
|
-
// objProp = mergeArray(objProp)
|
|
159
|
-
// }
|
|
160
|
-
// if (isObjectLike(objProp)) {
|
|
161
|
-
// // queueMicrotask(() => {
|
|
162
|
-
// o[prop] = deepClone(objProp, excludeFrom, cleanUndefined)
|
|
163
|
-
// // })
|
|
164
|
-
// } else o[prop] = objProp
|
|
165
|
-
// }
|
|
166
|
-
// return o
|
|
167
|
-
// }
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Deep cloning of object
|
|
171
|
-
*/
|
|
172
|
-
export const deepCloneWithExtend = (obj, excludeFrom = ['node'], options = {}, visited = new WeakSet()) => {
|
|
173
|
-
// Check if the value is object-like before trying to track it in visited
|
|
174
|
-
if (isObjectLike(obj)) {
|
|
175
|
-
if (visited.has(obj)) {
|
|
176
|
-
return obj // Return the object if it was already cloned
|
|
177
|
-
}
|
|
178
|
-
visited.add(obj) // Add to visited set only if it's an object
|
|
108
|
+
// Handle circular references
|
|
109
|
+
if (visited.has(obj)) {
|
|
110
|
+
return visited.get(obj)
|
|
179
111
|
}
|
|
180
112
|
|
|
181
|
-
|
|
113
|
+
// Create appropriate container based on type and window context
|
|
114
|
+
const clone = targetWindow
|
|
182
115
|
? isArray(obj)
|
|
183
|
-
? new
|
|
184
|
-
: new
|
|
116
|
+
? new targetWindow.Array()
|
|
117
|
+
: new targetWindow.Object()
|
|
185
118
|
: isArray(obj)
|
|
186
119
|
? []
|
|
187
120
|
: {}
|
|
188
121
|
|
|
189
|
-
|
|
190
|
-
|
|
122
|
+
// Store the clone to handle circular references
|
|
123
|
+
visited.set(obj, clone)
|
|
191
124
|
|
|
192
|
-
|
|
125
|
+
// Clone properties
|
|
126
|
+
for (const key in obj) {
|
|
127
|
+
if (!Object.prototype.hasOwnProperty.call(obj, key)) continue
|
|
128
|
+
|
|
129
|
+
// Skip excluded properties
|
|
130
|
+
if (exclude.includes(key) || key.startsWith('__') || key === '__proto__') continue
|
|
193
131
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
132
|
+
const value = obj[key]
|
|
133
|
+
|
|
134
|
+
// Skip based on cleanup options
|
|
135
|
+
if ((cleanUndefined && isUndefined(value)) || (cleanNull && isNull(value))) continue
|
|
136
|
+
|
|
137
|
+
// Handle special cases
|
|
138
|
+
if (isDOMNode(value)) {
|
|
139
|
+
clone[key] = value
|
|
140
|
+
continue
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Handle 'extend' array if enabled
|
|
144
|
+
if (handleExtend && key === 'extend' && isArray(value)) {
|
|
145
|
+
clone[key] = mergeArray(value, exclude)
|
|
200
146
|
continue
|
|
201
147
|
}
|
|
202
148
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
149
|
+
// Handle functions in cross-frame scenario
|
|
150
|
+
if (isFunction(value) && targetWindow) {
|
|
151
|
+
clone[key] = targetWindow.eval('(' + value.toString() + ')')
|
|
152
|
+
continue
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Recursively clone objects
|
|
156
|
+
if (isObjectLike(value)) {
|
|
157
|
+
clone[key] = deepClone(value, {
|
|
158
|
+
...options,
|
|
159
|
+
visited
|
|
160
|
+
})
|
|
207
161
|
} else {
|
|
208
|
-
|
|
162
|
+
clone[key] = value
|
|
209
163
|
}
|
|
210
164
|
}
|
|
211
165
|
|
|
212
|
-
return
|
|
166
|
+
return clone
|
|
213
167
|
}
|
|
214
168
|
|
|
215
169
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domql/utils",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.161",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "index.js",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"build": "yarn build:cjs; yarn build:esm",
|
|
26
26
|
"prepublish": "rimraf -I dist; yarn build; yarn copy:package:cjs"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "39a7af3d77c6b0257d5e1a0d6110850926d83c19",
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@babel/core": "^7.12.0"
|
|
31
31
|
}
|