@domql/utils 2.5.184 → 2.5.187
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 +27 -2
- package/dist/esm/object.js +27 -2
- package/object.js +37 -18
- package/package.json +4 -5
package/dist/cjs/object.js
CHANGED
|
@@ -37,6 +37,7 @@ __export(object_exports, {
|
|
|
37
37
|
exec: () => exec,
|
|
38
38
|
flattenRecursive: () => flattenRecursive,
|
|
39
39
|
getInObjectByPath: () => getInObjectByPath,
|
|
40
|
+
hasFunction: () => hasFunction,
|
|
40
41
|
hasOwnProperty: () => hasOwnProperty,
|
|
41
42
|
isCyclic: () => isCyclic,
|
|
42
43
|
isEmpty: () => isEmpty,
|
|
@@ -298,6 +299,30 @@ const detachFunctionsFromObject = (obj, detached = {}) => {
|
|
|
298
299
|
}
|
|
299
300
|
return detached;
|
|
300
301
|
};
|
|
302
|
+
const hasFunction = (str) => {
|
|
303
|
+
if (!str)
|
|
304
|
+
return false;
|
|
305
|
+
const trimmed = str.trim().replace(/\n\s*/g, " ").trim();
|
|
306
|
+
if (trimmed === "")
|
|
307
|
+
return false;
|
|
308
|
+
if (trimmed === "{}")
|
|
309
|
+
return false;
|
|
310
|
+
if (trimmed === "[]")
|
|
311
|
+
return false;
|
|
312
|
+
const patterns = [
|
|
313
|
+
/^\(\s*\{[^}]*\}\s*\)\s*=>/,
|
|
314
|
+
/^(\([^)]*\)|[^=]*)\s*=>/,
|
|
315
|
+
/^function[\s(]/,
|
|
316
|
+
/^async\s+/,
|
|
317
|
+
/^\(\s*function/,
|
|
318
|
+
/^[a-zA-Z_$][a-zA-Z0-9_$]*\s*=>/
|
|
319
|
+
];
|
|
320
|
+
const isFunction2 = patterns.some((pattern) => pattern.test(trimmed));
|
|
321
|
+
const isObjectLiteral = trimmed.startsWith("{") && !trimmed.includes("=>");
|
|
322
|
+
const isArrayLiteral = trimmed.startsWith("[");
|
|
323
|
+
const isJSONLike = /^["[{]/.test(trimmed) && !trimmed.includes("=>");
|
|
324
|
+
return isFunction2 && !isObjectLiteral && !isArrayLiteral && !isJSONLike;
|
|
325
|
+
};
|
|
301
326
|
const deepDestringify = (obj, destringified = {}) => {
|
|
302
327
|
for (const prop in obj) {
|
|
303
328
|
const hasOwnProperty2 = Object.prototype.hasOwnProperty.call(obj, prop);
|
|
@@ -305,7 +330,7 @@ const deepDestringify = (obj, destringified = {}) => {
|
|
|
305
330
|
continue;
|
|
306
331
|
const objProp = obj[prop];
|
|
307
332
|
if ((0, import_types.isString)(objProp)) {
|
|
308
|
-
if ((objProp
|
|
333
|
+
if (hasFunction(objProp)) {
|
|
309
334
|
try {
|
|
310
335
|
const evalProp = import_globals.window.eval(`(${objProp})`);
|
|
311
336
|
destringified[prop] = evalProp;
|
|
@@ -320,7 +345,7 @@ const deepDestringify = (obj, destringified = {}) => {
|
|
|
320
345
|
destringified[prop] = [];
|
|
321
346
|
objProp.forEach((arrProp) => {
|
|
322
347
|
if ((0, import_types.isString)(arrProp)) {
|
|
323
|
-
if (
|
|
348
|
+
if (hasFunction(arrProp)) {
|
|
324
349
|
try {
|
|
325
350
|
const evalProp = import_globals.window.eval(`(${arrProp})`);
|
|
326
351
|
destringified[prop].push(evalProp);
|
package/dist/esm/object.js
CHANGED
|
@@ -267,6 +267,30 @@ const detachFunctionsFromObject = (obj, detached = {}) => {
|
|
|
267
267
|
}
|
|
268
268
|
return detached;
|
|
269
269
|
};
|
|
270
|
+
const hasFunction = (str) => {
|
|
271
|
+
if (!str)
|
|
272
|
+
return false;
|
|
273
|
+
const trimmed = str.trim().replace(/\n\s*/g, " ").trim();
|
|
274
|
+
if (trimmed === "")
|
|
275
|
+
return false;
|
|
276
|
+
if (trimmed === "{}")
|
|
277
|
+
return false;
|
|
278
|
+
if (trimmed === "[]")
|
|
279
|
+
return false;
|
|
280
|
+
const patterns = [
|
|
281
|
+
/^\(\s*\{[^}]*\}\s*\)\s*=>/,
|
|
282
|
+
/^(\([^)]*\)|[^=]*)\s*=>/,
|
|
283
|
+
/^function[\s(]/,
|
|
284
|
+
/^async\s+/,
|
|
285
|
+
/^\(\s*function/,
|
|
286
|
+
/^[a-zA-Z_$][a-zA-Z0-9_$]*\s*=>/
|
|
287
|
+
];
|
|
288
|
+
const isFunction2 = patterns.some((pattern) => pattern.test(trimmed));
|
|
289
|
+
const isObjectLiteral = trimmed.startsWith("{") && !trimmed.includes("=>");
|
|
290
|
+
const isArrayLiteral = trimmed.startsWith("[");
|
|
291
|
+
const isJSONLike = /^["[{]/.test(trimmed) && !trimmed.includes("=>");
|
|
292
|
+
return isFunction2 && !isObjectLiteral && !isArrayLiteral && !isJSONLike;
|
|
293
|
+
};
|
|
270
294
|
const deepDestringify = (obj, destringified = {}) => {
|
|
271
295
|
for (const prop in obj) {
|
|
272
296
|
const hasOwnProperty2 = Object.prototype.hasOwnProperty.call(obj, prop);
|
|
@@ -274,7 +298,7 @@ const deepDestringify = (obj, destringified = {}) => {
|
|
|
274
298
|
continue;
|
|
275
299
|
const objProp = obj[prop];
|
|
276
300
|
if (isString(objProp)) {
|
|
277
|
-
if ((objProp
|
|
301
|
+
if (hasFunction(objProp)) {
|
|
278
302
|
try {
|
|
279
303
|
const evalProp = window.eval(`(${objProp})`);
|
|
280
304
|
destringified[prop] = evalProp;
|
|
@@ -289,7 +313,7 @@ const deepDestringify = (obj, destringified = {}) => {
|
|
|
289
313
|
destringified[prop] = [];
|
|
290
314
|
objProp.forEach((arrProp) => {
|
|
291
315
|
if (isString(arrProp)) {
|
|
292
|
-
if (
|
|
316
|
+
if (hasFunction(arrProp)) {
|
|
293
317
|
try {
|
|
294
318
|
const evalProp = window.eval(`(${arrProp})`);
|
|
295
319
|
destringified[prop].push(evalProp);
|
|
@@ -680,6 +704,7 @@ export {
|
|
|
680
704
|
exec,
|
|
681
705
|
flattenRecursive,
|
|
682
706
|
getInObjectByPath,
|
|
707
|
+
hasFunction,
|
|
683
708
|
hasOwnProperty,
|
|
684
709
|
isCyclic,
|
|
685
710
|
isEmpty,
|
package/object.js
CHANGED
|
@@ -311,30 +311,47 @@ export const detachFunctionsFromObject = (obj, detached = {}) => {
|
|
|
311
311
|
return detached
|
|
312
312
|
}
|
|
313
313
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
314
|
+
export const hasFunction = (str) => {
|
|
315
|
+
if (!str) return false
|
|
316
|
+
|
|
317
|
+
const trimmed = str.trim().replace(/\n\s*/g, ' ').trim()
|
|
318
|
+
|
|
319
|
+
if (trimmed === '') return false
|
|
320
|
+
if (trimmed === '{}') return false
|
|
321
|
+
if (trimmed === '[]') return false
|
|
322
|
+
|
|
323
|
+
const patterns = [
|
|
324
|
+
/^\(\s*\{[^}]*\}\s*\)\s*=>/,
|
|
325
|
+
/^(\([^)]*\)|[^=]*)\s*=>/,
|
|
326
|
+
/^function[\s(]/,
|
|
327
|
+
/^async\s+/,
|
|
328
|
+
/^\(\s*function/,
|
|
329
|
+
/^[a-zA-Z_$][a-zA-Z0-9_$]*\s*=>/
|
|
330
|
+
]
|
|
331
|
+
|
|
332
|
+
const isFunction = patterns.some(pattern => pattern.test(trimmed))
|
|
333
|
+
const isObjectLiteral = trimmed.startsWith('{') && !trimmed.includes('=>')
|
|
334
|
+
const isArrayLiteral = trimmed.startsWith('[')
|
|
335
|
+
const isJSONLike = /^["[{]/.test(trimmed) && !trimmed.includes('=>')
|
|
336
|
+
|
|
337
|
+
return isFunction && !isObjectLiteral && !isArrayLiteral && !isJSONLike
|
|
338
|
+
}
|
|
339
|
+
|
|
317
340
|
export const deepDestringify = (obj, destringified = {}) => {
|
|
318
341
|
for (const prop in obj) {
|
|
319
342
|
const hasOwnProperty = Object.prototype.hasOwnProperty.call(obj, prop)
|
|
320
343
|
if (!hasOwnProperty) continue
|
|
344
|
+
|
|
321
345
|
const objProp = obj[prop]
|
|
346
|
+
|
|
322
347
|
if (isString(objProp)) {
|
|
323
|
-
if ((
|
|
324
|
-
objProp.includes('(){') ||
|
|
325
|
-
objProp.includes('() {') ||
|
|
326
|
-
objProp.includes('=>') ||
|
|
327
|
-
objProp.startsWith('()') ||
|
|
328
|
-
objProp.startsWith('async') ||
|
|
329
|
-
objProp.startsWith('function') ||
|
|
330
|
-
objProp.startsWith('(')
|
|
331
|
-
) &&
|
|
332
|
-
!objProp.startsWith('{') && !objProp.startsWith('[')
|
|
333
|
-
) {
|
|
348
|
+
if (hasFunction(objProp)) {
|
|
334
349
|
try {
|
|
335
350
|
const evalProp = window.eval(`(${objProp})`)
|
|
336
351
|
destringified[prop] = evalProp
|
|
337
|
-
} catch (e) {
|
|
352
|
+
} catch (e) {
|
|
353
|
+
if (e) destringified[prop] = objProp
|
|
354
|
+
}
|
|
338
355
|
} else {
|
|
339
356
|
destringified[prop] = objProp
|
|
340
357
|
}
|
|
@@ -342,11 +359,13 @@ export const deepDestringify = (obj, destringified = {}) => {
|
|
|
342
359
|
destringified[prop] = []
|
|
343
360
|
objProp.forEach((arrProp) => {
|
|
344
361
|
if (isString(arrProp)) {
|
|
345
|
-
if (
|
|
362
|
+
if (hasFunction(arrProp)) {
|
|
346
363
|
try {
|
|
347
|
-
const evalProp = window.eval(`(${arrProp})`)
|
|
364
|
+
const evalProp = window.eval(`(${arrProp})`)
|
|
348
365
|
destringified[prop].push(evalProp)
|
|
349
|
-
} catch (e) {
|
|
366
|
+
} catch (e) {
|
|
367
|
+
if (e) destringified[prop].push(arrProp)
|
|
368
|
+
}
|
|
350
369
|
} else {
|
|
351
370
|
destringified[prop].push(arrProp)
|
|
352
371
|
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domql/utils",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.187",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "index.js",
|
|
7
7
|
"main": "index.js",
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
10
|
-
"kalduna": "./dist/esm/index.js",
|
|
11
10
|
"default": "./dist/esm/index.js",
|
|
12
11
|
"import": "./dist/esm/index.js",
|
|
13
12
|
"require": "./dist/cjs/index.js"
|
|
@@ -22,10 +21,10 @@
|
|
|
22
21
|
"copy:package:cjs": "cp ../../build/package-cjs.json dist/cjs/package.json",
|
|
23
22
|
"build:esm": "npx esbuild *.js --target=es2017 --format=esm --outdir=dist/esm",
|
|
24
23
|
"build:cjs": "npx esbuild *.js --target=node16 --format=cjs --outdir=dist/cjs",
|
|
25
|
-
"build": "npm run build:cjs; npm run build:esm",
|
|
26
|
-
"prepublish": "
|
|
24
|
+
"build": "rimraf -I dist; npm run build:cjs; npm run build:esm",
|
|
25
|
+
"prepublish": "npm run build; npm run copy:package:cjs"
|
|
27
26
|
},
|
|
28
|
-
"gitHead": "
|
|
27
|
+
"gitHead": "c150bfbbdd51b19d25c93f10334d54175cea9d1d",
|
|
29
28
|
"devDependencies": {
|
|
30
29
|
"@babel/core": "^7.12.0"
|
|
31
30
|
}
|