@ztimson/utils 0.27.1 → 0.27.3
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/index.cjs +15 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +15 -11
- package/dist/index.mjs.map +1 -1
- package/dist/objects.d.ts +4 -4
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -121,17 +121,21 @@ ${opts.message || this.desc}`;
|
|
|
121
121
|
`;
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
|
-
function
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
124
|
+
function applyDeltas(base, ...deltas) {
|
|
125
|
+
function applyDelta(base2, delta) {
|
|
126
|
+
if (delta === null) return null;
|
|
127
|
+
if (typeof base2 !== "object" || base2 === null) return delta === void 0 ? base2 : delta;
|
|
128
|
+
const result = Array.isArray(base2) ? [...base2] : { ...base2 };
|
|
129
|
+
for (const key in delta) {
|
|
130
|
+
const val = delta[key];
|
|
131
|
+
if (val === void 0) delete result[key];
|
|
132
|
+
else if (typeof val === "object" && val !== null && !Array.isArray(val)) result[key] = applyDelta(result[key], val);
|
|
133
|
+
else result[key] = val;
|
|
134
|
+
}
|
|
135
|
+
return result;
|
|
133
136
|
}
|
|
134
|
-
|
|
137
|
+
for (const d of deltas.flat()) base = applyDelta(base, (d == null ? void 0 : d.delta) ?? d);
|
|
138
|
+
return base;
|
|
135
139
|
}
|
|
136
140
|
function calcDelta(old, updated) {
|
|
137
141
|
if (updated == null) return null;
|
|
@@ -2367,7 +2371,7 @@ ${opts.message || this.desc}`;
|
|
|
2367
2371
|
exports2.UnauthorizedError = UnauthorizedError;
|
|
2368
2372
|
exports2.addUnique = addUnique;
|
|
2369
2373
|
exports2.adjustedInterval = adjustedInterval;
|
|
2370
|
-
exports2.
|
|
2374
|
+
exports2.applyDeltas = applyDeltas;
|
|
2371
2375
|
exports2.arrayDiff = arrayDiff;
|
|
2372
2376
|
exports2.calcDelta = calcDelta;
|
|
2373
2377
|
exports2.camelCase = camelCase;
|