{"version":"1.0.0-next.17","name":"@polka/url","repository":{"type":"git","url":"git+https://github.com/lukeed/polka.git"},"description":"Super fast, memoized `req.url` parser","module":"build.mjs","types":"index.d.ts","main":"build.js","license":"MIT","exports":{".":{"import":"./build.mjs","require":"./build.js"},"./package.json":"./package.json"},"author":{"name":"Luke Edwards","email":"luke@lukeed.com","url":"https://lukeed.com"},"publishConfig":{"access":"public"},"gitHead":"e0a65c781b763f7421f1a64d4166b3911f4d20e9","readme":"# @polka/url [![npm](https://badgen.now.sh/npm/v/@polka/url)](https://npmjs.org/package/@polka/url)\n\n> Super fast, memoized `req.url` parser; _not_ limited to [Polka][polka]!\n\nParses the `url` from a [`IncomingMessage`](https://nodejs.org/api/http.html#http_class_http_incomingmessage) request. The returned object will always only contain the following keys: `search`, `query`, `pathname`, and `raw`.\n\n> **Note:** This library does not process `protocol`, `hostname`, `port`, etc.<br>This is because the incoming `req.url` value only begins with the path information.\n\nParsed requests will be mutated with a `_parsedUrl` key, containing the returned output. This is used for future memoization, avoiding the need to fully parse the same `url` value multiple times.\n\n## Install\n\n```\n$ npm install --save @polka/url\n```\n\n## Usage\n\n```js\nconst parse = require('@polka/url');\n\nlet req = {\n  url: '/foo/bar?fizz=buzz'\n};\nlet output = parse(req);\n//=> {\n//=>   pathname: '/foo/bar',\n//=>   raw: '/foo/bar?fizz=buzz',\n//=>   search: '?fizz=buzz',\n//=>   query: {\n//=>     fizz: 'buzz'\n//=>   },\n//=> }\n\n// Attaches result for future memoization\nassert.deepEqual(output, req._parsedUrl); //=> true\n\n// Example with `toDecode` param\nreq = {\n  url: '/f%C3%B8%C3%B8%C3%9F%E2%88%82r?phone=%2b8675309'\n};\nparse(req, true);\n//=> {\n//=>   pathname: '/føøß∂r',\n//=>   raw: '/f%C3%B8%C3%B8%C3%9F%E2%88%82r?phone=%2b8675309',\n//=>   search: '?phone=%2b8675309',\n//=>   query: {\n//=>     phone: '+8675309'\n//=>   }\n//=> }\n\n// Attaches awareness key\nassert(req._decoded); //=> true\n```\n\n## API\n\n### url(req, toDecode?)\nReturns: `Object` or `undefined`\n\n> **Important:** The `req` must have a `url` key, otherwise `undefined` will be returned.<br>If no input is provided at all, a `TypeError` will be thrown.\n\n#### req\nType: `IncomingMessage` or `{ url: string }`\n\nThe incoming HTTP request (`req`) or a plain `Object` with a `url` key.\n\n> **Note:** In Node.js servers, the [`req.url`](https://nodejs.org/api/http.html#http_message_url) begins with a pathname & does not include a `hash`.\n\n#### toDecode\nType: `Boolean`<br>\nDefault: `false`\n\nIf enabled, the `pathname` will be fully decoded, via [`decodeURIComponent`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURIComponent).\n\n> **Important:** Please note the following behaviors:\n> * `raw` is _never_ decoded; this key reflects your original value\n> * `pathname` is decoded _only_ when `toDecode` is enabled\n> * `search` is _never_ decoded; this key reflects your original querystring value\n> * `query` is _always_ decoded; even when `toDecode` is disabled\n\nAdditionally, the `req` is mutated with `req._decoded = true` so as to prevent repetitive decoding.\n\n\n## Benchmarks\n\nCheck out the [`bench`](/bench) directory for in-depth benchmark results and comparisons.\n\n\n## Support\n\nAny issues or questions can be sent to the [Polka][polka] repository.<br>However, please specify that your inquiry is about `@polka/url` specifically.\n\n\n## License\n\nMIT © [Luke Edwards](https://lukeed.com)\n\n[polka]: https://github.com/lukeed/polka\n","readmeFilename":"readme.md","bugs":{"url":"https://github.com/lukeed/polka/issues"},"homepage":"https://github.com/lukeed/polka#readme","_id":"@polka/url@1.0.0-next.17","_nodeVersion":"14.15.3","_npmVersion":"lerna/3.13.4/node@v14.15.3+x64 (darwin)","dist":{"integrity":"sha512-0p1rCgM3LLbAdwBnc7gqgnvjHg9KpbhcSphergHShlkWz8EdPawoMJ3/VbezI0mGC5eKCDzMaPgF9Yca6cKvrg==","shasum":"25fdbdfd282c2f86ddf3fcefbd98be99cd2627e2","tarball":"http://registry-npm.ywwl.com/@polka/url/download/@polka/url-1.0.0-next.17.tgz","fileCount":6,"unpackedSize":7278,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhFw5JCRA9TVsSAnZWagAAFUUP+QC4PxGm8x6Rn/1jCyHt\nSIYuzb9BX+X/oy4DqsQquDtZd6JoaA9sUkqhQxFgGS4MxSIxVm/AIT4GLocx\nmRyvKkWyPacqPS6VX6tAA22/q0MftiIxi/7Wcq8Jy4i8HAcQaSTrLXSUCARa\nMze/Pre1pv8fU39ZrMfCLbyFFxxftZ8q4bwQMW7C3stAN29TyYYF1uFbcrtJ\nvXqT5prnuE+NYdRQWzcOgB1wKJkWhO5yXjIBDIGdNc8jaV+iRTHi0w04wznI\nurOATSZecKnJsEuOUXRTTRRPDOJyUt4WdxWjTAovkTJa9mjgHdrT2FYHwCHD\n7ZmhkjeEvMiYV7wRpTC6coMSPFNiCQilzVcflo0NIteOZ+d2PSfP1wJNjAIA\nDgDYvqQLhTYAcS6ZL6QN8MbQstS/P60iD1W8REk8h4SU5g5+T94Dtlas2HoK\nefu0IgaQUKXlnGv5xgTjdMixkYqcfJNhygL3MuXOchrWJVEO6k6+1kdbb+sA\n0BPFvD/s67afV8fCfr4A3IJVTiYKjcYA5tM3DklJiU+Wec2ojeM0Znx7WAoq\nFlSABVnZ3NKqB58CCZGZrNihr2d+BCimOpcRNT5muB40L5xUQcr7pBhhpxto\nPfRhjn7i0XqeVmOM4ILOht5BAaLeCyo6mDEMNirca7kTiDpQg5PwS8F5u/XI\nK15m\r\n=Ih4V\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCUQm9j+OfkONMEgAp8EF7x+RkW15YfEoL9p2GhQJ3kKgIgaNrRhB2s/ZTLn8qh+0xH3gDzVG7NNl+ukKv8ZB6XLXY="}],"size":3189,"noattachment":false,"key":"/@polka/url/-/@polka/url-1.0.0-next.17.tgz"},"_npmUser":{"name":"lukeed","email":"luke@lukeed.com"},"directories":{},"maintainers":[{"name":"lukeed","email":"luke@lukeed.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/url_1.0.0-next.17_1628900937212_0.3294904345756555"},"_hasShrinkwrap":false,"publish_time":1628900937328,"_cnpm_publish_time":1628900937328,"dist-tags":{"latest":"0.5.0","next":"1.0.0-next.29"}}