@domql/utils 2.5.123 → 2.5.125
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 +25 -0
- package/object.js +43 -1
- package/package.json +2 -2
package/dist/cjs/object.js
CHANGED
|
@@ -31,6 +31,7 @@ __export(object_exports, {
|
|
|
31
31
|
deepMerge: () => deepMerge,
|
|
32
32
|
deepStringify: () => deepStringify,
|
|
33
33
|
detachFunctionsFromObject: () => detachFunctionsFromObject,
|
|
34
|
+
detectInfiniteLoop: () => detectInfiniteLoop,
|
|
34
35
|
diff: () => diff,
|
|
35
36
|
diffArrays: () => diffArrays,
|
|
36
37
|
diffObjects: () => diffObjects,
|
|
@@ -62,6 +63,7 @@ var import_array = require("./array.js");
|
|
|
62
63
|
var import_string = require("./string.js");
|
|
63
64
|
var import_node = require("./node.js");
|
|
64
65
|
var import_function = require("./function.js");
|
|
66
|
+
const ENV = "development";
|
|
65
67
|
const exec = (param, element, state, context) => {
|
|
66
68
|
if ((0, import_types.isFunction)(param)) {
|
|
67
69
|
return param(
|
|
@@ -622,3 +624,26 @@ const removeNestedKeyByPath = (obj, path) => {
|
|
|
622
624
|
delete current[lastKey];
|
|
623
625
|
}
|
|
624
626
|
};
|
|
627
|
+
const detectInfiniteLoop = (arr) => {
|
|
628
|
+
const maxRepeats = 10;
|
|
629
|
+
let pattern = [];
|
|
630
|
+
let repeatCount = 0;
|
|
631
|
+
for (let i = 0; i < arr.length; i++) {
|
|
632
|
+
if (pattern.length < 2) {
|
|
633
|
+
pattern.push(arr[i]);
|
|
634
|
+
} else {
|
|
635
|
+
if (arr[i] === pattern[i % 2]) {
|
|
636
|
+
repeatCount++;
|
|
637
|
+
} else {
|
|
638
|
+
pattern = [arr[i - 1], arr[i]];
|
|
639
|
+
repeatCount = 1;
|
|
640
|
+
}
|
|
641
|
+
if (repeatCount >= maxRepeats * 2) {
|
|
642
|
+
if (ENV === "test" || ENV === "development") {
|
|
643
|
+
console.warn("Warning: Potential infinite loop detected due to repeated sequence:", pattern);
|
|
644
|
+
}
|
|
645
|
+
return true;
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
};
|
package/object.js
CHANGED
|
@@ -1,12 +1,24 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
import { window } from './globals.js'
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
isFunction,
|
|
6
|
+
isObjectLike,
|
|
7
|
+
isObject,
|
|
8
|
+
isArray,
|
|
9
|
+
isString,
|
|
10
|
+
is,
|
|
11
|
+
isUndefined,
|
|
12
|
+
isDate,
|
|
13
|
+
isNull
|
|
14
|
+
} from './types.js'
|
|
5
15
|
import { mergeAndCloneIfArray, mergeArray } from './array.js'
|
|
6
16
|
import { stringIncludesAny } from './string.js'
|
|
7
17
|
import { isDOMNode } from './node.js'
|
|
8
18
|
import { cloneFunction } from './function.js'
|
|
9
19
|
|
|
20
|
+
const ENV = process.env.NODE_ENV
|
|
21
|
+
|
|
10
22
|
export const exec = (param, element, state, context) => {
|
|
11
23
|
if (isFunction(param)) {
|
|
12
24
|
return param(
|
|
@@ -757,3 +769,33 @@ export const removeNestedKeyByPath = (obj, path) => {
|
|
|
757
769
|
delete current[lastKey]
|
|
758
770
|
}
|
|
759
771
|
}
|
|
772
|
+
|
|
773
|
+
export const detectInfiniteLoop = arr => {
|
|
774
|
+
const maxRepeats = 10 // Maximum allowed repetitions
|
|
775
|
+
let pattern = []
|
|
776
|
+
let repeatCount = 0
|
|
777
|
+
|
|
778
|
+
for (let i = 0; i < arr.length; i++) {
|
|
779
|
+
if (pattern.length < 2) {
|
|
780
|
+
// Build the initial pattern with two consecutive elements
|
|
781
|
+
pattern.push(arr[i])
|
|
782
|
+
} else {
|
|
783
|
+
// Check if the current element follows the repeating pattern
|
|
784
|
+
if (arr[i] === pattern[i % 2]) {
|
|
785
|
+
repeatCount++
|
|
786
|
+
} else {
|
|
787
|
+
// If there's a mismatch, reset the pattern and repeat counter
|
|
788
|
+
pattern = [arr[i - 1], arr[i]]
|
|
789
|
+
repeatCount = 1 // Reset to 1 because we start a new potential pattern
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
// If the pattern repeats more than `maxRepeats`, throw a warning
|
|
793
|
+
if (repeatCount >= maxRepeats * 2) {
|
|
794
|
+
if (ENV === 'test' || ENV === 'development') {
|
|
795
|
+
console.warn('Warning: Potential infinite loop detected due to repeated sequence:', pattern)
|
|
796
|
+
}
|
|
797
|
+
return true
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domql/utils",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.125",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "index.js",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"build": "yarn build:cjs",
|
|
24
24
|
"prepublish": "rimraf -I dist && yarn build && yarn copy:package:cjs"
|
|
25
25
|
},
|
|
26
|
-
"gitHead": "
|
|
26
|
+
"gitHead": "20b6bab140fa7d75aaac85afa237cd906c60e89c",
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@babel/core": "^7.12.0"
|
|
29
29
|
}
|