@domql/utils 2.5.113 → 2.5.116

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.
@@ -467,30 +467,35 @@ const isEqualDeep = (param, element, visited = /* @__PURE__ */ new Set()) => {
467
467
  }
468
468
  return true;
469
469
  };
470
- const deepContains = (obj1, obj2) => {
471
- if (typeof obj1 !== typeof obj2) {
470
+ const deepContains = (obj1, obj2, ignoredKeys = ["node", "__ref"]) => {
471
+ if (obj1 === obj2)
472
+ return true;
473
+ if (!(0, import_types.isObjectLike)(obj1) || !(0, import_types.isObjectLike)(obj2))
472
474
  return false;
473
- }
474
- if ((0, import_types.isObjectLike)(obj1)) {
475
- if (Array.isArray(obj1) && Array.isArray(obj2)) {
476
- if (obj1.length !== obj2.length) {
475
+ const stack = [[obj1, obj2]];
476
+ const visited = /* @__PURE__ */ new WeakSet();
477
+ while (stack.length > 0) {
478
+ const [current1, current2] = stack.pop();
479
+ if (visited.has(current1))
480
+ continue;
481
+ visited.add(current1);
482
+ const keys1 = Object.keys(current1).filter((key) => !ignoredKeys.includes(key));
483
+ const keys2 = Object.keys(current2).filter((key) => !ignoredKeys.includes(key));
484
+ if (keys1.length !== keys2.length)
485
+ return false;
486
+ for (const key of keys1) {
487
+ if (!Object.prototype.hasOwnProperty.call(current2, key))
477
488
  return false;
478
- }
479
- for (let i = 0; i < obj1.length; i++) {
480
- if (!deepContains(obj1[i], obj2[i])) {
481
- return false;
482
- }
483
- }
484
- } else if ((0, import_types.isObjectLike)(obj1) && obj2 !== null) {
485
- for (const key in obj1) {
486
- const hasOwnProperty2 = Object.prototype.hasOwnProperty.call(obj2, key);
487
- if (!hasOwnProperty2 || !deepContains(obj1[key], obj2[key])) {
488
- return false;
489
+ const value1 = current1[key];
490
+ const value2 = current2[key];
491
+ if ((0, import_types.isObjectLike)(value1) && (0, import_types.isObjectLike)(value2)) {
492
+ if (value1 !== value2) {
493
+ stack.push([value1, value2]);
489
494
  }
495
+ } else if (value1 !== value2) {
496
+ return false;
490
497
  }
491
498
  }
492
- } else {
493
- return obj2 === obj1;
494
499
  }
495
500
  return true;
496
501
  };
package/object.js CHANGED
@@ -538,35 +538,42 @@ export const isEqualDeep = (param, element, visited = new Set()) => {
538
538
  return true
539
539
  }
540
540
 
541
- export const deepContains = (obj1, obj2) => {
542
- if (typeof obj1 !== typeof obj2) {
543
- return false
544
- }
541
+ export const deepContains = (obj1, obj2, ignoredKeys = ['node', '__ref']) => {
542
+ if (obj1 === obj2) return true
543
+ if (!isObjectLike(obj1) || !isObjectLike(obj2)) return false
545
544
 
546
- if (isObjectLike(obj1)) {
547
- if (Array.isArray(obj1) && Array.isArray(obj2)) {
548
- if (obj1.length !== obj2.length) {
549
- return false
550
- }
551
- for (let i = 0; i < obj1.length; i++) {
552
- if (!deepContains(obj1[i], obj2[i])) {
553
- return false
554
- }
555
- }
556
- } else if (isObjectLike(obj1) && obj2 !== null) {
557
- for (const key in obj1) {
558
- const hasOwnProperty = Object.prototype.hasOwnProperty.call(obj2, key)
559
- if (!hasOwnProperty || !deepContains(obj1[key], obj2[key])) {
560
- return false
545
+ const stack = [[obj1, obj2]]
546
+ const visited = new WeakSet()
547
+
548
+ while (stack.length > 0) {
549
+ const [current1, current2] = stack.pop()
550
+
551
+ if (visited.has(current1)) continue
552
+ visited.add(current1)
553
+
554
+ const keys1 = Object.keys(current1).filter(key => !ignoredKeys.includes(key))
555
+ const keys2 = Object.keys(current2).filter(key => !ignoredKeys.includes(key))
556
+
557
+ if (keys1.length !== keys2.length) return false
558
+
559
+ for (const key of keys1) {
560
+ if (!Object.prototype.hasOwnProperty.call(current2, key)) return false
561
+
562
+ const value1 = current1[key]
563
+ const value2 = current2[key]
564
+
565
+ if (isObjectLike(value1) && isObjectLike(value2)) {
566
+ if (value1 !== value2) {
567
+ stack.push([value1, value2])
561
568
  }
569
+ } else if (value1 !== value2) {
570
+ return false
562
571
  }
563
572
  }
564
- } else {
565
- return obj2 === obj1
566
573
  }
567
574
 
568
575
  return true
569
- }
576
+ };
570
577
 
571
578
  export const removeFromObject = (obj, props) => {
572
579
  if (props === undefined || props === null) return obj
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domql/utils",
3
- "version": "2.5.113",
3
+ "version": "2.5.116",
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": "8436abbfa2752c4659982516ff9ad1db80862e42",
26
+ "gitHead": "cff7d465161d804f31e3b350081bb751da209eeb",
27
27
  "devDependencies": {
28
28
  "@babel/core": "^7.12.0"
29
29
  }