{"name":"destr","version":"0.1.8","description":"A faster, secure and convenient alternative for JSON.parse","repository":{"type":"git","url":"git+https://github.com/nuxt-contrib/destr.git"},"license":"MIT","main":"dist/index.js","types":"dist/index.d.ts","scripts":{"bench":"yarn build && node ./bench.js","build":"bili src/index.ts","lint":"eslint --ext .ts .","release":"yarn test && yarn build && standard-version && git push --follow-tags && npm publish","test":"yarn lint"},"devDependencies":{"@hapi/bourne":"^2.0.0","@nuxtjs/eslint-config-typescript":"latest","benchmark":"latest","bili":"latest","eslint":"latest","rollup-plugin-typescript2":"latest","secure-json-parse":"^2.1.0","standard-version":"latest","typescript":"latest"},"gitHead":"37055786fe10914bf74643d7ffa0fedbca2440d6","bugs":{"url":"https://github.com/nuxt-contrib/destr/issues"},"homepage":"https://github.com/nuxt-contrib/destr#readme","_id":"destr@0.1.8","_nodeVersion":"12.16.2","_npmVersion":"6.14.4","dist":{"integrity":"sha512-FM5DXFleFqEifizIBj3q13FRNH3THqSGXKdJ3doDqsdjO7ldh1JGQZSlsujUjAVQ6g/Q1GQ4FAyC9RNrtJsobg==","shasum":"208f0332380d3f1ebf3ba0a29d1603c9b47884cd","tarball":"http://registry-npm.ywwl.com/destr/download/destr-0.1.8.tgz","fileCount":6,"unpackedSize":7584,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJez6b6CRA9TVsSAnZWagAAHyoP/A33Lyh165qW5JVnIX64\nYmRHhZj7IRq1yjUVyz2QuQSfB2rbnB4vIt0wpIRWbk4AW/uwnNEYTNij0843\nUHb3GSK8M+1SAnmKlqWFIbTglRYcIMBQ41MYotYfmN5ONuhvMeywL31ds39v\nySgAX9sqT4AhvIo3El4XhrGlPCZzm8f8prIstIV3pCTrEPDM4vO8TRjVijzI\nqe9SXRqxmeqvBDN489H+UOPF9zyG6OeHNAIYCox3LAkEzwhB5XgyIVKU7si6\nktLwsSfeHn1w5D4FRZO3txbUqel8kPRjEBCdSTI+Gi60aY35tHrT/Gg1rTwh\n6Y5tCfQpP6H771+GkZJ/CnERWpRdF+dGJbltvZiSXE2WejIoF54mx2tL+iaW\nnaRpsOBOHr/tTngiLKeFVfe9jAftKVPFPclI5rxi3ZdDGfE5sGWkUORfHwBc\nywqTBhlT91URKeIb1Qhao5AKXMTt32q364BC92A7Isu+zobT9K37uzz4lyB9\nDLiq2BJxbPZ5iLyYQ0nlo/EdT1iSPWulADinvchps58ReVlFAg06mrpfEIgI\n9eqCLq0wzFqJT3NlyXMIPOQgIyL/2AGz2uznjcjuJkPThnnu0dXn1otsbFer\nyDXz6NtUMqNqHh9Xz5stCGv22XHiyxgjb4sQR91FP2M1ZkxRAAFxwGxgt3is\nRkwq\r\n=zXsS\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHLsFlZmj54WxS2lDnXJsEOT4BOt+UWtPpzE+ZokpyBvAiEAvkUVcMm+hRmePmk42A85wUf5yCE3e7uOWseqAutBvy8="}],"size":3413,"noattachment":false,"key":"/destr/-/destr-0.1.8.tgz"},"maintainers":[{"name":"pi0","email":"pyapar@gmail.com"}],"_npmUser":{"name":"pi0","email":"pyapar@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/destr_0.1.8_1590667001934_0.2512981699190229"},"_hasShrinkwrap":false,"readme":"# destr\n\n[![npm version][npm-version-src]][npm-version-href]\n[![npm downloads][npm-downloads-src]][npm-downloads-href]\n[![bundle][bundle-src]][bundle-href]\n[![License][license-src]][license-href]\n\nA faster, secure and convenient alternative for [`JSON.parse`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse).\n\n## Usage\n\n### Node.js\n\nInstall dependency:\n\n```bash\n# npm\nnpm i destr\n\n# yarn\nyarn add destr\n\n# pnpm\npnpm i destr\n```\n\nImport into your Node.js project:\n\n```js\n// ESM\nimport { destr, safeDestr } from \"destr\";\n\n// CommonJS\nconst { destr, safeDestr } = require(\"destr\");\n```\n\n### Deno\n\n```js\nimport { destr, safeDestr } from \"https://deno.land/x/destr/src/index.ts\";\n\nconsole.log(destr('{ \"deno\": \"yay\" }'));\n```\n\n## Why?\n\n### ✅ Type Safe\n\n```ts\nconst obj = JSON.parse(\"{}\"); // obj type is any\n\nconst obj = destr(\"{}\"); // obj type is unknown by default\n\nconst obj = destr<MyInterface>(\"{}\"); // obj is well-typed\n```\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### ✅ 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### ✅ 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\nJSON.parse(\"salam\");\n\n// \"salam\"\ndestr(\"salam\");\n```\n\n**Note:** This fails in safe/strict mode with `safeDestr`.\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### ✅ Strict Mode\n\nWhen using `safeDestr` it will throw an error if the input is not a valid JSON string or parsing fails. (non string values and built-ins will be still returned as-is)\n\n```js\n// Returns \"[foo\"\ndestr(\"[foo\");\n\n// Throws an error\nsafeDestr(\"[foo\");\n```\n\n## Benchmarks\n\n`destr` is faster generally for arbitrary inputs but also sometimes little bit slower than `JSON.parse` when parsing a valid JSON string mainly because of transform to avoid [prototype pollution](https://learn.snyk.io/lessons/prototype-pollution/javascript/) 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\nCheck [Benchmark Results](./BENCH.md) or run with `pnpm run bench:node` or `pnpm run bench:bun` yourself!\n\n## License\n\nMIT. Made with 💖\n\n<!-- Badges -->\n\n[npm-version-src]: https://img.shields.io/npm/v/destr?style=flat&colorA=18181B&colorB=F0DB4F\n[npm-version-href]: https://npmjs.com/package/destr\n[npm-downloads-src]: https://img.shields.io/npm/dm/destr?style=flat&colorA=18181B&colorB=F0DB4F\n[npm-downloads-href]: https://npmjs.com/package/destr\n[bundle-src]: https://img.shields.io/bundlephobia/minzip/destr?style=flat&colorA=18181B&colorB=F0DB4F\n[bundle-href]: https://bundlephobia.com/result?p=destr\n[license-src]: https://img.shields.io/github/license/unjs/destr.svg?style=flat&colorA=18181B&colorB=F0DB4F\n[license-href]: https://github.com/unjs/destr/blob/main/LICENSE\n","publish_time":1590667002065,"_cnpm_publish_time":1590667002065,"dist-tags":{"latest":"2.0.5"}}