1 |
|
2 | import typeson from './typeson.js'
|
3 |
|
4 | import { structuredCloningThrowing } from 'typeson-registry';
|
5 |
|
6 | import blob from './blob.js'
|
7 | import file from './file.js'
|
8 | import filelist from './filelist.js'
|
9 |
|
10 | const { Typeson } = typeson;
|
11 |
|
12 | const structuredCloningThrowingPatched = (structuredCloningThrowing as any[])
|
13 | .filter((x: any) => !x.file && !x.blob)
|
14 | .concat([blob, file, filelist])
|
15 |
|
16 | const Structured = new Typeson().register([structuredCloningThrowingPatched]);
|
17 |
|
18 | export function parse(s: string) {
|
19 | return Structured.revive(JSON.parse(s))
|
20 | }
|
21 |
|
22 | export function stringify(value: any): string {
|
23 | return Structured.stringifySync(value);
|
24 | }
|
25 |
|
26 | export function stringifyAsync(value: any): string | Promise<string> {
|
27 | return Structured.stringifyAsync(value);
|
28 | }
|
29 |
|
30 | export function toJSON(value: any): any {
|
31 | return Structured.encapsulateSync(value)
|
32 | }
|
33 |
|
34 | export function toJSONAsync(value: any): any | Promise<any> {
|
35 | return Structured.encapsulateAsync(value)
|
36 | }
|
37 |
|
38 | export function fromJSON(json: any) {
|
39 | return Structured.revive(json)
|
40 | }
|
41 |
|
42 | export {
|
43 | toJSON as toJSONValue,
|
44 | fromJSON as fromJSONValue,
|
45 | fromJSON as revive,
|
46 | toJSON as encapsulate,
|
47 | toJSONAsync as encapsulateAsync,
|
48 | }
|