@worker-tools/structured-json
Version:
Stringify and parse JavaScript values according to Structured Clone Algorithm.
32 lines • 1.17 kB
JavaScript
// deno-lint-ignore-file no-explicit-any ban-ts-comment
import typeson from './typeson.js';
// @ts-ignore
import { structuredCloningThrowing } from 'typeson-registry';
import blob from './blob.js';
import file from './file.js';
import filelist from './filelist.js';
const { Typeson } = typeson;
const structuredCloningThrowingPatched = structuredCloningThrowing
.filter((x) => !x.file && !x.blob)
.concat([blob, file, filelist]);
const Structured = new Typeson().register([structuredCloningThrowingPatched]);
export function parse(s) {
return Structured.revive(JSON.parse(s));
}
export function stringify(value) {
return Structured.stringifySync(value);
}
export function stringifyAsync(value) {
return Structured.stringifyAsync(value);
}
export function toJSON(value) {
return Structured.encapsulateSync(value);
}
export function toJSONAsync(value) {
return Structured.encapsulateAsync(value);
}
export function fromJSON(json) {
return Structured.revive(json);
}
export { toJSON as toJSONValue, fromJSON as fromJSONValue, fromJSON as revive, toJSON as encapsulate, toJSONAsync as encapsulateAsync, };
//# sourceMappingURL=index.js.map