@seam-rpc/core 5.1.3 → 5.2.0
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.d.ts +9 -0
- package/dist/index.js +43 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -43,3 +43,12 @@ export declare function injectFiles(json: any, files: {
|
|
|
43
43
|
path: (string | number)[];
|
|
44
44
|
file: File;
|
|
45
45
|
}[]): void;
|
|
46
|
+
export declare function extractDates(input: unknown): {
|
|
47
|
+
json: any;
|
|
48
|
+
dates: string[];
|
|
49
|
+
paths: (string | number)[][];
|
|
50
|
+
};
|
|
51
|
+
export declare function injectDates(json: any, dates: {
|
|
52
|
+
path: (string | number)[];
|
|
53
|
+
dateString: string;
|
|
54
|
+
}[]): void;
|
package/dist/index.js
CHANGED
|
@@ -22,6 +22,10 @@ export function extractFiles(input) {
|
|
|
22
22
|
paths.push(path);
|
|
23
23
|
return null;
|
|
24
24
|
}
|
|
25
|
+
// Keep Date objects intact so date extraction can process them later.
|
|
26
|
+
if (value instanceof Date) {
|
|
27
|
+
return value;
|
|
28
|
+
}
|
|
25
29
|
if (Array.isArray(value)) {
|
|
26
30
|
return value.map((e, index) => walk(e, [...path, index]));
|
|
27
31
|
}
|
|
@@ -47,3 +51,42 @@ export function injectFiles(json, files) {
|
|
|
47
51
|
}
|
|
48
52
|
}
|
|
49
53
|
}
|
|
54
|
+
export function extractDates(input) {
|
|
55
|
+
const dates = [];
|
|
56
|
+
const paths = [];
|
|
57
|
+
function walk(value, path) {
|
|
58
|
+
if (value instanceof Date) {
|
|
59
|
+
dates.push(value.toISOString());
|
|
60
|
+
paths.push(path);
|
|
61
|
+
return value.toISOString();
|
|
62
|
+
}
|
|
63
|
+
// Keep File objects intact so file extraction can process them later.
|
|
64
|
+
if (value instanceof File) {
|
|
65
|
+
return value;
|
|
66
|
+
}
|
|
67
|
+
if (Array.isArray(value)) {
|
|
68
|
+
return value.map((e, index) => walk(e, [...path, index]));
|
|
69
|
+
}
|
|
70
|
+
if (value && typeof value === "object") {
|
|
71
|
+
return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, walk(v, [...path, k])]));
|
|
72
|
+
}
|
|
73
|
+
return value;
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
json: walk(input, []),
|
|
77
|
+
dates,
|
|
78
|
+
paths,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
export function injectDates(json, dates) {
|
|
82
|
+
for (const dateEntry of dates) {
|
|
83
|
+
let current = json;
|
|
84
|
+
for (let i = 0; i < dateEntry.path.length; i++) {
|
|
85
|
+
const key = dateEntry.path[i];
|
|
86
|
+
if (i < dateEntry.path.length - 1)
|
|
87
|
+
current = current[key];
|
|
88
|
+
else
|
|
89
|
+
current[key] = new Date(dateEntry.dateString);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|