{"version":"1.0.0-next.18","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":"765e0b2e888f210b869e9584b31af6e876ccfdc4","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.18","_nodeVersion":"16.6.2","_npmVersion":"lerna/3.13.4/node@v16.6.2+x64 (darwin)","dist":{"integrity":"sha512-rEAwa2i6cLiGROES86oNNsSV8DlXXnv34+G/e3lnEcmkP9Y2YVuEGcqv09dHQuvzQCDAqRGlJVjeqlawQb2qew==","shasum":"c8d8db7f3d38092c90ebc5e825c2c6b0cc5b1042","tarball":"http://registry-npm.ywwl.com/@polka/url/download/@polka/url-1.0.0-next.18.tgz","fileCount":6,"unpackedSize":7227,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhJwliCRA9TVsSAnZWagAA6psQAKTRr3uCeT1SiJWgW/6s\nl4yMsVyvHIsMK9CNeCdIboKn/71ziP/JfJdBcPWT0LXDjz8Wl3CIoOdUwqr4\nabjSJdZe4lmQyFrFExFct4qLKd6PLkUwjpiL7QPx2dJ19NHsFalIPL9IkuvE\nn/U58ciuTwGIDmtxHKzXWEYCwFcvOekDgj8cFidwhHsY6A83+NfDpBMEk1Yp\nTjS36jmEzcNwEuah9GgnlNiFLlfPUAI2CrffYz83c7MIDusqMOKtuB60ubcz\nqTtCyspQTnXRxaSLCJWN+NNalo+VPpy6MecUVYLwWjkZpUeoaSEe8pbv6Rnm\nKHxhXCLBUFEjoGWqKVJY2Dt2T3OeAw5WNJieaCByd7GTmmiwbxdzj0TcS9dk\nOXSYrJPPwezwtrDFsEy4Z+zOoT3yuh+V86JVWAqY7fBysdWGKXc8OZQr1gUz\nAk1zimZM+8LPJCmu35Q9yqPKBU0W5NRp+yH3m0f1mPWjDtvItT9l2DxW0+wz\nimCkmh4i3tQUlAe1YpjM+vDOsUAeMlTG3o6uS1CIShS0cqTZ+CjPPy9EppxG\nrHqVhSBHLRCEpl+u5/8ex7ao0f/yGl0F3k3YdZ+8PmCGru+RwUWSwJIBXnT+\nBsz8bem8QTjL8jb6Ng7xkbBaLx6d1b5Zu7xYboFabZo3a7a4lXT7cqEy2JYY\nGyYk\r\n=U0gw\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDZ3h194g+Tj/AkWlRKly2kav92BcNcRoNNZ8NRTFfccQIhAIW0k3wAeb+dC5+EhXRAME+qCjiBJaiSt8Ns+uhCiUw1"}],"size":3175,"noattachment":false,"key":"/@polka/url/-/@polka/url-1.0.0-next.18.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.18_1629948258115_0.6912421050551216"},"_hasShrinkwrap":false,"publish_time":1629948258299,"_cnpm_publish_time":1629948258299,"dist-tags":{"latest":"0.5.0","next":"1.0.0-next.29"}}