{"name":"parseuri","version":"0.0.6","description":"Method that parses a URI and returns an array of its components","repository":{"type":"git","url":"git+https://github.com/get/parseuri.git"},"homepage":"https://github.com/get/parseuri","scripts":{"test":"make test"},"devDependencies":{"better-assert":"~1.0.0","mocha":"1.17.1","expect.js":"^0.3.1"},"author":{"name":"Gal Koren"},"license":"MIT","gitHead":"ad9e2495173e763ab9edc46a5c15f89c324455d9","bugs":{"url":"https://github.com/get/parseuri/issues"},"_id":"parseuri@0.0.6","_npmVersion":"6.4.1","_nodeVersion":"10.14.2","_npmUser":{"name":"gal","email":"koren@mit.edu"},"dist":{"integrity":"sha512-AUjen8sAkGgao7UyCX6Ahv0gIK2fABKmYjvP4xmy5JaKvcbTRueIqIPHLAfq30xJddqSE033IOMUSOMCcK3Sow==","shasum":"e1496e829e3ac2ff47f39a4dd044b32823c4a25a","tarball":"http://registry-npm.ywwl.com/parseuri/download/parseuri-0.0.6.tgz","fileCount":7,"unpackedSize":5914,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdgk76CRA9TVsSAnZWagAAnH8QAKKlQVaYBSSLcgxCzG/I\nlaiQ7vIoQpIcdSvIzTmmzzyy6szz8uzSa/Ad/Shxbf96kAhWAmYjNtELFCrx\nGs4VEtCw1wz007GsNGu//DUGXmADC7x8J13VJh5tVX9u+N5/8cYjP7MVHBIY\nkcvzlKi5omUW81w0tOe0lGxhs6/Dg31rKdTkmB0LTMPArLbutrEHIxLekc4S\n1LdLfIetpBVK8ZqOS34OLPjAThkH4MiOxrNwoQRR1uQtvxza3zuJ9BvugKRr\n0g6kulpYrx54XxxTJx/APgq4ve3U690Y1y9aQ5XnEqTaLR/X+jMpp2r/bY1r\n4Guv1EsfqmztHcRWXGQ0p/YUJ6eLsmufkGLoUsbnFoT6AnjC13Mao588lk9L\nMWlLjTTGkgfZmY9x92NPnRaBiC8VM0Yv7/mvFIKno9BfSIS1m7++KrgreUls\npFP6uX6QsYlqPaFfrhPqZ91Jh0sXvhqDLvwYugk0EquBCu9LRyFkoICbh7rE\nmOf1r0LGmihHLhDNNcHc0ZRI7n0eUcQfgsmAxjMgW7hKY4MB7vA/mQe+eT7m\nNQ4oqcGj6G1cur5CjlMG0RfVUyxv5x73JbO0I/OMJsssS2qk/tGhJxcV8XrJ\ns2zUYj7Xnux5p2CJo+YrjHuP31Ux28RjzCN98J3VwbJt7TfytR35r1xJ5w/c\nDLdD\r\n=J2vk\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIC7VGfp0FWqs8at082tLN3RLM27n7JqPLmpqKb1ahQxKAiAo1UFffKWa6i//5WTqpVL8fMyRcuMCtBIXcuMq0Jwdug=="}],"size":2565,"noattachment":false,"key":"/parseuri/-/parseuri-0.0.6.tgz"},"maintainers":[{"name":"gal","email":"koren@mit.edu"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/parseuri_0.0.6_1568820986115_0.7809546772297578"},"_hasShrinkwrap":false,"readme":"# parseUri\n\n`parseUri` is a mighty but tiny JavaScript URI/URN/URL parser that splits any URI into its parts (all of which are optional). Its combination of accuracy, comprehensiveness, and brevity is unrivaled (1KB min/gzip, with no dependencies).\n\n## Breaking changes\n\nVersion 2 was a major, breaking change that probably requires updating URI part names in your code. See details in the [release notes](https://github.com/slevithan/parseuri/releases/tag/v2.0.0) and compare results on the [demo page](https://slevithan.github.io/parseuri/demo/?compareV1=true&friendlyMode=true). Version 3 was a small update published on npm as pure ESM.\n\n## Compared to the `URL` constructor\n\n`parseUri` includes several advantages over the built-in [`URL`](https://developer.mozilla.org/en-US/docs/Web/API/URL):\n\n* It gives you many additional properties (`authority`, `userinfo`, `subdomain`, `domain`, `tld`, `resource`, `directory`, `filename`, `suffix`) that aren’t available from `URL`.\n* `URL` throws e.g. if not given a protocol, and in many other cases of valid (but not supported) and invalid URIs. `parseUri` makes a best case effort even with partial or invalid URIs and is extremely good with edge cases.\n* `URL`’s rules don’t allow correctly handling many non-web protocols. For example, `URL` doesn’t throw on any of `'git://localhost:1234'`, `'ssh://myid@192.168.1.101'`, or `'t2ab:///path/entry'`, but it also doesn’t get their details correct since it treats everything after `<non-web-protocol>:` up to `?` or `#` as part of the `pathname`.\n* `parseUri` includes a “friendly” parsing mode (in addition to its default mode) that handles human-friendly URLs like `'example.com/file.html'` as expected.\n* `parseUri` supports providing a list of second-level domains that should be treated as part of the top-level domain (ex: `co.uk`).\n\nConversely, `parseUri` is single-purpose and doesn’t apply normalization.\n\nThe [demo page](https://slevithan.github.io/parseuri/demo/?urlStandard=true) allows easily comparing with `URL`’s results.\n\n## Results / URI parts\n\nReturns an object with 20 URI parts as properties plus `queryParams`, a [`URLSearchParams`](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams) object that includes methods `get(key)`, `getAll(key)`, etc.\n\nHere’s an example of what each part contains:\n\n```text\n┌──────────────────────────────────────────────────────────────────────────────────────────────────────────┐\n│                                                  href                                                    │\n├────────────────────────────────────────────────────────────────┬─────────────────────────────────────────┤\n│                             origin                             │                resource                 │\n├──────────┬─┬───────────────────────────────────────────────────┼──────────────────────┬───────┬──────────┤\n│ protocol │ │                     authority                     │       pathname       │ query │ fragment │\n│          │ ├─────────────────────┬─────────────────────────────┼───────────┬──────────┤       │          │\n│          │ │      userinfo       │            host             │ directory │ filename │       │          │\n│          │ ├──────────┬──────────┼──────────────────────┬──────┤           ├─┬────────┤       │          │\n│          │ │ username │ password │       hostname       │ port │           │ │ suffix │       │          │\n│          │ │          │          ├───────────┬──────────┤      │           │ ├────────┤       │          │\n│          │ │          │          │ subdomain │  domain  │      │           │ │        │       │          │\n│          │ │          │          │           ├────┬─────┤      │           │ │        │       │          │\n│          │ │          │          │           │    │ tld │      │           │ │        │       │          │\n\"  https   ://   user   :   pass   @ sub1.sub2 . dom.com  : 8080   /p/a/t/h/  a.html    ?  q=1  #   hash   \"\n└──────────────────────────────────────────────────────────────────────────────────────────────────────────┘\n```\n\n> If this chart doesn’t appear correctly, view it on [GitHub](https://github.com/slevithan/parseuri/blob/main/README.md#results--uri-parts).\n\n`parseUri` additionally supports IPv4 and IPv6 addresses, URNs, and many edge cases not shown here. See the extensive [tests](https://slevithan.github.io/parseuri/spec/).\n\n## Parsing modes\n\n`parseUri` has two parsing modes: default and friendly. The default mode follows official URI rules. Friendly mode doesn’t require `'<protocol>:'`, `':'`, or `'//'` to signal the start of an authority, which allows handling human-friendly URLs like `'example.com/file.html'` as expected. This change has several effects:\n\n- It allows starting a URI with an authority (as noted above).\n- It precludes friendly mode from properly handling relative paths (that don’t start from root `'/'`) such as `'dir/file.html'`.\n- Since the web protocols `http`, `https`, `ws`, `wss`, and `ftp` don’t require `'//'`, this also means that friendly mode extends this behavior to non-web protocols.\n\n## Examples\n\n```js\nlet uri = parseUri('https://a.b.example.com:80/@user/a/my.img.jpg?q=x&q=#hash');\nuri.protocol // → 'https'\nuri.host // → 'a.b.example.com:80'\nuri.hostname // → 'a.b.example.com'\nuri.subdomain // → 'a.b'\nuri.domain // → 'example.com'\nuri.port // → '80'\nuri.resource // → '/@user/a/my.img.jpg?q=x&q=#hash'\nuri.pathname // → '/@user/a/my.img.jpg'\nuri.directory // → '/@user/a/'\nuri.filename // → 'my.img.jpg'\nuri.suffix // → 'jpg'\nuri.query // → 'q=x&q='\nuri.fragment // → 'hash'\nuri.queryParams.get('q') // → 'x'\nuri.queryParams.getAll('q') // → ['x', '']\nuri.queryParams.get('not-present') // → null\nuri.queryParams.getAll('not-present') // → []\n// Also available: href, origin, authority, userinfo, username, password, tld\n\n// Relative path (not starting from root /)\nuri = parseUri('dir/file.html?q=x');\nuri.hostname // → ''\nuri.directory // → 'dir/'\nuri.filename // → 'file.html'\nuri.query // → 'q=x'\n\n// Friendly mode allows starting with an authority\nuri = parseUri('example.com/file.html', 'friendly');\nuri.hostname // → 'example.com'\nuri.directory // → '/'\nuri.filename // → 'file.html'\n\n// IPv4 address\nuri = parseUri('ssh://myid@192.168.1.101');\nuri.protocol // → 'ssh'\nuri.username // → 'myid'\nuri.hostname // → '192.168.1.101'\nuri.domain // → ''\n\n// IPv6 address\nuri = parseUri('https://[2001:db8:85a3::7334]:80?q=x');\nuri.hostname // → '[2001:db8:85a3::7334]'\nuri.port // → '80'\nuri.domain // → ''\nuri.query // → 'q=x'\n\n// Mailto\nuri = parseUri('mailto:first@my.com,second@my.com?subject=Hey&body=Sign%20me%20up!');\nuri.protocol // → 'mailto'\nuri.username // → ''\nuri.hostname // → ''\nuri.pathname // → 'first@my.com,second@my.com'\nuri.query // → 'subject=Hey&body=Sign%20me%20up!'\nuri.queryParams.get('body') // → 'Sign me up!'\n\n// Mailto in friendly mode\nuri = parseUri('mailto:me@my.com?subject=Hey', 'friendly');\nuri.protocol // → 'mailto'\nuri.username // → 'me'\nuri.hostname // → 'my.com'\nuri.pathname // → ''\n\n/* Also supports e.g.:\n- https://[2001:db8:85a3::7334%en1]/ipv6-with-zone-identifier\n- git://localhost:1234\n- file:///path/file\n- tel:+1-800-555-1212\n- urn:uuid:c5542ab6-3d96-403e-8e6b-b8bb52f48d9a?q=x\n*/\n```\n\nUse the [demo page](https://slevithan.github.io/parseuri/demo/) to easily test and compare results.\n\n## Install\n\n```bash\nnpm install parseuri\n```\n\n## Use\n\n```js\nimport { parseUri, setTlds } from 'parseuri';\n```\n\nIn browsers:\n\n```html\n<script src=\"https://cdn.jsdelivr.net/npm/parseuri/dist/parseuri.min.js\"></script>\n<script>\n  console.log(parseUri('https://example.com/'));\n  // If needed, use `parseUri.setTlds`\n</script>\n```\n","publish_time":1568820986251,"_cnpm_publish_time":1568820986251,"dist-tags":{"latest":"3.0.2"}}