@domql/utils 2.5.119 → 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.
@@ -18,6 +18,7 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var function_exports = {};
20
20
  __export(function_exports, {
21
+ cloneFunction: () => cloneFunction,
21
22
  debounce: () => debounce,
22
23
  debounceOnContext: () => debounceOnContext,
23
24
  isStringFunction: () => isStringFunction,
@@ -67,3 +68,14 @@ const isStringFunction = (inputString) => {
67
68
  const functionRegex = /^((function\s*\([^)]*\)\s*\{[^}]*\})|(\([^)]*\)\s*=>))/;
68
69
  return functionRegex.test(inputString);
69
70
  };
71
+ function cloneFunction(fn, win = window) {
72
+ const temp = function() {
73
+ return fn.apply(win, arguments);
74
+ };
75
+ for (const key in fn) {
76
+ if (Object.hasOwnProperty.call(fn, key)) {
77
+ temp[key] = fn[key];
78
+ }
79
+ }
80
+ return temp;
81
+ }
@@ -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,6 +62,8 @@ 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");
65
+ var import_function = require("./function.js");
66
+ const ENV = "development";
64
67
  const exec = (param, element, state, context) => {
65
68
  if ((0, import_types.isFunction)(param)) {
66
69
  return param(
@@ -172,6 +175,8 @@ const deepCloneWithExtend = (obj, excludeFrom = ["node"], options = {}) => {
172
175
  continue;
173
176
  if ((0, import_types.isObjectLike)(objProp)) {
174
177
  o[prop] = deepCloneWithExtend(objProp, excludeFrom, options);
178
+ } else if ((0, import_types.isFunction)(objProp) && options.window) {
179
+ o[prop] = (0, import_function.cloneFunction)(objProp, options.window);
175
180
  } else
176
181
  o[prop] = objProp;
177
182
  }
@@ -619,3 +624,26 @@ const removeNestedKeyByPath = (obj, path) => {
619
624
  delete current[lastKey];
620
625
  }
621
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/function.js CHANGED
@@ -71,3 +71,17 @@ export const isStringFunction = inputString => {
71
71
  // Use the regex to test if the inputString matches the function pattern
72
72
  return functionRegex.test(inputString)
73
73
  }
74
+
75
+ export function cloneFunction (fn, win = window) {
76
+ const temp = function () {
77
+ return fn.apply(win, arguments)
78
+ }
79
+
80
+ // Copy properties from original function
81
+ for (const key in fn) {
82
+ if (Object.hasOwnProperty.call(fn, key)) {
83
+ temp[key] = fn[key]
84
+ }
85
+ }
86
+ return temp
87
+ }
package/object.js CHANGED
@@ -1,10 +1,23 @@
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'
18
+ import { cloneFunction } from './function.js'
19
+
20
+ const ENV = process.env.NODE_ENV
8
21
 
9
22
  export const exec = (param, element, state, context) => {
10
23
  if (isFunction(param)) {
@@ -176,6 +189,8 @@ export const deepCloneWithExtend = (obj, excludeFrom = ['node'], options = {}) =
176
189
  // queueMicrotask(() => {
177
190
  o[prop] = deepCloneWithExtend(objProp, excludeFrom, options)
178
191
  // })
192
+ } else if (isFunction(objProp) && options.window) {
193
+ o[prop] = cloneFunction(objProp, options.window)
179
194
  } else o[prop] = objProp
180
195
  }
181
196
  return o
@@ -754,3 +769,33 @@ export const removeNestedKeyByPath = (obj, path) => {
754
769
  delete current[lastKey]
755
770
  }
756
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.119",
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": "930d02cd05b1fa9cbfe3da9b1eea3f1baafdab6b",
26
+ "gitHead": "20b6bab140fa7d75aaac85afa237cd906c60e89c",
27
27
  "devDependencies": {
28
28
  "@babel/core": "^7.12.0"
29
29
  }