@domql/utils 2.5.141 → 2.5.143
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/dist/cjs/object.js +14 -5
- package/object.js +31 -14
- package/package.json +2 -2
package/dist/cjs/object.js
CHANGED
|
@@ -63,7 +63,8 @@ var import_node = require("./node.js");
|
|
|
63
63
|
const ENV = "development";
|
|
64
64
|
const exec = (param, element, state, context) => {
|
|
65
65
|
if ((0, import_types.isFunction)(param)) {
|
|
66
|
-
return param(
|
|
66
|
+
return param.call(
|
|
67
|
+
element,
|
|
67
68
|
element,
|
|
68
69
|
state || element.state,
|
|
69
70
|
context || element.context
|
|
@@ -162,20 +163,28 @@ const deepClone = (obj, exclude = [], cleanUndefined = false, visited = /* @__PU
|
|
|
162
163
|
}
|
|
163
164
|
return clone2;
|
|
164
165
|
};
|
|
165
|
-
const deepCloneWithExtend = (obj, excludeFrom = ["node"], options = {}) => {
|
|
166
|
+
const deepCloneWithExtend = (obj, excludeFrom = ["node"], options = {}, visited = /* @__PURE__ */ new WeakSet()) => {
|
|
167
|
+
if ((0, import_types.isObjectLike)(obj)) {
|
|
168
|
+
if (visited.has(obj)) {
|
|
169
|
+
return obj;
|
|
170
|
+
}
|
|
171
|
+
visited.add(obj);
|
|
172
|
+
}
|
|
166
173
|
const o = options.window ? (0, import_types.isArray)(obj) ? new options.window.Array([]) : new options.window.Object({}) : (0, import_types.isArray)(obj) ? [] : {};
|
|
167
174
|
for (const prop in obj) {
|
|
168
175
|
if (!Object.prototype.hasOwnProperty.call(obj, prop))
|
|
169
176
|
continue;
|
|
170
177
|
const objProp = obj[prop];
|
|
171
|
-
if (excludeFrom.includes(prop) || prop.startsWith("__") || options.cleanUndefined && (0, import_types.isUndefined)(objProp) || options.cleanNull && (0, import_types.isNull)(objProp))
|
|
178
|
+
if (excludeFrom.includes(prop) || prop.startsWith("__") || options.cleanUndefined && (0, import_types.isUndefined)(objProp) || options.cleanNull && (0, import_types.isNull)(objProp)) {
|
|
172
179
|
continue;
|
|
180
|
+
}
|
|
173
181
|
if ((0, import_types.isObjectLike)(objProp)) {
|
|
174
|
-
o[prop] = deepCloneWithExtend(objProp, excludeFrom, options);
|
|
182
|
+
o[prop] = deepCloneWithExtend(objProp, excludeFrom, options, visited);
|
|
175
183
|
} else if ((0, import_types.isFunction)(objProp) && options.window) {
|
|
176
184
|
o[prop] = (options.window || import_globals.window).eval("(" + objProp.toString() + ")");
|
|
177
|
-
} else
|
|
185
|
+
} else {
|
|
178
186
|
o[prop] = objProp;
|
|
187
|
+
}
|
|
179
188
|
}
|
|
180
189
|
return o;
|
|
181
190
|
};
|
package/object.js
CHANGED
|
@@ -20,7 +20,8 @@ const ENV = process.env.NODE_ENV
|
|
|
20
20
|
|
|
21
21
|
export const exec = (param, element, state, context) => {
|
|
22
22
|
if (isFunction(param)) {
|
|
23
|
-
return param(
|
|
23
|
+
return param.call(
|
|
24
|
+
element,
|
|
24
25
|
element,
|
|
25
26
|
state || element.state,
|
|
26
27
|
context || element.context
|
|
@@ -168,30 +169,46 @@ export const deepClone = (obj, exclude = [], cleanUndefined = false, visited = n
|
|
|
168
169
|
/**
|
|
169
170
|
* Deep cloning of object
|
|
170
171
|
*/
|
|
171
|
-
export const deepCloneWithExtend = (obj, excludeFrom = ['node'], options = {}) => {
|
|
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
|
|
179
|
+
}
|
|
180
|
+
|
|
172
181
|
const o = options.window
|
|
173
|
-
? isArray(obj)
|
|
174
|
-
|
|
182
|
+
? isArray(obj)
|
|
183
|
+
? new options.window.Array([])
|
|
184
|
+
: new options.window.Object({})
|
|
185
|
+
: isArray(obj)
|
|
186
|
+
? []
|
|
187
|
+
: {}
|
|
188
|
+
|
|
175
189
|
for (const prop in obj) {
|
|
176
190
|
if (!Object.prototype.hasOwnProperty.call(obj, prop)) continue
|
|
177
|
-
|
|
178
|
-
// console.warn('recursive clonning is called', obj)
|
|
179
|
-
// continue
|
|
180
|
-
// }
|
|
191
|
+
|
|
181
192
|
const objProp = obj[prop]
|
|
193
|
+
|
|
182
194
|
if (
|
|
183
|
-
excludeFrom.includes(prop) ||
|
|
195
|
+
excludeFrom.includes(prop) ||
|
|
196
|
+
prop.startsWith('__') ||
|
|
184
197
|
(options.cleanUndefined && isUndefined(objProp)) ||
|
|
185
198
|
(options.cleanNull && isNull(objProp))
|
|
186
|
-
)
|
|
199
|
+
) {
|
|
200
|
+
continue
|
|
201
|
+
}
|
|
202
|
+
|
|
187
203
|
if (isObjectLike(objProp)) {
|
|
188
|
-
|
|
189
|
-
o[prop] = deepCloneWithExtend(objProp, excludeFrom, options)
|
|
190
|
-
// })
|
|
204
|
+
o[prop] = deepCloneWithExtend(objProp, excludeFrom, options, visited)
|
|
191
205
|
} else if (isFunction(objProp) && options.window) {
|
|
192
206
|
o[prop] = (options.window || window).eval('(' + objProp.toString() + ')')
|
|
193
|
-
} else
|
|
207
|
+
} else {
|
|
208
|
+
o[prop] = objProp
|
|
209
|
+
}
|
|
194
210
|
}
|
|
211
|
+
|
|
195
212
|
return o
|
|
196
213
|
}
|
|
197
214
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domql/utils",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.143",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "index.js",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"build": "yarn build:cjs",
|
|
26
26
|
"prepublish": "rimraf -I dist && yarn build && yarn copy:package:cjs"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "46440d5034244c18657bf272df1bdc3e8ff666c5",
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@babel/core": "^7.12.0"
|
|
31
31
|
}
|