{"version":"1.0.0-next.15","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":"e0e131dd28b03e26652a96b9a1428c017209e187","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.15","_nodeVersion":"14.15.3","_npmVersion":"lerna/3.13.4/node@v14.15.3+x64 (darwin)","dist":{"integrity":"sha512-15spi3V28QdevleWBNXE4pIls3nFZmBbUGrW9IVPwiQczuSb9n76TCB4bsk8TSel+I1OkHEdPhu5QKMfY6rQHA==","shasum":"6a9d143f7f4f49db2d782f9e1c8839a29b43ae23","tarball":"http://registry-npm.ywwl.com/@polka/url/download/@polka/url-1.0.0-next.15.tgz","fileCount":6,"unpackedSize":7198,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgrCIlCRA9TVsSAnZWagAAGYcP/RfR9OvhVwDRvwapCpZi\nD6rrAtxaZvsxMc7CokZckGkEd/8Zt0b1U8d6w0s62T6qeQbD71BLbGT+uxda\nRm3hs0Ga7Bug+BdI6Hp6HlRmhmyeYceSW2QDoNz/ENiEL9G8PfuTe+dlwVBL\njU+JiVzgoGCPyeUP+/5BlVHQnorWl0Fkeq3PlJIES3Adu5J4yui8mNPBIe0/\nYMcRUOwqlydsxwNrWgXtdHgjkdxVIP+V+e+R8QBPhrint42oVWCXpiZXyfUM\niBH2oF7hWDB51oEFT+YaEc8hxhyoGoWHcCeWwBS2PvpRls1ASzIkkZ+SIZ/X\nAaYO+xeK5ZIbaZzgNqVhqV355K0KKJyeqMtptm8VCulVaX+/IcxVgxr3omDx\nqkbfDobeqDMry0xpoCjk8DVfgWjZSyv+yfjXPHXV/bS0YbG/YzRNF0o4gggk\nsOGOEdzfdwFvZZzmdKWROWGtlG/Mr4eSebhRquAoKhWO4+X2fIR9vm1qcgAs\nWtqw3juuAWGMCpYOnNJZuFDyO1GACnw6sivaWeCQ8m03Rucn3PoysHd87fWL\nx4asmVHbRJMu/Jvdw2y0o09/ciOE/Z9MDJHc6d2GhmzFpOAKG58QEBHeIwb+\nZZ47Rdii4Z9yTqSeP+F6DNR/FXYklZx7Hnzp5MHAcj2l6OamiI+K+12dJ/sh\nLqdg\r\n=dD5Y\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCRapcZ2xdvG2s78vTB5dYhPhtYt5PvCgfQf2pA+lkzGgIhAP74QFhhxX0gClU7X2aRJ+P6DCdk3DRonjbldYiZXda+"}],"size":3162,"noattachment":false,"key":"/@polka/url/-/@polka/url-1.0.0-next.15.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.15_1621893668932_0.40685878213468585"},"_hasShrinkwrap":false,"publish_time":1621893669099,"_cnpm_publish_time":1621893669099,"dist-tags":{"latest":"0.5.0","next":"1.0.0-next.29"}}