@domql/utils
Advanced tools
Comparing version 2.5.130 to 2.5.134
@@ -30,1 +30,6 @@ 'use strict' | ||
} | ||
export const removeCookie = (cname) => { | ||
if (isUndefined(document) || isUndefined(document.cookie)) return | ||
document.cookie = cname + '=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;' | ||
} |
@@ -23,2 +23,3 @@ "use strict"; | ||
isMobile: () => isMobile, | ||
removeCookie: () => removeCookie, | ||
setCookie: () => setCookie | ||
@@ -53,1 +54,6 @@ }); | ||
}; | ||
const removeCookie = (cname) => { | ||
if ((0, import_types.isUndefined)(import_utils.document) || (0, import_types.isUndefined)(import_utils.document.cookie)) | ||
return; | ||
import_utils.document.cookie = cname + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;"; | ||
}; |
@@ -32,2 +32,3 @@ "use strict"; | ||
deepStringify: () => deepStringify, | ||
deepStringifyWithMaxDepth: () => deepStringifyWithMaxDepth, | ||
detachFunctionsFromObject: () => detachFunctionsFromObject, | ||
@@ -183,2 +184,7 @@ detectInfiniteLoop: () => detectInfiniteLoop, | ||
const deepStringify = (obj, stringified = {}) => { | ||
var _a; | ||
if (obj.node || obj.__ref || obj.parent || obj.__element || obj.parse) { | ||
console.warn("Trying to clone element or state at", obj); | ||
obj = (_a = obj.parse) == null ? void 0 : _a.call(obj); | ||
} | ||
for (const prop in obj) { | ||
@@ -209,2 +215,35 @@ const objProp = obj[prop]; | ||
}; | ||
const MAX_DEPTH = 100; | ||
const deepStringifyWithMaxDepth = (obj, stringified = {}, depth = 0, path = "") => { | ||
if (depth > MAX_DEPTH) { | ||
console.warn(`Maximum depth exceeded at path: ${path}. Possible circular reference.`); | ||
return "[MAX_DEPTH_EXCEEDED]"; | ||
} | ||
for (const prop in obj) { | ||
const currentPath = path ? `${path}.${prop}` : prop; | ||
const objProp = obj[prop]; | ||
if ((0, import_types.isFunction)(objProp)) { | ||
stringified[prop] = objProp.toString(); | ||
} else if ((0, import_types.isObject)(objProp)) { | ||
stringified[prop] = {}; | ||
deepStringifyWithMaxDepth(objProp, stringified[prop], depth + 1, currentPath); | ||
} else if ((0, import_types.isArray)(objProp)) { | ||
stringified[prop] = []; | ||
objProp.forEach((v, i) => { | ||
const itemPath = `${currentPath}[${i}]`; | ||
if ((0, import_types.isObject)(v)) { | ||
stringified[prop][i] = {}; | ||
deepStringifyWithMaxDepth(v, stringified[prop][i], depth + 1, itemPath); | ||
} else if ((0, import_types.isFunction)(v)) { | ||
stringified[prop][i] = v.toString(); | ||
} else { | ||
stringified[prop][i] = v; | ||
} | ||
}); | ||
} else { | ||
stringified[prop] = objProp; | ||
} | ||
} | ||
return stringified; | ||
}; | ||
const objectToString = (obj = {}, indent = 0) => { | ||
@@ -211,0 +250,0 @@ const spaces = " ".repeat(indent); |
@@ -202,2 +202,7 @@ 'use strict' | ||
export const deepStringify = (obj, stringified = {}) => { | ||
if (obj.node || obj.__ref || obj.parent || obj.__element || obj.parse) { | ||
console.warn('Trying to clone element or state at', obj) | ||
obj = obj.parse?.() | ||
} | ||
for (const prop in obj) { | ||
@@ -229,2 +234,38 @@ const objProp = obj[prop] | ||
const MAX_DEPTH = 100 // Adjust this value as needed | ||
export const deepStringifyWithMaxDepth = (obj, stringified = {}, depth = 0, path = '') => { | ||
if (depth > MAX_DEPTH) { | ||
console.warn(`Maximum depth exceeded at path: ${path}. Possible circular reference.`) | ||
return '[MAX_DEPTH_EXCEEDED]' | ||
} | ||
for (const prop in obj) { | ||
const currentPath = path ? `${path}.${prop}` : prop | ||
const objProp = obj[prop] | ||
if (isFunction(objProp)) { | ||
stringified[prop] = objProp.toString() | ||
} else if (isObject(objProp)) { | ||
stringified[prop] = {} | ||
deepStringifyWithMaxDepth(objProp, stringified[prop], depth + 1, currentPath) | ||
} else if (isArray(objProp)) { | ||
stringified[prop] = [] | ||
objProp.forEach((v, i) => { | ||
const itemPath = `${currentPath}[${i}]` | ||
if (isObject(v)) { | ||
stringified[prop][i] = {} | ||
deepStringifyWithMaxDepth(v, stringified[prop][i], depth + 1, itemPath) | ||
} else if (isFunction(v)) { | ||
stringified[prop][i] = v.toString() | ||
} else { | ||
stringified[prop][i] = v | ||
} | ||
}) | ||
} else { | ||
stringified[prop] = objProp | ||
} | ||
} | ||
return stringified | ||
} | ||
export const objectToString = (obj = {}, indent = 0) => { | ||
@@ -231,0 +272,0 @@ const spaces = ' '.repeat(indent) |
{ | ||
"name": "@domql/utils", | ||
"version": "2.5.130", | ||
"version": "2.5.134", | ||
"license": "MIT", | ||
@@ -28,3 +28,3 @@ "type": "module", | ||
}, | ||
"gitHead": "88815c621b7aeb9458c779643934c0d2e5305cd2", | ||
"gitHead": "20e65426dc742448bd6dc85211dea3a48ed74ae0", | ||
"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
102939
3072