{"name":"destr","version":"0.0.0","description":"A faster, secure and convenient alternative for [`JSON.parse`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse):","repository":{"type":"git","url":"git+https://github.com/nuxt-community/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"},"devDependencies":{"@nuxtjs/eslint-config-typescript":"latest","benchmark":"^2.1.4","bili":"^4.10.0","rollup-plugin-typescript2":"^0.27.1","typescript":"latest"},"bugs":{"url":"https://github.com/nuxt-community/destr/issues"},"homepage":"https://github.com/nuxt-community/destr#readme","_id":"destr@0.0.0","_nodeVersion":"12.16.2","_npmVersion":"6.14.4","dist":{"integrity":"sha512-STwGEEd78GFvtey6Ri55UL6wj+Pq9B6+uboNGEyLZi3W3B6G+nvBzjBIDr3W8qx1iRrnfd64RIgfzeXKKGn6cQ==","shasum":"0a0444aaef3f98d125a55decea43e43fe87e487a","tarball":"http://registry-npm.ywwl.com/destr/download/destr-0.0.0.tgz","fileCount":5,"unpackedSize":4306,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJexRPLCRA9TVsSAnZWagAAUCIP/jcP+C2qxGwHxbl98C63\n5PymC95MT9EuhxhX9iYUp5nDzcWP5oSFpr0snTvy+O3+bnG/ii1BpayA5AKf\nQkgCOf9/r4fXGelhU8ukuaC6aPazeXR5GFMETOkF+us1UoQGB+kPQiVLliwP\npi8QLrVcy157tQtIRcZ2b1V+qC/ZqzcOPafPQSulfb7l/w1t/3xRhW0xdMwf\nRfx4hQvbF2+J4UJwZkuCVikJlQThm/KM2cM4C4qudQmi19/DpJN3KUbtIoS+\nH/6D8+y2+cYSt4BysvooOGWIbxo61jw+ygpd+1sMPwh+SkLADhTh+v5JB6fU\nAeWsLMdGgGCvRP98lEz45b4zQ36DatMRHuFCtTksEs0ShbjzxExC2G0ONOsp\nch5/byxo3lXsubMb/aEfA7u13pbqpgJETaroi3XoFYdSgV00KYlYDVGiXytz\n4N2DB9RogvxI3A0FF6q05oTBD67aCYeIyiCYigGFI1OjcIaLoA6tzI3YBiIT\nFizaYRRCWabC6+t5TiALPUbvM3T+R42rS8blmHnRbQGZlr9JHZHN61dUi0Ib\nS4/9RNk0SkvMFQoQWDRthJWc7Vp5fziezf2FvK169AmNASaNBp6FqXqhJ3S4\ncsvzJxEmkqeISus8BYvfc7r9CaBAUYESiU7othqz8flNb/1Bo74JWGt6P1D3\nPvLh\r\n=0rH1\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDnGTa5F4xSvbNA+9iBekeVAOB2kplAds0wlKBtt8ca/gIgJXH+T8smNz13pPemGizRcNxbEw4dZ8zSk9cwaGkdZBM="}],"size":2203,"noattachment":false,"key":"/destr/-/destr-0.0.0.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.0.0_1589973963030_0.25856366537613207"},"_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":1589973963142,"_cnpm_publish_time":1589973963142,"dist-tags":{"latest":"2.0.5"}}