1121 lines
39 KiB
JavaScript
1121 lines
39 KiB
JavaScript
// node_modules/devalue/src/constants.js
|
|
var MAX_ARRAY_LEN = 2 ** 32 - 1;
|
|
var MAX_ARRAY_INDEX = MAX_ARRAY_LEN - 1;
|
|
// node_modules/devalue/src/utils.js
|
|
/** @type {Record<string, string>} */
|
|
var escaped = {
|
|
"<": "\\u003C",
|
|
"\\": "\\\\",
|
|
"\b": "\\b",
|
|
"\f": "\\f",
|
|
"\n": "\\n",
|
|
"\r": "\\r",
|
|
" ": "\\t",
|
|
"\u2028": "\\u2028",
|
|
"\u2029": "\\u2029"
|
|
};
|
|
var DevalueError = class extends Error {
|
|
/**
|
|
* @param {string} message
|
|
* @param {string[]} keys
|
|
* @param {any} [value] - The value that failed to be serialized
|
|
* @param {any} [root] - The root value being serialized
|
|
*/
|
|
constructor(message, keys, value, root) {
|
|
super(message);
|
|
this.name = "DevalueError";
|
|
this.path = keys.join("");
|
|
this.value = value;
|
|
this.root = root;
|
|
}
|
|
};
|
|
/** @param {any} thing */
|
|
function is_primitive(thing) {
|
|
return thing === null || typeof thing !== "object" && typeof thing !== "function";
|
|
}
|
|
var object_proto_names = /* @__PURE__ */ Object.getOwnPropertyNames(Object.prototype).sort().join("\0");
|
|
/** @param {any} thing */
|
|
function is_plain_object(thing) {
|
|
const proto = Object.getPrototypeOf(thing);
|
|
return proto === Object.prototype || proto === null || Object.getPrototypeOf(proto) === null || Object.getOwnPropertyNames(proto).sort().join("\0") === object_proto_names;
|
|
}
|
|
/** @param {any} thing */
|
|
function get_type(thing) {
|
|
return Object.prototype.toString.call(thing).slice(8, -1);
|
|
}
|
|
/** @param {any} thing */
|
|
function is_buffer(thing) {
|
|
return typeof Buffer !== "undefined" && Buffer.isBuffer(thing);
|
|
}
|
|
/** @param {string} char */
|
|
function get_escaped_char(char) {
|
|
switch (char) {
|
|
case "\"": return "\\\"";
|
|
case "<": return "\\u003C";
|
|
case "\\": return "\\\\";
|
|
case "\n": return "\\n";
|
|
case "\r": return "\\r";
|
|
case " ": return "\\t";
|
|
case "\b": return "\\b";
|
|
case "\f": return "\\f";
|
|
case "\u2028": return "\\u2028";
|
|
case "\u2029": return "\\u2029";
|
|
default: return char < " " ? `\\u${char.charCodeAt(0).toString(16).padStart(4, "0")}` : "";
|
|
}
|
|
}
|
|
/** @param {string} str */
|
|
function stringify_string(str) {
|
|
let result = "";
|
|
let last_pos = 0;
|
|
const len = str.length;
|
|
for (let i = 0; i < len; i += 1) {
|
|
const char = str[i];
|
|
const replacement = get_escaped_char(char);
|
|
if (replacement) {
|
|
result += str.slice(last_pos, i) + replacement;
|
|
last_pos = i + 1;
|
|
}
|
|
}
|
|
return `"${last_pos === 0 ? str : result + str.slice(last_pos)}"`;
|
|
}
|
|
/** @param {Record<string | symbol, any>} object */
|
|
function enumerable_symbols(object) {
|
|
return Object.getOwnPropertySymbols(object).filter((symbol) => Object.getOwnPropertyDescriptor(object, symbol).enumerable);
|
|
}
|
|
var is_identifier = /^[a-zA-Z_$][a-zA-Z_$0-9]*$/;
|
|
/** @param {string} key */
|
|
function stringify_key(key) {
|
|
return is_identifier.test(key) ? "." + key : "[" + JSON.stringify(key) + "]";
|
|
}
|
|
/** @param {number} n */
|
|
function is_valid_array_index(n) {
|
|
if (!Number.isInteger(n)) return false;
|
|
if (n < 0) return false;
|
|
if (n > MAX_ARRAY_INDEX) return false;
|
|
return true;
|
|
}
|
|
/** @param {number} n */
|
|
function is_valid_array_len(n) {
|
|
if (!Number.isInteger(n)) return false;
|
|
if (n < 0) return false;
|
|
if (n > MAX_ARRAY_LEN) return false;
|
|
return true;
|
|
}
|
|
/** @param {string} s */
|
|
function is_valid_array_index_string(s) {
|
|
if (s.length === 0) return false;
|
|
if (s.length > 1 && s.charCodeAt(0) === 48) return false;
|
|
for (let i = 0; i < s.length; i++) {
|
|
const c = s.charCodeAt(i);
|
|
if (c < 48 || c > 57) return false;
|
|
}
|
|
return is_valid_array_index(+s);
|
|
}
|
|
/**
|
|
* Returns the length of the leading run of valid array indices in `keys`.
|
|
* @param {readonly string[]} keys
|
|
*/
|
|
function array_index_cut(keys) {
|
|
for (var i = keys.length - 1; i >= 0; i--) if (is_valid_array_index_string(keys[i])) break;
|
|
return i + 1;
|
|
}
|
|
/**
|
|
* Finds the populated indices of an array.
|
|
* @param {unknown[]} array
|
|
*/
|
|
function valid_array_indices(array) {
|
|
const keys = Object.keys(array);
|
|
keys.length = array_index_cut(keys);
|
|
return keys;
|
|
}
|
|
/**
|
|
* Given the own enumerable string keys of an array-like value, in property
|
|
* order, returns the leading run of them that are valid array indices.
|
|
*
|
|
* This is the filtering half of the `indicesOf` stringify operation,
|
|
* exposed so that custom operations — which typically already have the keys
|
|
* in hand, e.g. from a foreign runtime — don't have to reimplement it.
|
|
*
|
|
* Does not modify `keys`.
|
|
*
|
|
* @param {readonly string[]} keys
|
|
* @returns {string[]}
|
|
*/
|
|
function filter_array_indices(keys) {
|
|
return keys.slice(0, array_index_cut(keys));
|
|
}
|
|
// node_modules/devalue/src/uneval.js
|
|
var chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_$";
|
|
var MIN_STRING_LENGTH = 128;
|
|
var unsafe_chars = /[<\b\f\n\r\t\0\u2028\u2029]/g;
|
|
var reserved = /^(?:do|if|in|for|int|let|new|try|var|byte|case|char|else|enum|goto|long|this|void|with|await|break|catch|class|const|final|float|short|super|throw|while|yield|delete|double|export|import|native|return|switch|throws|typeof|boolean|default|extends|finally|package|private|abstract|continue|debugger|function|volatile|interface|protected|transient|implements|instanceof|synchronized)$/;
|
|
/**
|
|
* Turn a value into the JavaScript that creates an equivalent value
|
|
* @param {any} value
|
|
* @param {(value: any, uneval: (value: any) => string) => string | void} [replacer]
|
|
*/
|
|
function uneval(value, replacer) {
|
|
const counts = /* @__PURE__ */ new Map();
|
|
/** @type {string[]} */
|
|
const keys = [];
|
|
const custom = /* @__PURE__ */ new Map();
|
|
/** @type {Map<string | bigint, string> | undefined} */
|
|
let primitives;
|
|
/** @param {any} thing */
|
|
function stringify_cached_primitive(thing) {
|
|
if (typeof thing === "string" && thing.length >= MIN_STRING_LENGTH || typeof thing === "bigint") {
|
|
primitives ??= /* @__PURE__ */ new Map();
|
|
let literal = primitives.get(thing);
|
|
if (literal === void 0) {
|
|
literal = stringify_primitive$1(thing);
|
|
primitives.set(thing, literal);
|
|
}
|
|
return literal;
|
|
}
|
|
return stringify_primitive$1(thing);
|
|
}
|
|
/** @param {any} thing */
|
|
function walk(thing) {
|
|
if (!is_primitive(thing)) {
|
|
if (counts.has(thing)) {
|
|
counts.set(thing, counts.get(thing) + 1);
|
|
return;
|
|
}
|
|
counts.set(thing, 1);
|
|
if (replacer) {
|
|
const str = replacer(thing, (value) => uneval(value, replacer));
|
|
if (typeof str === "string") {
|
|
custom.set(thing, str);
|
|
return;
|
|
}
|
|
}
|
|
if (typeof thing === "function") throw new DevalueError(`Cannot stringify a function`, keys, thing, value);
|
|
switch (get_type(thing)) {
|
|
case "BigInt":
|
|
case "String":
|
|
walk(thing.valueOf());
|
|
return;
|
|
case "Number":
|
|
case "Boolean":
|
|
case "Date":
|
|
case "RegExp":
|
|
case "URL":
|
|
case "URLSearchParams": return;
|
|
case "Array":
|
|
for (const i of valid_array_indices(thing)) {
|
|
keys.push(`[${i}]`);
|
|
walk(thing[i]);
|
|
keys.pop();
|
|
}
|
|
break;
|
|
case "Set":
|
|
Array.from(thing).forEach(walk);
|
|
break;
|
|
case "Map":
|
|
for (const [key, value] of thing) {
|
|
keys.push(`.get(${is_primitive(key) ? stringify_cached_primitive(key) : "..."})`);
|
|
walk(key);
|
|
walk(value);
|
|
keys.pop();
|
|
}
|
|
break;
|
|
case "Int8Array":
|
|
case "Uint8Array":
|
|
case "Uint8ClampedArray":
|
|
case "Int16Array":
|
|
case "Uint16Array":
|
|
case "Float16Array":
|
|
case "Int32Array":
|
|
case "Uint32Array":
|
|
case "Float32Array":
|
|
case "Float64Array":
|
|
case "BigInt64Array":
|
|
case "BigUint64Array":
|
|
case "DataView":
|
|
if (!is_buffer(thing)) walk(thing.buffer);
|
|
return;
|
|
case "ArrayBuffer": return;
|
|
case "Temporal.Duration":
|
|
case "Temporal.Instant":
|
|
case "Temporal.PlainDate":
|
|
case "Temporal.PlainTime":
|
|
case "Temporal.PlainDateTime":
|
|
case "Temporal.PlainMonthDay":
|
|
case "Temporal.PlainYearMonth":
|
|
case "Temporal.ZonedDateTime": return;
|
|
default:
|
|
if (!is_plain_object(thing)) throw new DevalueError(`Cannot stringify arbitrary non-POJOs`, keys, thing, value);
|
|
if (enumerable_symbols(thing).length > 0) throw new DevalueError(`Cannot stringify POJOs with symbolic keys`, keys, thing, value);
|
|
for (const key of Object.keys(thing)) {
|
|
if (key === "__proto__") throw new DevalueError(`Cannot stringify objects with __proto__ keys`, keys, thing, value);
|
|
keys.push(stringify_key(key));
|
|
walk(thing[key]);
|
|
keys.pop();
|
|
}
|
|
}
|
|
} else if (typeof thing === "symbol") throw new DevalueError(`Cannot stringify a Symbol primitive`, keys, thing, value);
|
|
else if (typeof thing === "string" && thing.length >= MIN_STRING_LENGTH || typeof thing === "bigint") counts.set(thing, (counts.get(thing) || 0) + 1);
|
|
}
|
|
walk(value);
|
|
const names = /* @__PURE__ */ new Map();
|
|
/** @type {Array<[any, number]>} */
|
|
const repeated = [];
|
|
counts.forEach((count, thing) => {
|
|
if (count > 1) repeated.push([thing, count]);
|
|
});
|
|
repeated.sort((a, b) => b[1] - a[1]).forEach(([thing, count]) => {
|
|
const name = get_name(names.size);
|
|
if (is_primitive(thing)) {
|
|
const length = stringify_cached_primitive(thing).length;
|
|
if (length * count <= length + (count + 1) * name.length + 25) return;
|
|
}
|
|
names.set(thing, name);
|
|
});
|
|
/**
|
|
* @param {any} thing
|
|
* @returns {string}
|
|
*/
|
|
function stringify(thing) {
|
|
if (names.has(thing)) return names.get(thing);
|
|
if (is_primitive(thing)) return stringify_primitive$1(thing);
|
|
if (custom.has(thing)) return custom.get(thing);
|
|
const type = get_type(thing);
|
|
switch (type) {
|
|
case "Number":
|
|
case "String":
|
|
case "Boolean":
|
|
case "BigInt": return `Object(${stringify(thing.valueOf())})`;
|
|
case "RegExp":
|
|
const { source, flags } = thing;
|
|
return flags ? `new RegExp(${stringify_string(source)},"${flags}")` : `new RegExp(${stringify_string(source)})`;
|
|
case "Date": return `new Date(${thing.getTime()})`;
|
|
case "URL": return `new URL(${stringify_string(thing.toString())})`;
|
|
case "URLSearchParams": return `new URLSearchParams(${stringify_string(thing.toString())})`;
|
|
case "Array": {
|
|
let has_holes = false;
|
|
let result = "[";
|
|
for (let i = 0; i < thing.length; i += 1) {
|
|
if (i > 0) result += ",";
|
|
if (Object.hasOwn(thing, i)) result += stringify(thing[i]);
|
|
else if (!has_holes) {
|
|
const populated_keys = valid_array_indices(thing);
|
|
const population = populated_keys.length;
|
|
const d = String(thing.length).length;
|
|
const array = stringify_sparse_array(thing.length);
|
|
if (thing.length + 2 > array.length + 18 + population * (d + 2)) return `Object.assign(${array},{${populated_keys.map((k) => `${k}:${stringify(thing[k])}`).join(",")}})`;
|
|
has_holes = true;
|
|
}
|
|
}
|
|
const tail = thing.length === 0 || Object.hasOwn(thing, thing.length - 1) ? "" : ",";
|
|
return result + tail + "]";
|
|
}
|
|
case "Set":
|
|
case "Map": return `new ${type}([${Array.from(thing).map(stringify).join(",")}])`;
|
|
case "Int8Array":
|
|
case "Uint8Array":
|
|
case "Uint8ClampedArray":
|
|
case "Int16Array":
|
|
case "Uint16Array":
|
|
case "Float16Array":
|
|
case "Int32Array":
|
|
case "Uint32Array":
|
|
case "Float32Array":
|
|
case "Float64Array":
|
|
case "BigInt64Array":
|
|
case "BigUint64Array": {
|
|
if (is_buffer(thing)) thing = new Uint8Array(thing);
|
|
let str = `new ${type}`;
|
|
if (!names.has(thing.buffer)) str += `([${stringify_typed_array_elements(type, thing.buffer)}])`;
|
|
else str += `(${stringify(thing.buffer)})`;
|
|
if (thing.byteLength !== thing.buffer.byteLength) {
|
|
const start = thing.byteOffset / thing.BYTES_PER_ELEMENT;
|
|
const end = start + thing.length;
|
|
str += `.subarray(${start},${end})`;
|
|
}
|
|
return str;
|
|
}
|
|
case "DataView": {
|
|
let str = `new DataView`;
|
|
if (!names.has(thing.buffer)) str += `(new Uint8Array([${new Uint8Array(thing.buffer)}]).buffer`;
|
|
else str += `(${stringify(thing.buffer)}`;
|
|
if (thing.byteLength !== thing.buffer.byteLength) str += `,${thing.byteOffset},${thing.byteLength}`;
|
|
return str + ")";
|
|
}
|
|
case "ArrayBuffer": return `new Uint8Array([${new Uint8Array(thing).toString()}]).buffer`;
|
|
case "Temporal.Duration":
|
|
case "Temporal.Instant":
|
|
case "Temporal.PlainDate":
|
|
case "Temporal.PlainTime":
|
|
case "Temporal.PlainDateTime":
|
|
case "Temporal.PlainMonthDay":
|
|
case "Temporal.PlainYearMonth":
|
|
case "Temporal.ZonedDateTime": return `${type}.from(${stringify_string(thing.toString())})`;
|
|
default:
|
|
const keys = Object.keys(thing);
|
|
const obj = keys.map((key) => `${safe_key(key)}:${stringify(thing[key])}`).join(",");
|
|
if (Object.getPrototypeOf(thing) === null) return keys.length > 0 ? `{${obj},__proto__:null}` : `{__proto__:null}`;
|
|
return `{${obj}}`;
|
|
}
|
|
}
|
|
const str = stringify(value);
|
|
if (names.size) {
|
|
/** @type {string[]} */
|
|
const params = [];
|
|
/** @type {string[]} */
|
|
const statements = [];
|
|
/** @type {string[]} */
|
|
const values = [];
|
|
/** @type {string[]} */
|
|
const reconstructions = [];
|
|
names.forEach((name, thing) => {
|
|
params.push(name);
|
|
if (custom.has(thing)) {
|
|
values.push(custom.get(thing));
|
|
return;
|
|
}
|
|
if (is_primitive(thing)) {
|
|
values.push(stringify_cached_primitive(thing));
|
|
return;
|
|
}
|
|
const type = get_type(thing);
|
|
switch (type) {
|
|
case "Number":
|
|
case "String":
|
|
case "Boolean":
|
|
case "BigInt": {
|
|
const primitive = thing.valueOf();
|
|
if (names.has(primitive)) {
|
|
values.push("{}");
|
|
reconstructions.push(`${name}=Object(${stringify(primitive)})`);
|
|
} else values.push(`Object(${stringify(primitive)})`);
|
|
break;
|
|
}
|
|
case "RegExp":
|
|
const { source, flags } = thing;
|
|
const regexp = flags ? `new RegExp(${stringify_string(source)},"${flags}")` : `new RegExp(${stringify_string(source)})`;
|
|
values.push(regexp);
|
|
break;
|
|
case "Date":
|
|
values.push(`new Date(${thing.getTime()})`);
|
|
break;
|
|
case "URL":
|
|
values.push(`new URL(${stringify_string(thing.toString())})`);
|
|
break;
|
|
case "URLSearchParams":
|
|
values.push(`new URLSearchParams(${stringify_string(thing.toString())})`);
|
|
break;
|
|
case "Array": {
|
|
const populated_keys = valid_array_indices(thing);
|
|
values.push(thing.length > 32 + 2 * populated_keys.length ? stringify_sparse_array(thing.length) : `Array(${thing.length})`);
|
|
for (const i of populated_keys) statements.push(`${name}[${i}]=${stringify(thing[i])}`);
|
|
break;
|
|
}
|
|
case "Set": {
|
|
values.push(`new Set`);
|
|
const adds = Array.from(thing).map((v) => `.add(${stringify(v)})`);
|
|
if (adds.length > 0) statements.push(name + adds.join(""));
|
|
break;
|
|
}
|
|
case "Map": {
|
|
values.push(`new Map`);
|
|
const sets = Array.from(thing).map(([k, v]) => `.set(${stringify(k)}, ${stringify(v)})`);
|
|
if (sets.length > 0) statements.push(name + sets.join(""));
|
|
break;
|
|
}
|
|
case "Int8Array":
|
|
case "Uint8Array":
|
|
case "Uint8ClampedArray":
|
|
case "Int16Array":
|
|
case "Uint16Array":
|
|
case "Float16Array":
|
|
case "Int32Array":
|
|
case "Uint32Array":
|
|
case "Float32Array":
|
|
case "Float64Array":
|
|
case "BigInt64Array":
|
|
case "BigUint64Array": {
|
|
if (is_buffer(thing)) thing = new Uint8Array(thing);
|
|
let str = `new ${type}`;
|
|
if (!names.has(thing.buffer)) str += `([${stringify_typed_array_elements(type, thing.buffer)}])`;
|
|
else str += `(${stringify(thing.buffer)})`;
|
|
if (thing.byteLength !== thing.buffer.byteLength) {
|
|
const start = thing.byteOffset / thing.BYTES_PER_ELEMENT;
|
|
const end = start + thing.length;
|
|
str += `.subarray(${start},${end})`;
|
|
}
|
|
values.push(`{}`);
|
|
reconstructions.push(`${name}=${str}`);
|
|
break;
|
|
}
|
|
case "DataView": {
|
|
let str = `new DataView`;
|
|
if (!names.has(thing.buffer)) str += `(new Uint8Array([${new Uint8Array(thing.buffer)}]).buffer`;
|
|
else str += `(${stringify(thing.buffer)}`;
|
|
if (thing.byteLength !== thing.buffer.byteLength) str += `,${thing.byteOffset},${thing.byteLength}`;
|
|
str += ")";
|
|
values.push(`{}`);
|
|
reconstructions.push(`${name}=${str}`);
|
|
break;
|
|
}
|
|
case "ArrayBuffer":
|
|
values.push(`new Uint8Array([${new Uint8Array(thing)}]).buffer`);
|
|
break;
|
|
case "Temporal.Duration":
|
|
case "Temporal.Instant":
|
|
case "Temporal.PlainDate":
|
|
case "Temporal.PlainTime":
|
|
case "Temporal.PlainDateTime":
|
|
case "Temporal.PlainMonthDay":
|
|
case "Temporal.PlainYearMonth":
|
|
case "Temporal.ZonedDateTime":
|
|
values.push(`${type}.from(${stringify_string(thing.toString())})`);
|
|
break;
|
|
default:
|
|
values.push(Object.getPrototypeOf(thing) === null ? "Object.create(null)" : "{}");
|
|
Object.keys(thing).forEach((key) => {
|
|
statements.push(`${name}${safe_prop(key)}=${stringify(thing[key])}`);
|
|
});
|
|
}
|
|
});
|
|
statements.push(`return ${str}`);
|
|
const body = [...reconstructions, ...statements].join(";");
|
|
if (params.length > 65534) return `(function(){var[${params.join(",")}]=arguments[0];${body}}([${values.join(",")}]))`;
|
|
return `(function(${params.join(",")}){${body}}(${values.join(",")}))`;
|
|
} else return str;
|
|
}
|
|
/**
|
|
* Emit an array whose storage is not proportional to its declared length.
|
|
* As in the default parse operations, touching and deleting the largest valid
|
|
* index forces V8 into dictionary-elements mode before setting the length.
|
|
* Merely starting with [] and assigning .length still eagerly allocates.
|
|
* @param {number} length
|
|
*/
|
|
function stringify_sparse_array(length) {
|
|
return `(function(a){a[${MAX_ARRAY_INDEX}]=0;delete a[${MAX_ARRAY_INDEX}];a.length=${length};return a}([]))`;
|
|
}
|
|
/**
|
|
* Serialize the elements of `buffer`, read as `type`, as a comma-separated list.
|
|
* The view is created from `type` rather than from the serialized value's own
|
|
* constructor, which may be a subclass like Node's `Buffer` whose `toString`
|
|
* decodes the bytes instead of listing them.
|
|
* `BigInt64Array`/`BigUint64Array` elements are bigints and must be written
|
|
* with an `n` suffix, otherwise the emitted `new BigInt64Array([...])` throws.
|
|
* @param {string} type
|
|
* @param {ArrayBufferLike} buffer
|
|
*/
|
|
function stringify_typed_array_elements(type, buffer) {
|
|
const array = new globalThis[type](buffer);
|
|
if (type === "BigInt64Array" || type === "BigUint64Array") return Array.from(array, (element) => `${element}n`).join(",");
|
|
if (array instanceof Float32Array || array instanceof Float64Array || typeof Float16Array !== "undefined" && array instanceof Float16Array) return Array.from(array, (element) => Object.is(element, -0) ? "-0" : `${element}`).join(",");
|
|
return array.toString();
|
|
}
|
|
/** @param {number} num */
|
|
function get_name(num) {
|
|
let name = "";
|
|
do {
|
|
name = chars[num % 54] + name;
|
|
num = ~~(num / 54) - 1;
|
|
} while (num >= 0);
|
|
return reserved.test(name) ? `${name}0` : name;
|
|
}
|
|
/** @param {string} c */
|
|
function escape_unsafe_char(c) {
|
|
return escaped[c] || c;
|
|
}
|
|
/** @param {string} str */
|
|
function escape_unsafe_chars(str) {
|
|
return str.replace(unsafe_chars, escape_unsafe_char);
|
|
}
|
|
/** @param {string} key */
|
|
function safe_key(key) {
|
|
return /^[_$a-zA-Z][_$a-zA-Z0-9]*$/.test(key) ? key : escape_unsafe_chars(JSON.stringify(key));
|
|
}
|
|
/** @param {string} key */
|
|
function safe_prop(key) {
|
|
return /^[_$a-zA-Z][_$a-zA-Z0-9]*$/.test(key) ? `.${key}` : `[${escape_unsafe_chars(JSON.stringify(key))}]`;
|
|
}
|
|
/** @param {any} thing */
|
|
function stringify_primitive$1(thing) {
|
|
const type = typeof thing;
|
|
if (type === "string") return stringify_string(thing);
|
|
if (thing === void 0) return "void 0";
|
|
if (thing === 0 && 1 / thing < 0) return "-0";
|
|
const str = String(thing);
|
|
if (type === "number") return str.replace(/^(-)?0\./, "$1.");
|
|
if (type === "bigint") return thing + "n";
|
|
return str;
|
|
}
|
|
// node_modules/devalue/src/base64.js
|
|
/** @type {(array_buffer: ArrayBuffer) => string} */
|
|
function encode_native(array_buffer) {
|
|
return new Uint8Array(array_buffer).toBase64();
|
|
}
|
|
/** @type {(base64: string) => ArrayBuffer} */
|
|
function decode_native(base64) {
|
|
return Uint8Array.fromBase64(base64).buffer;
|
|
}
|
|
/** @type {(array_buffer: ArrayBuffer) => string} */
|
|
function encode_buffer(array_buffer) {
|
|
return Buffer.from(array_buffer).toString("base64");
|
|
}
|
|
/** @type {(base64: string) => ArrayBuffer} */
|
|
function decode_buffer(base64) {
|
|
return Uint8Array.from(Buffer.from(base64, "base64")).buffer;
|
|
}
|
|
/** @type {(array_buffer: ArrayBuffer) => string} */
|
|
function encode_legacy(array_buffer) {
|
|
const array = new Uint8Array(array_buffer);
|
|
let binary = "";
|
|
const chunk_size = 32768;
|
|
for (let i = 0; i < array.length; i += chunk_size) {
|
|
const chunk = array.subarray(i, i + chunk_size);
|
|
binary += String.fromCharCode.apply(null, chunk);
|
|
}
|
|
return btoa(binary);
|
|
}
|
|
/** @type {(base64: string) => ArrayBuffer} */
|
|
function decode_legacy(base64) {
|
|
const binary_string = atob(base64);
|
|
const len = binary_string.length;
|
|
const array = new Uint8Array(len);
|
|
for (let i = 0; i < len; i++) array[i] = binary_string.charCodeAt(i);
|
|
return array.buffer;
|
|
}
|
|
var native = typeof Uint8Array.fromBase64 === "function";
|
|
var buffer = typeof process === "object" && process.versions?.node !== void 0;
|
|
var encode64 = native ? encode_native : buffer ? encode_buffer : encode_legacy;
|
|
var decode64 = native ? decode_native : buffer ? decode_buffer : decode_legacy;
|
|
// node_modules/devalue/src/operations.js
|
|
/**
|
|
* Merges caller-provided operation overrides over the defaults. Iterating the
|
|
* default keys (rather than the override's own keys) means nullish members
|
|
* fall back to the default, and inherited members — e.g. from a class
|
|
* instance — are picked up.
|
|
*
|
|
* @template {Record<string, any>} T
|
|
* @param {T} defaults
|
|
* @param {Partial<T> | undefined} overrides
|
|
* @returns {T}
|
|
*/
|
|
function merge_operations(defaults, overrides) {
|
|
if (!overrides) return defaults;
|
|
const merged = {};
|
|
for (const key of Object.keys(defaults)) merged[key] = overrides[key] ?? defaults[key];
|
|
return merged;
|
|
}
|
|
/** @type {{ kind: 'not-plain' }} */
|
|
var NOT_PLAIN = /* @__PURE__ */ Object.freeze({ kind: "not-plain" });
|
|
/** @type {{ kind: 'symbol-keys' }} */
|
|
var SYMBOL_KEYS = /* @__PURE__ */ Object.freeze({ kind: "symbol-keys" });
|
|
var default_stringify_operations = /* @__PURE__ */ Object.freeze({
|
|
identify: (value) => value,
|
|
typeOf: (value) => value === null ? "null" : typeof value,
|
|
toPrimitive: (value) => value,
|
|
tagOf: (value) => get_type(value),
|
|
isThenable: (value) => typeof value.then === "function",
|
|
toPromise: (thenable) => Promise.resolve(thenable),
|
|
unbox: (boxed) => boxed.valueOf(),
|
|
toISOString: (date) => isNaN(date.getDate()) ? "" : date.toISOString(),
|
|
toStringValue: (value) => value.toString(),
|
|
regExpInfo: (regexp) => ({
|
|
source: regexp.source,
|
|
flags: regexp.flags
|
|
}),
|
|
valuesOf: (set) => set,
|
|
entriesOf: (map) => map,
|
|
viewInfo: (view) => {
|
|
if (is_buffer(view)) view = new Uint8Array(view);
|
|
return {
|
|
buffer: view.buffer,
|
|
byteOffset: view.byteOffset,
|
|
byteLength: view.byteLength,
|
|
length: view.length,
|
|
bufferByteLength: view.buffer.byteLength
|
|
};
|
|
},
|
|
toArrayBuffer: (buffer) => buffer,
|
|
lengthOf: (array) => array.length,
|
|
hasOwn: (value, key) => Object.hasOwn(value, key),
|
|
indicesOf: (array) => valid_array_indices(array),
|
|
shapeOf: (value) => {
|
|
if (!is_plain_object(value)) return NOT_PLAIN;
|
|
if (enumerable_symbols(value).length > 0) return SYMBOL_KEYS;
|
|
return {
|
|
kind: Object.getPrototypeOf(value) === null ? "null-proto" : "plain",
|
|
keys: Object.keys(value)
|
|
};
|
|
},
|
|
get: (value, key) => value[key]
|
|
});
|
|
var array_buffer_byte_length = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "byteLength").get;
|
|
var shared_array_buffer_byte_length = typeof SharedArrayBuffer === "undefined" ? void 0 : Object.getOwnPropertyDescriptor(SharedArrayBuffer.prototype, "byteLength").get;
|
|
var default_parse_operations = /* @__PURE__ */ Object.freeze({
|
|
fromPrimitive: (primitive) => primitive,
|
|
fromISOString: (iso) => new Date(iso),
|
|
fromStringValue: (tag, text) => {
|
|
if (tag === "URL") return new URL(text);
|
|
if (tag === "URLSearchParams") return new URLSearchParams(text);
|
|
return Temporal[tag.slice(9)].from(text);
|
|
},
|
|
fromArrayBuffer: (buffer) => buffer,
|
|
fromRegExpInfo: (source, flags) => new RegExp(source, flags),
|
|
fromViewInfo: (tag, buffer, byteOffset, length) => {
|
|
try {
|
|
array_buffer_byte_length.call(buffer);
|
|
} catch (error) {
|
|
if (!shared_array_buffer_byte_length) throw error;
|
|
shared_array_buffer_byte_length.call(buffer);
|
|
}
|
|
const Constructor = globalThis[tag];
|
|
return byteOffset !== void 0 ? new Constructor(buffer, byteOffset, length) : new Constructor(buffer);
|
|
},
|
|
box: (value) => Object(value),
|
|
createArray: (length) => new Array(length),
|
|
createSparseArray: (length) => {
|
|
/** @type {any[]} */
|
|
const array = [];
|
|
array[MAX_ARRAY_INDEX] = void 0;
|
|
delete array[MAX_ARRAY_INDEX];
|
|
array.length = length;
|
|
return array;
|
|
},
|
|
createObject: () => ({}),
|
|
createNullPrototypeObject: () => Object.create(null),
|
|
createSet: () => /* @__PURE__ */ new Set(),
|
|
createMap: () => /* @__PURE__ */ new Map(),
|
|
set: (target, key, value) => {
|
|
target[key] = value;
|
|
},
|
|
addValue: (set, value) => {
|
|
set.add(value);
|
|
},
|
|
addEntry: (map, key, value) => {
|
|
map.set(key, value);
|
|
}
|
|
});
|
|
// node_modules/devalue/src/parse.js
|
|
/**
|
|
* Revive a value serialized with `devalue.stringify`
|
|
* @param {string} serialized
|
|
* @param {Record<string, (value: any) => any>} [revivers]
|
|
* @param {import('./types.js').ParseOptions} [options]
|
|
*/
|
|
function parse(serialized, revivers, options) {
|
|
return unflatten(JSON.parse(serialized), revivers, options);
|
|
}
|
|
/**
|
|
* Revive a value flattened with `devalue.stringify`
|
|
* @param {number | any[]} parsed
|
|
* @param {Record<string, (value: any) => any>} [revivers]
|
|
* @param {import('./types.js').ParseOptions} [options]
|
|
*/
|
|
function unflatten(parsed, revivers, options) {
|
|
/** @type {import('./types.js').ParseOperations} */
|
|
const ops = merge_operations(default_parse_operations, options?.operations);
|
|
if (typeof parsed === "number") return hydrate(parsed, true);
|
|
if (!Array.isArray(parsed) || parsed.length === 0) throw new Error("Invalid input");
|
|
const values = parsed;
|
|
const hydrated = Array(values.length);
|
|
/**
|
|
* A set of values currently being hydrated with custom revivers,
|
|
* used to detect invalid cyclical dependencies
|
|
* @type {Set<number> | null}
|
|
*/
|
|
let hydrating = null;
|
|
/**
|
|
* @param {number} index
|
|
* @returns {any}
|
|
*/
|
|
function hydrate(index, standalone = false) {
|
|
if (index === -1) return ops.fromPrimitive(void 0);
|
|
if (index === -3) return ops.fromPrimitive(NaN);
|
|
if (index === -4) return ops.fromPrimitive(Infinity);
|
|
if (index === -5) return ops.fromPrimitive(-Infinity);
|
|
if (index === -6) return ops.fromPrimitive(-0);
|
|
if (standalone || typeof index !== "number") throw new Error(`Invalid input`);
|
|
if (index in hydrated) return hydrated[index];
|
|
if (index >= values.length) throw new Error(`Invalid input`);
|
|
const value = values[index];
|
|
if (!value || typeof value !== "object") hydrated[index] = ops.fromPrimitive(value);
|
|
else if (Array.isArray(value)) {
|
|
if (typeof value[0] === "string") {
|
|
const type = value[0];
|
|
const reviver = revivers && Object.hasOwn(revivers, type) ? revivers[type] : void 0;
|
|
if (reviver) {
|
|
let i = value[1];
|
|
if (typeof i !== "number") i = values.push(value[1]) - 1;
|
|
if (Object.hasOwn(hydrated, i)) return hydrated[index] = reviver(hydrated[i]);
|
|
hydrating ??= /* @__PURE__ */ new Set();
|
|
if (hydrating.has(i)) throw new Error("Invalid circular reference");
|
|
hydrating.add(i);
|
|
hydrated[index] = reviver(hydrate(i));
|
|
hydrating.delete(i);
|
|
return hydrated[index];
|
|
}
|
|
switch (type) {
|
|
case "Date":
|
|
hydrated[index] = ops.fromISOString(value[1]);
|
|
break;
|
|
case "Set":
|
|
const set = ops.createSet();
|
|
hydrated[index] = set;
|
|
for (let i = 1; i < value.length; i += 1) ops.addValue(set, hydrate(value[i]));
|
|
break;
|
|
case "Map":
|
|
const map = ops.createMap();
|
|
hydrated[index] = map;
|
|
for (let i = 1; i < value.length; i += 2) ops.addEntry(map, hydrate(value[i]), hydrate(value[i + 1]));
|
|
break;
|
|
case "RegExp":
|
|
hydrated[index] = ops.fromRegExpInfo(value[1], value[2]);
|
|
break;
|
|
case "Object": {
|
|
const wrapped_index = value[1];
|
|
if (typeof values[wrapped_index] === "object" && values[wrapped_index][0] !== "BigInt") throw new Error("Invalid input");
|
|
hydrated[index] = ops.box(hydrate(wrapped_index));
|
|
break;
|
|
}
|
|
case "BigInt":
|
|
hydrated[index] = ops.fromPrimitive(BigInt(value[1]));
|
|
break;
|
|
case "null":
|
|
const obj = ops.createNullPrototypeObject();
|
|
hydrated[index] = obj;
|
|
for (let i = 1; i < value.length; i += 2) {
|
|
const key = value[i];
|
|
if (typeof key !== "string") throw new Error("Cannot parse an object with a non-string key");
|
|
if (key === "__proto__") throw new Error("Cannot parse an object with a `__proto__` property");
|
|
ops.set(obj, key, hydrate(value[i + 1]));
|
|
}
|
|
break;
|
|
case "Int8Array":
|
|
case "Uint8Array":
|
|
case "Uint8ClampedArray":
|
|
case "Int16Array":
|
|
case "Uint16Array":
|
|
case "Float16Array":
|
|
case "Int32Array":
|
|
case "Uint32Array":
|
|
case "Float32Array":
|
|
case "Float64Array":
|
|
case "BigInt64Array":
|
|
case "BigUint64Array":
|
|
case "DataView": {
|
|
if (values[value[1]][0] !== "ArrayBuffer") throw new Error("Invalid data");
|
|
const buffer = hydrate(value[1]);
|
|
hydrated[index] = ops.fromViewInfo(type, buffer, value[2], value[3]);
|
|
break;
|
|
}
|
|
case "ArrayBuffer": {
|
|
const base64 = value[1];
|
|
if (typeof base64 !== "string") throw new Error("Invalid ArrayBuffer encoding");
|
|
hydrated[index] = ops.fromArrayBuffer(decode64(base64));
|
|
break;
|
|
}
|
|
case "URL":
|
|
case "URLSearchParams":
|
|
case "Temporal.Duration":
|
|
case "Temporal.Instant":
|
|
case "Temporal.PlainDate":
|
|
case "Temporal.PlainTime":
|
|
case "Temporal.PlainDateTime":
|
|
case "Temporal.PlainMonthDay":
|
|
case "Temporal.PlainYearMonth":
|
|
case "Temporal.ZonedDateTime":
|
|
hydrated[index] = ops.fromStringValue(type, value[1]);
|
|
break;
|
|
default: throw new Error(`Unknown type ${type}`);
|
|
}
|
|
} else if (value[0] === -7) {
|
|
const len = value[1];
|
|
if (!is_valid_array_len(len)) throw new Error("Invalid input");
|
|
const array = ops.createSparseArray(len);
|
|
hydrated[index] = array;
|
|
for (let i = 2; i < value.length; i += 2) {
|
|
const idx = value[i];
|
|
if (!is_valid_array_index(idx) || idx >= len) throw new Error("Invalid input");
|
|
ops.set(array, idx, hydrate(value[i + 1]));
|
|
}
|
|
} else {
|
|
const array = ops.createArray(value.length);
|
|
hydrated[index] = array;
|
|
for (let i = 0; i < value.length; i += 1) {
|
|
const n = value[i];
|
|
if (n === -2) continue;
|
|
ops.set(array, i, hydrate(n));
|
|
}
|
|
}
|
|
} else {
|
|
const object = ops.createObject();
|
|
hydrated[index] = object;
|
|
for (const key of Object.keys(value)) {
|
|
if (key === "__proto__") throw new Error("Cannot parse an object with a `__proto__` property");
|
|
ops.set(object, key, hydrate(value[key]));
|
|
}
|
|
}
|
|
return hydrated[index];
|
|
}
|
|
return hydrate(0);
|
|
}
|
|
// node_modules/devalue/src/stringify.js
|
|
/**
|
|
* Turn a value into a JSON string that can be parsed with `devalue.parse`
|
|
* @param {any} value
|
|
* @param {Record<string, (value: any) => any>} [reducers]
|
|
* @param {import('./types.js').StringifyOptions} [options]
|
|
*/
|
|
function stringify(value, reducers, options) {
|
|
const stringified = run(false, value, reducers, options);
|
|
return typeof stringified === "string" ? stringified : `[${stringified.join(",")}]`;
|
|
}
|
|
/**
|
|
* Turn a value into a JSON string that can be parsed with `devalue.parse`
|
|
* @param {any} value
|
|
* @param {Record<string, (value: any) => any>} [reducers]
|
|
* @param {import('./types.js').StringifyOptions} [options]
|
|
*/
|
|
async function stringifyAsync(value, reducers, options) {
|
|
const stringified = run(true, value, reducers, options);
|
|
if (typeof stringified === "string") return stringified;
|
|
let out = "[";
|
|
for (let i = 0; i < stringified.length; i += 1) {
|
|
let value = stringified[i];
|
|
if (typeof value !== "string") {
|
|
await value;
|
|
value = stringified[i];
|
|
if (i === 0 && value < 0) return `${value}`;
|
|
}
|
|
out += value;
|
|
if (i < stringified.length - 1) out += ",";
|
|
}
|
|
out += "]";
|
|
return out;
|
|
}
|
|
/**
|
|
* @param {boolean} async
|
|
* @param {any} value
|
|
* @param {Record<string, (value: any) => any>} [reducers]
|
|
* @param {import('./types.js').StringifyOptions} [options]
|
|
*/
|
|
function run(async, value, reducers, options) {
|
|
const ops = merge_operations(default_stringify_operations, options?.operations);
|
|
/** @type {any[]} */
|
|
const stringified = [];
|
|
/** @type {Map<any, number>} */
|
|
const indexes = /* @__PURE__ */ new Map();
|
|
/** @type {Array<{ key: string, fn: (value: any) => any }>} */
|
|
const custom = [];
|
|
if (reducers) for (const key of Object.getOwnPropertyNames(reducers)) custom.push({
|
|
key,
|
|
fn: reducers[key]
|
|
});
|
|
/** @type {string[]} */
|
|
const keys = [];
|
|
let p = 0;
|
|
/**
|
|
* @param {any} thing
|
|
* @param {number} [index]
|
|
*/
|
|
function flatten(thing, index) {
|
|
const type = ops.typeOf(thing);
|
|
if (type === "undefined") return -1;
|
|
/** @type {number | undefined} */
|
|
let number;
|
|
if (type === "number") {
|
|
number = ops.toPrimitive(thing);
|
|
if (Number.isNaN(number)) return -3;
|
|
if (number === Infinity) return -4;
|
|
if (number === -Infinity) return -5;
|
|
if (number === 0 && 1 / number < 0) return -6;
|
|
}
|
|
const id = ops.identify(thing);
|
|
if (indexes.has(id)) return indexes.get(id);
|
|
index ??= p++;
|
|
indexes.set(id, index);
|
|
for (const { key, fn } of custom) {
|
|
const value = fn(thing);
|
|
if (value) {
|
|
stringified[index] = `["${key}",${flatten(value)}]`;
|
|
return index;
|
|
}
|
|
}
|
|
if (type === "function") throw new DevalueError(`Cannot stringify a function`, keys, thing, value);
|
|
else if (type === "symbol") throw new DevalueError(`Cannot stringify a Symbol primitive`, keys, thing, value);
|
|
/** @type {string | Promise<any>} */
|
|
let str = "";
|
|
if (type !== "object") str = stringify_primitive(type === "number" ? number : ops.toPrimitive(thing));
|
|
else if (ops.isThenable(thing)) {
|
|
if (!async) throw new DevalueError(`Cannot stringify a Promise or thenable — use stringifyAsync instead`, keys, thing, value);
|
|
str = ops.toPromise(thing).then((value) => {
|
|
const i = flatten(value, index);
|
|
if (i < 0) stringified[index] = i;
|
|
});
|
|
str.catch(() => {});
|
|
} else {
|
|
const tag = ops.tagOf(thing);
|
|
switch (tag) {
|
|
case "Number":
|
|
case "String":
|
|
case "Boolean":
|
|
case "BigInt":
|
|
str = `["Object",${flatten(ops.unbox(thing))}]`;
|
|
break;
|
|
case "Date":
|
|
str = `["Date","${ops.toISOString(thing)}"]`;
|
|
break;
|
|
case "URL":
|
|
str = `["URL",${stringify_string(ops.toStringValue(thing))}]`;
|
|
break;
|
|
case "URLSearchParams":
|
|
str = `["URLSearchParams",${stringify_string(ops.toStringValue(thing))}]`;
|
|
break;
|
|
case "RegExp":
|
|
const { source, flags } = ops.regExpInfo(thing);
|
|
str = flags ? `["RegExp",${stringify_string(source)},"${flags}"]` : `["RegExp",${stringify_string(source)}]`;
|
|
break;
|
|
case "Array": {
|
|
let mostly_dense = false;
|
|
const length = ops.lengthOf(thing);
|
|
str = "[";
|
|
for (let i = 0; i < length; i += 1) {
|
|
if (i > 0) str += ",";
|
|
if (ops.hasOwn(thing, i)) {
|
|
keys.push(`[${i}]`);
|
|
str += flatten(ops.get(thing, i));
|
|
keys.pop();
|
|
} else if (mostly_dense) str += -2;
|
|
else {
|
|
const populated_keys = ops.indicesOf(thing);
|
|
const population = populated_keys.length;
|
|
const d = String(length).length;
|
|
if ((length - population) * 3 > 4 + d + population * (d + 1)) {
|
|
str = "[-7," + length;
|
|
for (let j = 0; j < populated_keys.length; j++) {
|
|
const key = populated_keys[j];
|
|
keys.push(`[${key}]`);
|
|
str += "," + key + "," + flatten(ops.get(thing, key));
|
|
keys.pop();
|
|
}
|
|
break;
|
|
} else {
|
|
mostly_dense = true;
|
|
str += -2;
|
|
}
|
|
}
|
|
}
|
|
str += "]";
|
|
break;
|
|
}
|
|
case "Set":
|
|
str = "[\"Set\"";
|
|
for (const value of ops.valuesOf(thing)) str += `,${flatten(value)}`;
|
|
str += "]";
|
|
break;
|
|
case "Map":
|
|
str = "[\"Map\"";
|
|
for (const [key, value] of ops.entriesOf(thing)) {
|
|
const key_type = ops.typeOf(key);
|
|
const key_is_primitive = key_type !== "object" && key_type !== "function" && key_type !== "symbol";
|
|
keys.push(`.get(${key_is_primitive ? stringify_primitive(ops.toPrimitive(key)) : "..."})`);
|
|
str += `,${flatten(key)},${flatten(value)}`;
|
|
keys.pop();
|
|
}
|
|
str += "]";
|
|
break;
|
|
case "Int8Array":
|
|
case "Uint8Array":
|
|
case "Uint8ClampedArray":
|
|
case "Int16Array":
|
|
case "Uint16Array":
|
|
case "Float16Array":
|
|
case "Int32Array":
|
|
case "Uint32Array":
|
|
case "Float32Array":
|
|
case "Float64Array":
|
|
case "BigInt64Array":
|
|
case "BigUint64Array": {
|
|
const info = ops.viewInfo(thing);
|
|
str = "[\"" + tag + "\"," + flatten(info.buffer);
|
|
if (info.byteLength !== info.bufferByteLength) str += `,${info.byteOffset},${info.length}`;
|
|
str += "]";
|
|
break;
|
|
}
|
|
case "DataView": {
|
|
const info = ops.viewInfo(thing);
|
|
str = "[\"" + tag + "\"," + flatten(info.buffer);
|
|
if (info.byteLength !== info.bufferByteLength) str += `,${info.byteOffset},${info.byteLength}`;
|
|
str += "]";
|
|
break;
|
|
}
|
|
case "ArrayBuffer":
|
|
str = `["ArrayBuffer","${encode64(ops.toArrayBuffer(thing))}"]`;
|
|
break;
|
|
case "Temporal.Duration":
|
|
case "Temporal.Instant":
|
|
case "Temporal.PlainDate":
|
|
case "Temporal.PlainTime":
|
|
case "Temporal.PlainDateTime":
|
|
case "Temporal.PlainMonthDay":
|
|
case "Temporal.PlainYearMonth":
|
|
case "Temporal.ZonedDateTime":
|
|
str = `["${tag}",${stringify_string(ops.toStringValue(thing))}]`;
|
|
break;
|
|
default: {
|
|
const shape = ops.shapeOf(thing);
|
|
if (shape.kind === "not-plain") throw new DevalueError(`Cannot stringify arbitrary non-POJOs`, keys, thing, value);
|
|
if (shape.kind === "symbol-keys") throw new DevalueError(`Cannot stringify POJOs with symbolic keys`, keys, thing, value);
|
|
if (shape.kind === "null-proto") {
|
|
str = "[\"null\"";
|
|
for (const key of shape.keys) {
|
|
if (key === "__proto__") throw new DevalueError(`Cannot stringify objects with __proto__ keys`, keys, thing, value);
|
|
keys.push(stringify_key(key));
|
|
str += `,${stringify_string(key)},${flatten(ops.get(thing, key))}`;
|
|
keys.pop();
|
|
}
|
|
str += "]";
|
|
} else {
|
|
str = "{";
|
|
let started = false;
|
|
for (const key of shape.keys) {
|
|
if (key === "__proto__") throw new DevalueError(`Cannot stringify objects with __proto__ keys`, keys, thing, value);
|
|
if (started) str += ",";
|
|
started = true;
|
|
keys.push(stringify_key(key));
|
|
str += `${stringify_string(key)}:${flatten(ops.get(thing, key))}`;
|
|
keys.pop();
|
|
}
|
|
str += "}";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
stringified[index] = str;
|
|
return index;
|
|
}
|
|
const index = flatten(value);
|
|
if (index < 0) return `${index}`;
|
|
return stringified;
|
|
}
|
|
/**
|
|
* @param {any} thing
|
|
* @returns {string}
|
|
*/
|
|
function stringify_primitive(thing) {
|
|
const type = typeof thing;
|
|
if (type === "string") return stringify_string(thing);
|
|
if (thing === void 0) return (-1).toString();
|
|
if (thing === 0 && 1 / thing < 0) return (-6).toString();
|
|
if (type === "bigint") return `["BigInt","${thing}"]`;
|
|
return String(thing);
|
|
}
|
|
// node_modules/devalue/index.js
|
|
/** @typedef {import('./src/types.js').StringValueTag} StringValueTag */
|
|
/** @typedef {import('./src/types.js').ViewTag} ViewTag */
|
|
/** @typedef {import('./src/types.js').StringifyOperations} StringifyOperations */
|
|
/** @typedef {import('./src/types.js').DefaultStringifyOperations} DefaultStringifyOperations */
|
|
/** @typedef {import('./src/types.js').StringifyOptions} StringifyOptions */
|
|
/** @typedef {import('./src/types.js').ParseOperations} ParseOperations */
|
|
/** @typedef {import('./src/types.js').DefaultParseOperations} DefaultParseOperations */
|
|
/** @typedef {import('./src/types.js').ParseOptions} ParseOptions */
|
|
export { DevalueError, default_parse_operations as defaultParseOperations, default_stringify_operations as defaultStringifyOperations, filter_array_indices as filterArrayIndices, parse, stringify, stringifyAsync, uneval, unflatten };
|