Files
discord-clone/node_modules/nuxi/dist/shared/nuxi.e90bf846.mjs
2023-01-03 09:29:04 -06:00

53 lines
1.4 KiB
JavaScript

const suspectProtoRx = /"(?:_|\\u0{2}5[Ff]){2}(?:p|\\u0{2}70)(?:r|\\u0{2}72)(?:o|\\u0{2}6[Ff])(?:t|\\u0{2}74)(?:o|\\u0{2}6[Ff])(?:_|\\u0{2}5[Ff]){2}"\s*:/;
const suspectConstructorRx = /"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/;
const JsonSigRx = /^["[{]|^-?\d[\d.]{0,14}$/;
function jsonParseTransform(key, value) {
if (key === "__proto__" || key === "constructor") {
return;
}
return value;
}
function destr(value, options = {}) {
if (typeof value !== "string") {
return value;
}
const _lval = value.toLowerCase();
if (_lval === "true") {
return true;
}
if (_lval === "false") {
return false;
}
if (_lval === "null") {
return null;
}
if (_lval === "nan") {
return Number.NaN;
}
if (_lval === "infinity") {
return Number.POSITIVE_INFINITY;
}
if (_lval === "undefined") {
return void 0;
}
if (!JsonSigRx.test(value)) {
if (options.strict) {
throw new SyntaxError("Invalid JSON");
}
return value;
}
try {
if (suspectProtoRx.test(value) || suspectConstructorRx.test(value)) {
return JSON.parse(value, jsonParseTransform);
}
return JSON.parse(value);
} catch (error) {
if (options.strict) {
throw error;
}
return value;
}
}
export { destr as d };