@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
- import { deepCloneWithExtend, deepMerge } from './object'
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, excludeFrom = []) => {
43
- return arr.reduce((a, c) => deepMerge(a, deepCloneWithExtend(c, excludeFrom), excludeFrom), {})
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) : deepCloneWithExtend(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
- deepCloneWithExtend,
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(deepCloneWithExtend(newChild))
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, excludeFrom = []) => {
71
- return arr.reduce((a, c) => (0, import_object.deepMerge)(a, (0, import_object.deepCloneWithExtend)(c, excludeFrom), excludeFrom), {});
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.deepCloneWithExtend)(obj);
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);
@@ -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__.deepCloneWithExtend)(newChild));
138
+ assignChild((0, import__.deepClone)(newChild));
139
139
  else {
140
140
  const isSugarChildElem = checkIfSugar(childElem, parent, key);
141
141
  if (isSugarChildElem)
@@ -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 deepCloneExclude = (obj, excludeFrom = []) => {
121
- if ((0, import_types.isArray)(obj)) {
122
- return obj.map((x) => deepCloneExclude(x, excludeFrom));
123
- }
124
- const o = {};
125
- for (const k in obj) {
126
- const hasOwnProperty2 = Object.prototype.hasOwnProperty.call(obj, k);
127
- if (!hasOwnProperty2 || excludeFrom.includes(k) || k.startsWith("__"))
128
- continue;
129
- let v = obj[k];
130
- if (k === "extend" && (0, import_types.isArray)(v)) {
131
- v = mergeArrayExclude(v, excludeFrom);
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
- if (visited.has(obj))
132
+ }
133
+ if (visited.has(obj)) {
149
134
  return visited.get(obj);
150
- const clone2 = (0, import_types.isArray)(obj) ? [] : {};
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) && !exclude.includes(key)) {
154
- const value = obj[key];
155
- if ((0, import_node.isDOMNode)(value)) {
156
- clone2[key] = value;
157
- } else if (key === "extend" && (0, import_types.isArray)(value)) {
158
- clone2[key] = (0, import_array.mergeArray)(value, exclude);
159
- } else if ((0, import_types.isObjectLike)(value)) {
160
- clone2[key] = deepClone(value, exclude, cleanUndefined, visited);
161
- } else {
162
- clone2[key] = value;
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
- visited.add(obj);
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
- const objProp = obj[prop];
180
- if (excludeFrom.includes(prop) || prop.startsWith("__") || options.cleanUndefined && (0, import_types.isUndefined)(objProp) || options.cleanNull && (0, import_types.isNull)(objProp)) {
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)(objProp)) {
184
- o[prop] = deepCloneWithExtend(objProp, excludeFrom, options, visited);
185
- } else if ((0, import_types.isFunction)(objProp) && options.window) {
186
- o[prop] = (options.window || import_globals.window).eval("(" + objProp.toString() + ")");
158
+ if ((0, import_types.isObjectLike)(value)) {
159
+ clone2[key] = deepClone(value, {
160
+ ...options,
161
+ visited
162
+ });
187
163
  } else {
188
- o[prop] = objProp;
164
+ clone2[key] = value;
189
165
  }
190
166
  }
191
- return o;
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 { deepCloneWithExtend, deepMerge } from "./object";
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, excludeFrom = []) => {
33
- return arr.reduce((a, c) => deepMerge(a, deepCloneWithExtend(c, excludeFrom), excludeFrom), {});
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) : deepCloneWithExtend(obj);
36
+ return isArray(obj) ? mergeArray(obj) : deepClone(obj);
37
37
  };
38
38
  const cutArrayBeforeValue = (arr, value) => {
39
39
  const index = arr.indexOf(value);
@@ -18,7 +18,7 @@ var __spreadValues = (a, b) => {
18
18
  };
19
19
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
20
  import {
21
- deepCloneWithExtend,
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(deepCloneWithExtend(newChild));
128
+ assignChild(deepClone(newChild));
129
129
  else {
130
130
  const isSugarChildElem = checkIfSugar(childElem, parent, key);
131
131
  if (isSugarChildElem)
@@ -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 deepCloneExclude = (obj, excludeFrom = []) => {
88
- if (isArray(obj)) {
89
- return obj.map((x) => deepCloneExclude(x, excludeFrom));
90
- }
91
- const o = {};
92
- for (const k in obj) {
93
- const hasOwnProperty2 = Object.prototype.hasOwnProperty.call(obj, k);
94
- if (!hasOwnProperty2 || excludeFrom.includes(k) || k.startsWith("__"))
95
- continue;
96
- let v = obj[k];
97
- if (k === "extend" && isArray(v)) {
98
- v = mergeArrayExclude(v, excludeFrom);
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
- if (visited.has(obj))
104
+ }
105
+ if (visited.has(obj)) {
116
106
  return visited.get(obj);
117
- const clone2 = isArray(obj) ? [] : {};
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) && !exclude.includes(key)) {
121
- const value = obj[key];
122
- if (isDOMNode(value)) {
123
- clone2[key] = value;
124
- } else if (key === "extend" && isArray(value)) {
125
- clone2[key] = mergeArray(value, exclude);
126
- } else if (isObjectLike(value)) {
127
- clone2[key] = deepClone(value, exclude, cleanUndefined, visited);
128
- } else {
129
- clone2[key] = value;
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
- visited.add(obj);
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
- const objProp = obj[prop];
147
- if (excludeFrom.includes(prop) || prop.startsWith("__") || options.cleanUndefined && isUndefined(objProp) || options.cleanNull && isNull(objProp)) {
125
+ }
126
+ if (isFunction(value) && targetWindow) {
127
+ clone2[key] = targetWindow.eval("(" + value.toString() + ")");
148
128
  continue;
149
129
  }
150
- if (isObjectLike(objProp)) {
151
- o[prop] = deepCloneWithExtend(objProp, excludeFrom, options, visited);
152
- } else if (isFunction(objProp) && options.window) {
153
- o[prop] = (options.window || window).eval("(" + objProp.toString() + ")");
130
+ if (isObjectLike(value)) {
131
+ clone2[key] = deepClone(value, __spreadProps(__spreadValues({}, options), {
132
+ visited
133
+ }));
154
134
  } else {
155
- o[prop] = objProp;
135
+ clone2[key] = value;
156
136
  }
157
137
  }
158
- return o;
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, excl = []) => {
106
- return arr.reduce((acc, curr) => deepMerge(acc, deepCloneExclude(curr, excl)), {})
78
+ export const mergeArrayExclude = (arr, exclude = []) => {
79
+ return arr.reduce((acc, curr) => deepMerge(acc, deepClone(curr, { exclude })), {})
107
80
  }
108
-
109
81
  /**
110
- * Deep cloning of object
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, exclude = [], cleanUndefined = false, visited = new WeakMap()) => {
113
- // Handle non-object types, null, and ignored types
114
- if (!isObjectLike(obj) || isDOMNode(obj)) return obj
115
-
116
- // Check for circular references
117
- if (visited.has(obj)) return visited.get(obj)
118
-
119
- // Create a new object or array
120
- const clone = isArray(obj) ? [] : {}
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
- // Store the clone in the WeakMap to handle circular references
123
- visited.set(obj, clone)
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
- return clone
144
- }
145
- // export const deepClone = (obj, excludeFrom = [], cleanUndefined = false) => {
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
- const o = options.window
113
+ // Create appropriate container based on type and window context
114
+ const clone = targetWindow
182
115
  ? isArray(obj)
183
- ? new options.window.Array([])
184
- : new options.window.Object({})
116
+ ? new targetWindow.Array()
117
+ : new targetWindow.Object()
185
118
  : isArray(obj)
186
119
  ? []
187
120
  : {}
188
121
 
189
- for (const prop in obj) {
190
- if (!Object.prototype.hasOwnProperty.call(obj, prop)) continue
122
+ // Store the clone to handle circular references
123
+ visited.set(obj, clone)
191
124
 
192
- const objProp = obj[prop]
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
- if (
195
- excludeFrom.includes(prop) ||
196
- prop.startsWith('__') ||
197
- (options.cleanUndefined && isUndefined(objProp)) ||
198
- (options.cleanNull && isNull(objProp))
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
- if (isObjectLike(objProp)) {
204
- o[prop] = deepCloneWithExtend(objProp, excludeFrom, options, visited)
205
- } else if (isFunction(objProp) && options.window) {
206
- o[prop] = (options.window || window).eval('(' + objProp.toString() + ')')
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
- o[prop] = objProp
162
+ clone[key] = value
209
163
  }
210
164
  }
211
165
 
212
- return o
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.159",
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": "7595b1077d3096c3ee7b1da5eef02aa9248f2ed6",
28
+ "gitHead": "39a7af3d77c6b0257d5e1a0d6110850926d83c19",
29
29
  "devDependencies": {
30
30
  "@babel/core": "^7.12.0"
31
31
  }