@domql/utils 2.4.7 → 2.5.13

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.
@@ -19,6 +19,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  var function_exports = {};
20
20
  __export(function_exports, {
21
21
  debounce: () => debounce,
22
+ isStringFunction: () => isStringFunction,
22
23
  memoize: () => memoize
23
24
  });
24
25
  module.exports = __toCommonJS(function_exports);
@@ -44,3 +45,7 @@ const memoize = (fn) => {
44
45
  }
45
46
  };
46
47
  };
48
+ const isStringFunction = (inputString) => {
49
+ const functionRegex = /^((function\s*\([^)]*\)\s*\{[^}]*\})|(\([^)]*\)\s*=>))/;
50
+ return functionRegex.test(inputString);
51
+ };
package/dist/cjs/key.js CHANGED
@@ -18,11 +18,11 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var key_exports = {};
20
20
  __export(key_exports, {
21
- createKey: () => createKey,
22
- createSnapshotId: () => createSnapshotId
21
+ createSnapshotId: () => createSnapshotId,
22
+ generateKey: () => generateKey
23
23
  });
24
24
  module.exports = __toCommonJS(key_exports);
25
- const createKey = function() {
25
+ const generateKey = function() {
26
26
  let index = 0;
27
27
  function newId() {
28
28
  index++;
@@ -30,4 +30,4 @@ const createKey = function() {
30
30
  }
31
31
  return newId;
32
32
  }();
33
- const createSnapshotId = createKey;
33
+ const createSnapshotId = generateKey;
@@ -380,22 +380,28 @@ const flattenRecursive = (param, prop, stack = []) => {
380
380
  delete objectized[prop];
381
381
  return stack;
382
382
  };
383
- const isEqualDeep = (param, element) => {
384
- if (param === element)
383
+ const isEqualDeep = (param, element, visited = /* @__PURE__ */ new Set()) => {
384
+ if (typeof param !== "object" || typeof element !== "object" || param === null || element === null) {
385
+ return param === element;
386
+ }
387
+ if (visited.has(param) || visited.has(element)) {
385
388
  return true;
386
- if (!param || !element)
389
+ }
390
+ visited.add(param);
391
+ visited.add(element);
392
+ const keysParam = Object.keys(param);
393
+ const keysElement = Object.keys(element);
394
+ if (keysParam.length !== keysElement.length) {
387
395
  return false;
388
- for (const prop in param) {
389
- const paramProp = param[prop];
390
- const elementProp = element[prop];
391
- if ((0, import_types.isObjectLike)(paramProp)) {
392
- const isEqual = isEqualDeep(paramProp, elementProp);
393
- if (!isEqual)
394
- return false;
395
- } else {
396
- const isEqual = paramProp === elementProp;
397
- if (!isEqual)
398
- return false;
396
+ }
397
+ for (const key of keysParam) {
398
+ if (!keysElement.includes(key)) {
399
+ return false;
400
+ }
401
+ const paramProp = param[key];
402
+ const elementProp = element[key];
403
+ if (!isEqualDeep(paramProp, elementProp, visited)) {
404
+ return false;
399
405
  }
400
406
  }
401
407
  return true;
package/function.js CHANGED
@@ -21,3 +21,11 @@ export const memoize = (fn) => {
21
21
  }
22
22
  }
23
23
  }
24
+
25
+ export const isStringFunction = inputString => {
26
+ // Regular expression to match both regular and arrow function declarations
27
+ const functionRegex = /^((function\s*\([^)]*\)\s*\{[^}]*\})|(\([^)]*\)\s*=>))/
28
+
29
+ // Use the regex to test if the inputString matches the function pattern
30
+ return functionRegex.test(inputString)
31
+ }
package/key.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
- export const createKey = (function () {
3
+ export const generateKey = (function () {
4
4
  let index = 0
5
5
 
6
6
  function newId () {
@@ -11,4 +11,4 @@ export const createKey = (function () {
11
11
  return newId
12
12
  })()
13
13
 
14
- export const createSnapshotId = createKey
14
+ export const createSnapshotId = generateKey
package/object.js CHANGED
@@ -375,20 +375,77 @@ export const flattenRecursive = (param, prop, stack = []) => {
375
375
  return stack
376
376
  }
377
377
 
378
- export const isEqualDeep = (param, element) => {
379
- if (param === element) return true
380
- if (!param || !element) return false
381
- for (const prop in param) {
382
- const paramProp = param[prop]
383
- const elementProp = element[prop]
384
- if (isObjectLike(paramProp)) {
385
- const isEqual = isEqualDeep(paramProp, elementProp)
386
- if (!isEqual) return false
387
- } else {
388
- const isEqual = paramProp === elementProp
389
- if (!isEqual) return false
378
+ /**
379
+ * Recursively compares two values to determine if they are deeply equal.
380
+ *
381
+ * This function checks for deep equality between two values, including
382
+ * objects, arrays, and nested structures. It handles circular references to
383
+ * prevent infinite loops.
384
+ *
385
+ * @param {*} param - The first value to compare.
386
+ * @param {*} element - The second value to compare.
387
+ * @param {Set} [visited] - (Optional) A set to track visited objects during recursion
388
+ * to handle circular references. You can omit this parameter when calling
389
+ * the function; it is used internally for tracking visited objects.
390
+ *
391
+ * @returns {boolean} Returns `true` if the values are deeply equal, `false` otherwise.
392
+ *
393
+ * @example
394
+ * // Comparing primitive values
395
+ * isEqualDeep(42, 42); // true
396
+ * isEqualDeep('hello', 'hello'); // true
397
+ * isEqualDeep(true, true); // true
398
+ * isEqualDeep(42, '42'); // false
399
+ *
400
+ * // Comparing simple objects
401
+ * const obj1 = { a: 1, b: { c: 2 } };
402
+ * const obj2 = { a: 1, b: { c: 2 } };
403
+ * isEqualDeep(obj1, obj2); // true
404
+ *
405
+ * // Handling circular references
406
+ * const circularObj = { prop: null };
407
+ * circularObj.prop = circularObj;
408
+ * const anotherObj = { prop: null };
409
+ * anotherObj.prop = anotherObj;
410
+ * isEqualDeep(circularObj, anotherObj); // true
411
+ */
412
+ export const isEqualDeep = (param, element, visited = new Set()) => {
413
+ // Check if both values are non-null objects
414
+ if (typeof param !== 'object' || typeof element !== 'object' || param === null || element === null) {
415
+ return param === element // Compare non-object values directly
416
+ }
417
+
418
+ // Check for circular references
419
+ if (visited.has(param) || visited.has(element)) {
420
+ return true // Assume equality to break the circular reference
421
+ }
422
+
423
+ visited.add(param)
424
+ visited.add(element)
425
+
426
+ const keysParam = Object.keys(param)
427
+ const keysElement = Object.keys(element)
428
+
429
+ // Check if both objects have the same number of properties
430
+ if (keysParam.length !== keysElement.length) {
431
+ return false
432
+ }
433
+
434
+ // Check if all properties in param also exist in element
435
+ for (const key of keysParam) {
436
+ if (!keysElement.includes(key)) {
437
+ return false
438
+ }
439
+
440
+ const paramProp = param[key]
441
+ const elementProp = element[key]
442
+
443
+ // Recursively check property values
444
+ if (!isEqualDeep(paramProp, elementProp, visited)) {
445
+ return false
390
446
  }
391
447
  }
448
+
392
449
  return true
393
450
  }
394
451
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domql/utils",
3
- "version": "2.4.7",
3
+ "version": "2.5.13",
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": "fd9683a7d42893983463967fa512ac095a6a36e9",
26
+ "gitHead": "3bbff7f4e2ced6f104572489a2779a5cf0dbb450",
27
27
  "devDependencies": {
28
28
  "@babel/core": "^7.12.0"
29
29
  }