@wikicasa-dev/utilities 1.2.6 → 1.2.7
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.
|
@@ -6,16 +6,8 @@ export type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
|
6
6
|
export type JsonObject = {
|
|
7
7
|
[key: string]: JsonValue;
|
|
8
8
|
};
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
*
|
|
12
|
-
* Key idea:
|
|
13
|
-
* - `null` = delete field
|
|
14
|
-
* - object = recurse
|
|
15
|
-
* - other values = replace
|
|
16
|
-
*/
|
|
17
|
-
export type JsonMergePatch<T> = T extends JsonValue[] ? JsonValue[] : T extends object ? {
|
|
18
|
-
[K in keyof T]?: JsonMergePatch<T[K]> | null;
|
|
9
|
+
export type MergePatch<T> = T extends JsonValue[] ? T : T extends object ? {
|
|
10
|
+
[K in keyof T]?: MergePatch<T[K]> | null;
|
|
19
11
|
} : T;
|
|
20
12
|
export declare function shallowCopyObjectTo(from: Record<string, any> | undefined, to: Record<string, any>): void;
|
|
21
13
|
/**
|
|
@@ -114,4 +106,4 @@ export declare const areObjectsEqual: (obj1?: object, obj2?: object) => boolean;
|
|
|
114
106
|
* @param patch - The JSON Merge Patch object describing changes.
|
|
115
107
|
* @returns A new object resulting from applying the patch.
|
|
116
108
|
*/
|
|
117
|
-
export declare
|
|
109
|
+
export declare const applyMergePatch: <T extends JsonObject>(source: T, patch: MergePatch<T>) => T;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function
|
|
1
|
+
function u(e, t) {
|
|
2
2
|
if (e)
|
|
3
3
|
for (const r in e)
|
|
4
4
|
t[r] = e[r];
|
|
@@ -34,21 +34,20 @@ const O = (e) => Object.entries(e).reduce(
|
|
|
34
34
|
t[s]
|
|
35
35
|
)
|
|
36
36
|
);
|
|
37
|
-
}, l = (e) => e !== null && typeof e == "object" && !Array.isArray(e)
|
|
37
|
+
}, l = (e) => e !== null && typeof e == "object" && !Array.isArray(e);
|
|
38
|
+
function f(e, t) {
|
|
38
39
|
if (t === null)
|
|
39
40
|
return;
|
|
40
41
|
if (!l(e) || !l(t))
|
|
41
42
|
return t;
|
|
42
43
|
const r = { ...e };
|
|
43
44
|
for (const n of Object.keys(t)) {
|
|
44
|
-
const s = t[n], i =
|
|
45
|
+
const s = t[n], i = f(e[n], s);
|
|
45
46
|
i === void 0 ? delete r[n] : r[n] = i;
|
|
46
47
|
}
|
|
47
48
|
return r;
|
|
48
|
-
};
|
|
49
|
-
function k(e, t) {
|
|
50
|
-
return u(e, t);
|
|
51
49
|
}
|
|
50
|
+
const k = (e, t) => f(e, t);
|
|
52
51
|
export {
|
|
53
52
|
k as applyMergePatch,
|
|
54
53
|
c as areObjectsEqual,
|
|
@@ -58,5 +57,5 @@ export {
|
|
|
58
57
|
O as invertFlatObject,
|
|
59
58
|
g as invertKeyToValue,
|
|
60
59
|
y as isEmptyObject,
|
|
61
|
-
|
|
60
|
+
u as shallowCopyObjectTo
|
|
62
61
|
};
|