@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.
- package/dist/atoms.full.js +18 -19
- package/dist/value/diff.js +13 -14
- package/package.json +1 -1
- package/src/value/diff.ts +23 -33
package/dist/atoms.full.js
CHANGED
|
@@ -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) ||
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
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;
|
package/dist/value/diff.js
CHANGED
|
@@ -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 ||
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
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:
|
|
119
|
-
second:
|
|
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) ||
|
|
161
|
-
|
|
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
|
-
|
|
161
|
+
const prefixed = join([prefix, key], '.');
|
|
170
162
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
prefixed,
|
|
177
|
-
)
|
|
178
|
-
: [];
|
|
163
|
+
const change = {
|
|
164
|
+
from,
|
|
165
|
+
to,
|
|
166
|
+
key: prefixed,
|
|
167
|
+
};
|
|
179
168
|
|
|
180
|
-
|
|
181
|
-
changes.push(change);
|
|
182
|
-
}
|
|
169
|
+
const nested = isArrayOrPlainObject(from) || isArrayOrPlainObject(to);
|
|
183
170
|
|
|
184
|
-
|
|
171
|
+
const diffs = nested ? getDiffs(from, to, relaxedNullish, prefixed) : [];
|
|
185
172
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
}
|
|
173
|
+
if (!nested || (nested && diffs.length > 0)) {
|
|
174
|
+
changes.push(change);
|
|
189
175
|
}
|
|
190
176
|
|
|
191
|
-
|
|
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
|
|