Blame Raw
· · · 25 lines (829 B)
0 contributors
1import {deserialize} from './deserialize.js';
2import {serialize} from './serialize.js';
3
4/**
5 * @typedef {Array<string,any>} Record a type representation
6 */
7
8/**
9 * Returns an array of serialized Records.
10 * @param {any} any a serializable value.
11 * @param {{transfer?: any[], json?: boolean, lossy?: boolean}?} options an object with
12 * a transfer option (ignored when polyfilled) and/or non standard fields that
13 * fallback to the polyfill if present.
14 * @returns {Record[]}
15 */
16export default typeof structuredClone === "function" ?
17 /* c8 ignore start */
18 (any, options) => (
19 options && ('json' in options || 'lossy' in options) ?
20 deserialize(serialize(any, options)) : structuredClone(any)
21 ) :
22 (any, options) => deserialize(serialize(any, options));
23 /* c8 ignore stop */
24
25export {deserialize, serialize};