@domql/utils 2.5.123 → 2.5.126

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.
@@ -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,
@@ -61,7 +62,7 @@ var import_types = require("./types.js");
61
62
  var import_array = require("./array.js");
62
63
  var import_string = require("./string.js");
63
64
  var import_node = require("./node.js");
64
- var import_function = require("./function.js");
65
+ const ENV = "development";
65
66
  const exec = (param, element, state, context) => {
66
67
  if ((0, import_types.isFunction)(param)) {
67
68
  return param(
@@ -174,7 +175,7 @@ const deepCloneWithExtend = (obj, excludeFrom = ["node"], options = {}) => {
174
175
  if ((0, import_types.isObjectLike)(objProp)) {
175
176
  o[prop] = deepCloneWithExtend(objProp, excludeFrom, options);
176
177
  } else if ((0, import_types.isFunction)(objProp) && options.window) {
177
- o[prop] = (0, import_function.cloneFunction)(objProp, options.window);
178
+ o[prop] = (options.window || import_globals.window).eval("(" + objProp.toString() + ")");
178
179
  } else
179
180
  o[prop] = objProp;
180
181
  }
@@ -622,3 +623,26 @@ const removeNestedKeyByPath = (obj, path) => {
622
623
  delete current[lastKey];
623
624
  }
624
625
  };
626
+ const detectInfiniteLoop = (arr) => {
627
+ const maxRepeats = 10;
628
+ let pattern = [];
629
+ let repeatCount = 0;
630
+ for (let i = 0; i < arr.length; i++) {
631
+ if (pattern.length < 2) {
632
+ pattern.push(arr[i]);
633
+ } else {
634
+ if (arr[i] === pattern[i % 2]) {
635
+ repeatCount++;
636
+ } else {
637
+ pattern = [arr[i - 1], arr[i]];
638
+ repeatCount = 1;
639
+ }
640
+ if (repeatCount >= maxRepeats * 2) {
641
+ if (ENV === "test" || ENV === "development") {
642
+ console.warn("Warning: Potential infinite loop detected due to repeated sequence:", pattern);
643
+ }
644
+ return true;
645
+ }
646
+ }
647
+ }
648
+ };
package/object.js CHANGED
@@ -1,11 +1,22 @@
1
1
  'use strict'
2
2
 
3
3
  import { window } from './globals.js'
4
- import { isFunction, isObjectLike, isObject, isArray, isString, is, isUndefined, isDate, isNull } from './types.js'
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
- import { cloneFunction } from './function.js'
18
+
19
+ const ENV = process.env.NODE_ENV
9
20
 
10
21
  export const exec = (param, element, state, context) => {
11
22
  if (isFunction(param)) {
@@ -178,7 +189,7 @@ export const deepCloneWithExtend = (obj, excludeFrom = ['node'], options = {}) =
178
189
  o[prop] = deepCloneWithExtend(objProp, excludeFrom, options)
179
190
  // })
180
191
  } else if (isFunction(objProp) && options.window) {
181
- o[prop] = cloneFunction(objProp, options.window)
192
+ o[prop] = (options.window || window).eval('(' + objProp.toString() + ')')
182
193
  } else o[prop] = objProp
183
194
  }
184
195
  return o
@@ -757,3 +768,33 @@ export const removeNestedKeyByPath = (obj, path) => {
757
768
  delete current[lastKey]
758
769
  }
759
770
  }
771
+
772
+ export const detectInfiniteLoop = arr => {
773
+ const maxRepeats = 10 // Maximum allowed repetitions
774
+ let pattern = []
775
+ let repeatCount = 0
776
+
777
+ for (let i = 0; i < arr.length; i++) {
778
+ if (pattern.length < 2) {
779
+ // Build the initial pattern with two consecutive elements
780
+ pattern.push(arr[i])
781
+ } else {
782
+ // Check if the current element follows the repeating pattern
783
+ if (arr[i] === pattern[i % 2]) {
784
+ repeatCount++
785
+ } else {
786
+ // If there's a mismatch, reset the pattern and repeat counter
787
+ pattern = [arr[i - 1], arr[i]]
788
+ repeatCount = 1 // Reset to 1 because we start a new potential pattern
789
+ }
790
+
791
+ // If the pattern repeats more than `maxRepeats`, throw a warning
792
+ if (repeatCount >= maxRepeats * 2) {
793
+ if (ENV === 'test' || ENV === 'development') {
794
+ console.warn('Warning: Potential infinite loop detected due to repeated sequence:', pattern)
795
+ }
796
+ return true
797
+ }
798
+ }
799
+ }
800
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domql/utils",
3
- "version": "2.5.123",
3
+ "version": "2.5.126",
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": "6dd041deb89bc2ebfa1f5ee9360d563df60eca13",
26
+ "gitHead": "e1ba05fba6c04b2379905d5e05d3d4fe17cb0978",
27
27
  "devDependencies": {
28
28
  "@babel/core": "^7.12.0"
29
29
  }