admin felület fejlesztése garázs, előfizeztési csomagok

This commit is contained in:
Roo
2026-06-25 01:58:04 +00:00
parent 80a5d67f79
commit 52011606ff
334 changed files with 46636 additions and 1606 deletions

View File

@@ -0,0 +1,72 @@
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 = /^\s*["[{]|^\s*-?\d{1,16}(\.\d{1,17})?([Ee][+-]?\d+)?\s*$/;
function jsonParseTransform(key, value) {
if (key === "__proto__" || key === "constructor" && value && typeof value === "object" && "prototype" in value) {
warnKeyDropped(key);
return;
}
return value;
}
function warnKeyDropped(key) {
console.warn(`[destr] Dropping "${key}" key to prevent prototype pollution.`);
}
function destr(value, options = {}) {
if (typeof value !== "string") {
return value;
}
if (value[0] === '"' && value[value.length - 1] === '"' && value.indexOf("\\") === -1) {
return value.slice(1, -1);
}
const _value = value.trim();
if (_value.length <= 9) {
switch (_value.toLowerCase()) {
case "true": {
return true;
}
case "false": {
return false;
}
case "undefined": {
return void 0;
}
case "null": {
return null;
}
case "nan": {
return Number.NaN;
}
case "infinity": {
return Number.POSITIVE_INFINITY;
}
case "-infinity": {
return Number.NEGATIVE_INFINITY;
}
}
}
if (!JsonSigRx.test(value)) {
if (options.strict) {
throw new SyntaxError("[destr] Invalid JSON");
}
return value;
}
try {
if (suspectProtoRx.test(value) || suspectConstructorRx.test(value)) {
if (options.strict) {
throw new Error("[destr] Possible prototype pollution");
}
return JSON.parse(value, jsonParseTransform);
}
return JSON.parse(value);
} catch (error) {
if (options.strict) {
throw error;
}
return value;
}
}
function safeDestr(value, options = {}) {
return destr(value, { ...options, strict: true });
}
export { destr as default, destr, safeDestr };

View File

@@ -0,0 +1,47 @@
{
"name": "destr",
"version": "2.0.5",
"description": "A faster, secure and convenient alternative for JSON.parse",
"repository": "unjs/destr",
"license": "MIT",
"sideEffects": false,
"type": "module",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"require": "./lib/index.cjs"
}
},
"main": "./lib/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"files": [
"dist",
"lib"
],
"scripts": {
"bench:bun": "pnpm build && bun --bun ./test/bench.mjs",
"bench:node": "pnpm build && node ./test/bench.mjs",
"build": "unbuild",
"dev": "vitest dev",
"lint": "eslint . && prettier -c src test",
"lint:fix": "eslint . --fix && prettier -w src test",
"release": "pnpm test && pnpm build && changelogen --release --push && npm publish",
"test": "pnpm lint && vitest run --coverage"
},
"devDependencies": {
"@hapi/bourne": "^3.0.0",
"@vitest/coverage-v8": "^3.1.1",
"changelogen": "^0.6.1",
"eslint": "^9.23.0",
"eslint-config-unjs": "^0.4.2",
"mitata": "^1.0.34",
"prettier": "^3.5.3",
"secure-json-parse": "^4.0.0",
"typescript": "^5.8.2",
"unbuild": "~3.4",
"vitest": "^3.1.1"
},
"packageManager": "pnpm@10.7.1"
}