{"name":"parseuri","version":"0.0.4","description":"Method that parses a URI and returns an array of its components","repository":{"type":"git","url":"https://github.com/get/parseuri.git"},"homepage":"https://github.com/get/parseuri","scripts":{"test":"make test"},"devDependencies":{"mocha":"1.17.1"},"author":"","license":"MIT","dependencies":{"better-assert":"~1.0.0"},"bugs":{"url":"https://github.com/get/parseuri/issues"},"_id":"parseuri@0.0.4","dist":{"shasum":"806582a39887e1ea18dd5e2fe0e01902268e9350","tarball":"http://registry-npm.ywwl.com/parseuri/download/parseuri-0.0.4.tgz","integrity":"sha512-9pW0ZCCDtEIzW7beHfLg2N13pgctOVRq1Z+1PKdpsF4wD9GhYUMAAxBhmPRPVVy1fg2z+eH/8uw8dgA0j9DNzw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD4tA2qfT88q4UI6WYetk6/BKeZ1egcnZKbjr84b1ajdwIgWEKvK/e+9pA2vkj1qcyWHmRiL3y6FwwhK5rUtXWXAdw="}],"size":1556,"noattachment":false,"key":"/parseuri/-/parseuri-0.0.4.tgz"},"_from":".","_npmVersion":"1.3.15","_npmUser":{"name":"gal","email":"koren@mit.edu"},"maintainers":[{"name":"gal","email":"koren@mit.edu"}],"directories":{},"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":1405815040568,"_cnpm_publish_time":1405815040568,"dist-tags":{"latest":"3.0.2"}}