@wavy/fn 0.0.37 → 0.0.39

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.
package/dist/main.cjs CHANGED
@@ -629,12 +629,19 @@ function traverse(obj, path) {
629
629
  function findObjectChanges(source, compareTo, options) {
630
630
  let entries = Object.entries(source);
631
631
  const changes = Object.keys(compareTo).filter(
632
- (key) => !entries.some(([sourceKey]) => sourceKey === key)
632
+ (key) => !options?.ignoredKeys?.includes(key) && !entries.some(([sourceKey]) => sourceKey === key)
633
633
  );
634
+ const ignoreDepth = options?.ignoreDepth === "max" ? Infinity : Math.abs(options?.ignoreDepth || 0);
635
+ const isKeyIgnored = (key) => {
636
+ return key.split(".").some(
637
+ (key2, idx) => idx <= ignoreDepth && options?.ignoredKeys?.includes(key2)
638
+ );
639
+ };
634
640
  for (let idx = 0; idx < entries.length; idx++) {
635
641
  const [key, value] = entries[idx];
636
642
  const comparedValue = traverse(compareTo, key);
637
643
  const checkArrayEquality = options?.strict ? strictArrayEquals : arrayEquals;
644
+ if (isKeyIgnored(key)) continue;
638
645
  if (Array.isArray(value) && Array.isArray(comparedValue) && !checkArrayEquality(value, comparedValue)) {
639
646
  changes.push(key);
640
647
  } else if (!!value && !!comparedValue && typeof value === "object" && typeof comparedValue === "object") {
@@ -644,6 +651,9 @@ function findObjectChanges(source, compareTo, options) {
644
651
  return [path, nestedValue];
645
652
  }
646
653
  );
654
+ const newCompareTo = traverse(compareTo, key);
655
+ const nonExistentKeys = Object.keys(newCompareTo).filter((key2) => !isKeyIgnored(key2) && !(key2 in value)).map((nestedKey) => [key, nestedKey].join("."));
656
+ changes.push(...nonExistentKeys);
647
657
  entries.push(...newEntries);
648
658
  } else if (JSON.stringify(value) !== JSON.stringify(comparedValue)) {
649
659
  changes.push(key);
@@ -651,18 +661,18 @@ function findObjectChanges(source, compareTo, options) {
651
661
  }
652
662
  return changes;
653
663
  }
654
- function findChanges(source, compareTo) {
664
+ function findChanges(source, compareTo, options) {
655
665
  if (Array.isArray(source) && Array.isArray(compareTo)) {
656
666
  const changes = [];
657
667
  for (let idx = 0; idx < source.length; idx++) {
658
- const _changes = findObjectChanges(source[idx], compareTo[idx]);
668
+ const _changes = findObjectChanges(source[idx], compareTo[idx], options);
659
669
  if (_changes.length > 0) {
660
670
  changes.push({ keys: _changes, index: idx });
661
671
  }
662
672
  }
663
673
  return changes;
664
674
  } else if (typeof source === "object" && typeof compareTo === "object") {
665
- return findObjectChanges(source, compareTo);
675
+ return findObjectChanges(source, compareTo, options);
666
676
  }
667
677
  return [];
668
678
  }
package/dist/main.d.cts CHANGED
@@ -88,8 +88,16 @@ declare function isFileDetails(value: unknown): value is FileDetails;
88
88
  declare function traverse(obj: object, path: string): object;
89
89
  declare function findObjectChanges<T extends object>(source: T, compareTo: T, options?: Partial<{
90
90
  strict: boolean;
91
+ ignoredKeys: (keyof T | (string & {}))[];
92
+ /**
93
+ * How deep the ignoredKeys should be applied.
94
+ *
95
+ * @default 0 */
96
+ ignoreDepth: "max" | number;
91
97
  }>): string[];
92
- declare function findChanges<T extends object | object[]>(source: T, compareTo: T): T extends object[] ? {
98
+ declare function findChanges<T extends object | object[]>(source: T, compareTo: T, options?: Parameters<typeof findObjectChanges>["2"] & {
99
+ ignoredKeys?: T extends any[] ? (keyof T[number] | (string & {}))[] : T extends object ? (keyof T | (string & {}))[] : never;
100
+ }): T extends object[] ? {
93
101
  keys: string[];
94
102
  index: number;
95
103
  }[] : T extends object ? string[] : never;
package/dist/main.d.ts CHANGED
@@ -88,8 +88,16 @@ declare function isFileDetails(value: unknown): value is FileDetails;
88
88
  declare function traverse(obj: object, path: string): object;
89
89
  declare function findObjectChanges<T extends object>(source: T, compareTo: T, options?: Partial<{
90
90
  strict: boolean;
91
+ ignoredKeys: (keyof T | (string & {}))[];
92
+ /**
93
+ * How deep the ignoredKeys should be applied.
94
+ *
95
+ * @default 0 */
96
+ ignoreDepth: "max" | number;
91
97
  }>): string[];
92
- declare function findChanges<T extends object | object[]>(source: T, compareTo: T): T extends object[] ? {
98
+ declare function findChanges<T extends object | object[]>(source: T, compareTo: T, options?: Parameters<typeof findObjectChanges>["2"] & {
99
+ ignoredKeys?: T extends any[] ? (keyof T[number] | (string & {}))[] : T extends object ? (keyof T | (string & {}))[] : never;
100
+ }): T extends object[] ? {
93
101
  keys: string[];
94
102
  index: number;
95
103
  }[] : T extends object ? string[] : never;
package/dist/main.js CHANGED
@@ -518,12 +518,19 @@ function traverse(obj, path) {
518
518
  function findObjectChanges(source, compareTo, options) {
519
519
  let entries = Object.entries(source);
520
520
  const changes = Object.keys(compareTo).filter(
521
- (key) => !entries.some(([sourceKey]) => sourceKey === key)
521
+ (key) => !options?.ignoredKeys?.includes(key) && !entries.some(([sourceKey]) => sourceKey === key)
522
522
  );
523
+ const ignoreDepth = options?.ignoreDepth === "max" ? Infinity : Math.abs(options?.ignoreDepth || 0);
524
+ const isKeyIgnored = (key) => {
525
+ return key.split(".").some(
526
+ (key2, idx) => idx <= ignoreDepth && options?.ignoredKeys?.includes(key2)
527
+ );
528
+ };
523
529
  for (let idx = 0; idx < entries.length; idx++) {
524
530
  const [key, value] = entries[idx];
525
531
  const comparedValue = traverse(compareTo, key);
526
532
  const checkArrayEquality = options?.strict ? strictArrayEquals : arrayEquals;
533
+ if (isKeyIgnored(key)) continue;
527
534
  if (Array.isArray(value) && Array.isArray(comparedValue) && !checkArrayEquality(value, comparedValue)) {
528
535
  changes.push(key);
529
536
  } else if (!!value && !!comparedValue && typeof value === "object" && typeof comparedValue === "object") {
@@ -533,6 +540,9 @@ function findObjectChanges(source, compareTo, options) {
533
540
  return [path, nestedValue];
534
541
  }
535
542
  );
543
+ const newCompareTo = traverse(compareTo, key);
544
+ const nonExistentKeys = Object.keys(newCompareTo).filter((key2) => !isKeyIgnored(key2) && !(key2 in value)).map((nestedKey) => [key, nestedKey].join("."));
545
+ changes.push(...nonExistentKeys);
536
546
  entries.push(...newEntries);
537
547
  } else if (JSON.stringify(value) !== JSON.stringify(comparedValue)) {
538
548
  changes.push(key);
@@ -540,18 +550,18 @@ function findObjectChanges(source, compareTo, options) {
540
550
  }
541
551
  return changes;
542
552
  }
543
- function findChanges(source, compareTo) {
553
+ function findChanges(source, compareTo, options) {
544
554
  if (Array.isArray(source) && Array.isArray(compareTo)) {
545
555
  const changes = [];
546
556
  for (let idx = 0; idx < source.length; idx++) {
547
- const _changes = findObjectChanges(source[idx], compareTo[idx]);
557
+ const _changes = findObjectChanges(source[idx], compareTo[idx], options);
548
558
  if (_changes.length > 0) {
549
559
  changes.push({ keys: _changes, index: idx });
550
560
  }
551
561
  }
552
562
  return changes;
553
563
  } else if (typeof source === "object" && typeof compareTo === "object") {
554
- return findObjectChanges(source, compareTo);
564
+ return findObjectChanges(source, compareTo, options);
555
565
  }
556
566
  return [];
557
567
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wavy/fn",
3
- "version": "0.0.37",
3
+ "version": "0.0.39",
4
4
  "main": "./dist/main.js",
5
5
  "module": "./dist/main.cjs",
6
6
  "types": "./dist/main.d.ts",