| 1 | /*! (c) Andrea Giammarchi - ISC */ |
| 2 | |
| 3 | import {deserialize} from './deserialize.js'; |
| 4 | import {serialize} from './serialize.js'; |
| 5 | |
| 6 | const {parse: $parse, stringify: $stringify} = JSON; |
| 7 | const 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 | */ |
| 14 | export 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 | */ |
| 21 | export const stringify = any => $stringify(serialize(any, options)); |