@oscarpalmer/atoms 0.111.0 → 0.111.1

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.
@@ -2685,28 +2685,27 @@ function getDiffs(first, second, relaxedNullish, prefix) {
2685
2685
  if (checked.has(key)) {
2686
2686
  continue;
2687
2687
  }
2688
+ checked.add(key);
2688
2689
  const from = first?.[key];
2689
2690
  const to = second?.[key];
2690
- if ((relaxedNullish && from == null && to == null) || !equal(from, to)) {
2691
- const prefixed = join([prefix, key], '.');
2692
- const change = {
2693
- from,
2694
- to,
2695
- key: prefixed,
2696
- };
2697
- const nested = isArrayOrPlainObject(from) || isArrayOrPlainObject(to);
2698
- const diffs = nested
2699
- ? getDiffs(from, to, relaxedNullish, prefixed)
2700
- : [];
2701
- if (!nested || (nested && diffs.length > 0)) {
2702
- changes.push(change);
2703
- }
2704
- const diffsLength = diffs.length;
2705
- for (let diffIndex = 0; diffIndex < diffsLength; diffIndex += 1) {
2706
- changes.push(diffs[diffIndex]);
2707
- }
2691
+ if ((relaxedNullish && from == null && to == null) || equal(from, to)) {
2692
+ continue;
2693
+ }
2694
+ const prefixed = join([prefix, key], '.');
2695
+ const change = {
2696
+ from,
2697
+ to,
2698
+ key: prefixed,
2699
+ };
2700
+ const nested = isArrayOrPlainObject(from) || isArrayOrPlainObject(to);
2701
+ const diffs = nested ? getDiffs(from, to, relaxedNullish, prefixed) : [];
2702
+ if (!nested || (nested && diffs.length > 0)) {
2703
+ changes.push(change);
2704
+ }
2705
+ const diffsLength = diffs.length;
2706
+ for (let diffIndex = 0; diffIndex < diffsLength; diffIndex += 1) {
2707
+ changes.push(diffs[diffIndex]);
2708
2708
  }
2709
- checked.add(key);
2710
2709
  }
2711
2710
  }
2712
2711
  return changes;
@@ -56,22 +56,21 @@ function getDiffs(first, second, relaxedNullish, prefix) {
56
56
  for (let innerIndex = 0; innerIndex < length; innerIndex += 1) {
57
57
  const key = keys[innerIndex];
58
58
  if (checked.has(key)) continue;
59
+ checked.add(key);
59
60
  const from = first?.[key];
60
61
  const to = second?.[key];
61
- if (relaxedNullish && from == null && to == null || !equal(from, to)) {
62
- const prefixed = join([prefix, key], ".");
63
- const change = {
64
- from,
65
- to,
66
- key: prefixed
67
- };
68
- const nested = isArrayOrPlainObject(from) || isArrayOrPlainObject(to);
69
- const diffs = nested ? getDiffs(from, to, relaxedNullish, prefixed) : [];
70
- if (!nested || nested && diffs.length > 0) changes.push(change);
71
- const diffsLength = diffs.length;
72
- for (let diffIndex = 0; diffIndex < diffsLength; diffIndex += 1) changes.push(diffs[diffIndex]);
73
- }
74
- checked.add(key);
62
+ if (relaxedNullish && from == null && to == null || equal(from, to)) continue;
63
+ const prefixed = join([prefix, key], ".");
64
+ const change = {
65
+ from,
66
+ to,
67
+ key: prefixed
68
+ };
69
+ const nested = isArrayOrPlainObject(from) || isArrayOrPlainObject(to);
70
+ const diffs = nested ? getDiffs(from, to, relaxedNullish, prefixed) : [];
71
+ if (!nested || nested && diffs.length > 0) changes.push(change);
72
+ const diffsLength = diffs.length;
73
+ for (let diffIndex = 0; diffIndex < diffsLength; diffIndex += 1) changes.push(diffs[diffIndex]);
75
74
  }
76
75
  }
77
76
  return changes;
package/package.json CHANGED
@@ -100,5 +100,5 @@
100
100
  },
101
101
  "type": "module",
102
102
  "types": "./types/index.d.ts",
103
- "version": "0.111.0"
103
+ "version": "0.111.1"
104
104
  }
package/src/value/diff.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import {isArrayOrPlainObject} from '../internal/is';
2
2
  import {join} from '../internal/string';
3
3
  import {equal} from '../internal/value/equal';
4
- import type {ArrayOrPlainObject} from '../models';
5
4
 
6
5
  type DiffOptions = {
7
6
  /**
@@ -93,11 +92,7 @@ export function diff<First, Second = First>(
93
92
  return result;
94
93
  }
95
94
 
96
- const diffs = getDiffs(
97
- first as ArrayOrPlainObject,
98
- second as ArrayOrPlainObject,
99
- relaxedNullish,
100
- );
95
+ const diffs = getDiffs(first, second, relaxedNullish);
101
96
 
102
97
  const {length} = diffs;
103
98
 
@@ -115,8 +110,8 @@ export function diff<First, Second = First>(
115
110
  }
116
111
 
117
112
  function getDiffs(
118
- first: ArrayOrPlainObject,
119
- second: ArrayOrPlainObject,
113
+ first: unknown,
114
+ second: unknown,
120
115
  relaxedNullish: boolean,
121
116
  prefix?: string,
122
117
  ): KeyedDiffValue[] {
@@ -154,41 +149,36 @@ function getDiffs(
154
149
  continue;
155
150
  }
156
151
 
152
+ checked.add(key);
153
+
157
154
  const from = first?.[key as never];
158
155
  const to = second?.[key as never];
159
156
 
160
- if ((relaxedNullish && from == null && to == null) || !equal(from, to)) {
161
- const prefixed = join([prefix, key], '.');
162
-
163
- const change = {
164
- from,
165
- to,
166
- key: prefixed,
167
- };
157
+ if ((relaxedNullish && from == null && to == null) || equal(from, to)) {
158
+ continue;
159
+ }
168
160
 
169
- const nested = isArrayOrPlainObject(from) || isArrayOrPlainObject(to);
161
+ const prefixed = join([prefix, key], '.');
170
162
 
171
- const diffs = nested
172
- ? getDiffs(
173
- from as ArrayOrPlainObject,
174
- to as ArrayOrPlainObject,
175
- relaxedNullish,
176
- prefixed,
177
- )
178
- : [];
163
+ const change = {
164
+ from,
165
+ to,
166
+ key: prefixed,
167
+ };
179
168
 
180
- if (!nested || (nested && diffs.length > 0)) {
181
- changes.push(change);
182
- }
169
+ const nested = isArrayOrPlainObject(from) || isArrayOrPlainObject(to);
183
170
 
184
- const diffsLength = diffs.length;
171
+ const diffs = nested ? getDiffs(from, to, relaxedNullish, prefixed) : [];
185
172
 
186
- for (let diffIndex = 0; diffIndex < diffsLength; diffIndex += 1) {
187
- changes.push(diffs[diffIndex]);
188
- }
173
+ if (!nested || (nested && diffs.length > 0)) {
174
+ changes.push(change);
189
175
  }
190
176
 
191
- checked.add(key);
177
+ const diffsLength = diffs.length;
178
+
179
+ for (let diffIndex = 0; diffIndex < diffsLength; diffIndex += 1) {
180
+ changes.push(diffs[diffIndex]);
181
+ }
192
182
  }
193
183
  }
194
184