Blame Raw
· · · 21 lines (690 B)
0 contributors
1/*! (c) Andrea Giammarchi - ISC */
2
3import {deserialize} from './deserialize.js';
4import {serialize} from './serialize.js';
5
6const {parse: $parse, stringify: $stringify} = JSON;
7const options = {json: true, lossy: true};
8
9/**
10 * Revive a previously stringified structured clone.
11 * @param {string} str previously stringified data as string.
12 * @returns {any} whatever was previously stringified as clone.
13 */
14export const parse = str => deserialize($parse(str));
15
16/**
17 * Represent a structured clone value as string.
18 * @param {any} any some clone-able value to stringify.
19 * @returns {string} the value stringified.
20 */
21export const stringify = any => $stringify(serialize(any, options));