@domql/utils
Advanced tools
Comparing version 2.5.142 to 2.5.143
@@ -166,3 +166,9 @@ "use strict"; | ||
}; | ||
const deepCloneWithExtend = (obj, excludeFrom = ["node"], options = {}) => { | ||
const deepCloneWithExtend = (obj, excludeFrom = ["node"], options = {}, visited = /* @__PURE__ */ new WeakSet()) => { | ||
if ((0, import_types.isObjectLike)(obj)) { | ||
if (visited.has(obj)) { | ||
return obj; | ||
} | ||
visited.add(obj); | ||
} | ||
const o = options.window ? (0, import_types.isArray)(obj) ? new options.window.Array([]) : new options.window.Object({}) : (0, import_types.isArray)(obj) ? [] : {}; | ||
@@ -173,10 +179,12 @@ for (const prop in obj) { | ||
const objProp = obj[prop]; | ||
if (excludeFrom.includes(prop) || prop.startsWith("__") || options.cleanUndefined && (0, import_types.isUndefined)(objProp) || options.cleanNull && (0, import_types.isNull)(objProp)) | ||
if (excludeFrom.includes(prop) || prop.startsWith("__") || options.cleanUndefined && (0, import_types.isUndefined)(objProp) || options.cleanNull && (0, import_types.isNull)(objProp)) { | ||
continue; | ||
} | ||
if ((0, import_types.isObjectLike)(objProp)) { | ||
o[prop] = deepCloneWithExtend(objProp, excludeFrom, options); | ||
o[prop] = deepCloneWithExtend(objProp, excludeFrom, options, visited); | ||
} else if ((0, import_types.isFunction)(objProp) && options.window) { | ||
o[prop] = (options.window || import_globals.window).eval("(" + objProp.toString() + ")"); | ||
} else | ||
} else { | ||
o[prop] = objProp; | ||
} | ||
} | ||
@@ -183,0 +191,0 @@ return o; |
@@ -172,26 +172,42 @@ 'use strict' | ||
*/ | ||
export const deepCloneWithExtend = (obj, excludeFrom = ['node'], options = {}) => { | ||
export const deepCloneWithExtend = (obj, excludeFrom = ['node'], options = {}, visited = new WeakSet()) => { | ||
// Check if the value is object-like before trying to track it in visited | ||
if (isObjectLike(obj)) { | ||
if (visited.has(obj)) { | ||
return obj // Return the object if it was already cloned | ||
} | ||
visited.add(obj) // Add to visited set only if it's an object | ||
} | ||
const o = options.window | ||
? isArray(obj) ? new options.window.Array([]) : new options.window.Object({}) | ||
: isArray(obj) ? [] : {} | ||
? isArray(obj) | ||
? new options.window.Array([]) | ||
: new options.window.Object({}) | ||
: isArray(obj) | ||
? [] | ||
: {} | ||
for (const prop in obj) { | ||
if (!Object.prototype.hasOwnProperty.call(obj, prop)) continue | ||
// if (prop === 'node' || prop === 'parent' || prop === 'root' || prop === '__element') { | ||
// console.warn('recursive clonning is called', obj) | ||
// continue | ||
// } | ||
const objProp = obj[prop] | ||
if ( | ||
excludeFrom.includes(prop) || prop.startsWith('__') || | ||
excludeFrom.includes(prop) || | ||
prop.startsWith('__') || | ||
(options.cleanUndefined && isUndefined(objProp)) || | ||
(options.cleanNull && isNull(objProp)) | ||
) continue | ||
) { | ||
continue | ||
} | ||
if (isObjectLike(objProp)) { | ||
// queueMicrotask(() => { | ||
o[prop] = deepCloneWithExtend(objProp, excludeFrom, options) | ||
// }) | ||
o[prop] = deepCloneWithExtend(objProp, excludeFrom, options, visited) | ||
} else if (isFunction(objProp) && options.window) { | ||
o[prop] = (options.window || window).eval('(' + objProp.toString() + ')') | ||
} else o[prop] = objProp | ||
} else { | ||
o[prop] = objProp | ||
} | ||
} | ||
return o | ||
@@ -198,0 +214,0 @@ } |
{ | ||
"name": "@domql/utils", | ||
"version": "2.5.142", | ||
"version": "2.5.143", | ||
"license": "MIT", | ||
@@ -28,3 +28,3 @@ "type": "module", | ||
}, | ||
"gitHead": "65537c9b9a818948e1835b75a5c8a3e79bffdecd", | ||
"gitHead": "46440d5034244c18657bf272df1bdc3e8ff666c5", | ||
"devDependencies": { | ||
@@ -31,0 +31,0 @@ "@babel/core": "^7.12.0" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
107202
3203