mirror of
https://github.com/Sevichecc/Urara-Blog.git
synced 2025-05-05 04:09:31 +08:00
40 lines
No EOL
3.9 KiB
Text
40 lines
No EOL
3.9 KiB
Text
{
|
|
"name": "destr",
|
|
"version": "1.1.1",
|
|
"description": "A faster, secure and convenient alternative for JSON.parse",
|
|
"repository": "unjs/destr",
|
|
"license": "MIT",
|
|
"main": "./dist/index.cjs",
|
|
"module": "./dist/index.mjs",
|
|
"type": "module",
|
|
"exports": {
|
|
".": {
|
|
"import": "./dist/index.mjs",
|
|
"require": "./dist/index.cjs"
|
|
}
|
|
},
|
|
"types": "dist/index.d.ts",
|
|
"files": [
|
|
"dist"
|
|
],
|
|
"devDependencies": {
|
|
"@hapi/bourne": "latest",
|
|
"@nuxtjs/eslint-config-typescript": "latest",
|
|
"benchmark": "latest",
|
|
"eslint": "latest",
|
|
"rollup-plugin-typescript2": "latest",
|
|
"secure-json-parse": "latest",
|
|
"standard-version": "latest",
|
|
"typescript": "latest",
|
|
"unbuild": "latest"
|
|
},
|
|
"packageManager": "pnpm@6.32.3",
|
|
"scripts": {
|
|
"bench": "pnpm build && node ./bench.cjs",
|
|
"build": "unbuild",
|
|
"lint": "eslint --ext .ts .",
|
|
"release": "pnpm test && pnpm build && standard-version && git push --follow-tags && pnpm publish",
|
|
"test": "pnpm lint"
|
|
},
|
|
"readme": "# destr\n\n> A faster, secure and convenient alternative for [`JSON.parse`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse):\n\n[![npm version][npm-v-src]][npm-v-href]\n[![npm downloads][npm-d-src]][npm-d-href]\n[![bundle phobia][bundlephobia-src]][bundlephobia-href]\n\n## Usage\n\n### Node.js\n\nInstall using npm or yarn:\n\n```bash\nnpm i destr\n# or\nyarn add destr\n```\n\nImport into your Node.js project:\n\n```js\n// CommonJS\nconst destr = require('destr')\n\n// ESM\nimport destr from 'destr'\n```\n\n### Deno\n\n```js\nimport destr from 'https://deno.land/x/destr/src/index.ts'\n\nconsole.log(destr('{ \"deno\": \"yay\" }'))\n```\n\n## Why?\n\nPlease note that `destr` is little bit slower when parsing a standard JSON string mainly because of transform to avoid [prototype pollution](https://hueniverse.com/a-tale-of-prototype-poisoning-2610fa170061) which can lead to serious security issues if not being sanitized. In the other words, `destr` is better when input is not always a json string or from untrusted source like request body.\n\n**Fast fallback to input if is not string:**\n\n```js\n// Uncaught SyntaxError: Unexpected token u in JSON at position 0\nJSON.parse()\n\n// undefined\ndestr()\n```\n\n```js\n// JSON.parse x 5,324,474 ops/sec ±0.65% (94 runs sampled)\nJSON.parse(3.14159265359)\n\n// destr x 657,187,095 ops/sec ±0.06% (98 runs sampled)\ndestr(3.14159265359)\n```\n\n**Fast lookup for known string values:**\n\n```js\n// Uncaught SyntaxError: Unexpected token T in JSON at position 0\nJSON.parse('TRUE')\n\n// true\ndestr('TRUE')\n```\n\n```js\n// JSON.parse x 10,407,488 ops/sec ±0.30% (97 runs sampled)\nJSON.parse('true')\n\n// destr x 88,634,032 ops/sec ±0.32% (95 runs sampled)\ndestr('true')\n```\n\n**Fallback to original value if parse fails (empty or any plain string):**\n\n```js\n// Uncaught SyntaxError: Unexpected token s in JSON at position 0\n// JSON.parse (try-catch) x 248,212 ops/sec ±1.22% (84 runs sampled\nJSON.parse('salam')\n\n// destr x 30,867,179 ops/sec ±0.49% (94 runs sampled)\ndestr('salam')\n```\n\n**Avoid prototype pollution:**\n\n```js\nconst input = '{ \"user\": { \"__proto__\": { \"isAdmin\": true } } }'\n\n// { user: { __proto__: { isAdmin: true } } }\nJSON.parse(input)\n\n// { user: {} }\ndestr(input)\n```\n\n## License\n\nMIT. Made with 💖\n\n<!-- Refs -->\n[npm-v-src]: https://img.shields.io/npm/v/destr?style=flat-square\n[npm-v-href]: https://npmjs.com/package/destr\n\n[npm-d-src]: https://img.shields.io/npm/dm/destr?style=flat-square\n[npm-d-href]: https://npmjs.com/package/destr\n\n[github-actions-src]: https://img.shields.io/github/workflow/status/unjs/destr/ci/master?style=flat-square\n[github-actions-href]: https://github.com/unjs/destr/actions?query=workflow%3Aci\n\n[bundlephobia-src]: https://img.shields.io/bundlephobia/min/destr?style=flat-square\n[bundlephobia-href]: https://bundlephobia.com/result?p=destr\n"
|
|
} |