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