{"name":"tldts","version":"5.7.48","keywords":["tld","sld","domain","subdomain","subdomain","hostname","browser","uri","url","domain name","public suffix","url parsing","typescript"],"author":{"name":"Rémi Berson"},"license":"MIT","_id":"tldts@5.7.48","contributors":[{"name":"Alexei","email":"alexeiatyahoodotcom@gmail.com"},{"name":"Alexey","email":"kureev-mail@ya.ru"},{"name":"Andrew","email":"chefandrew@seomoz.org"},{"name":"Johannes Ewald","email":"johannes.ewald@peerigon.com"},{"name":"Jérôme Desboeufs","email":"jerome.desboeufs@gmail.com"},{"name":"Kelly Campbell","email":"kelly.a.campbell@gmail.com"},{"name":"Kiko Beats","email":"josefrancisco.verdu@gmail.com"},{"name":"Kris Reeves","email":"krisreeves@searchfanatics.com"},{"name":"Krzysztof Jan Modras","email":"chrmod@chrmod.net"},{"name":"Olivier Melcher","email":"olivier.melcher@gmail.com"},{"name":"Rémi Berson","email":"remi.berson@pm.me"},{"name":"Saad Rashid","email":"srashid@lendinghome.com"},{"name":"Thomas Parisot","email":"hi@oncletom.io"},{"name":"Timo Tijhof","email":"krinklemail@gmail.com"},{"name":"Xavier Damman","email":"xdamman@gmail.com"},{"name":"Yehezkiel Syamsuhadi","email":"yehezkielbs@gmail.com"}],"homepage":"https://github.com/remusao/tldts#readme","bugs":{"url":"https://github.com/remusao/tldts/issues"},"bin":{"tldts":"bin/cli.js"},"dist":{"shasum":"b702fff76149a0d771d6bb67d13341d01ae751fc","tarball":"http://registry-npm.ywwl.com/tldts/download/tldts-5.7.48.tgz","fileCount":27,"integrity":"sha512-AYMc2b0y+ufgZwURfOPZiBixdV/CjHUWfuA5F6+nd4jXvVK70XEYV3Q1iL7tnAVO4Ivptjwi0GrXaE4ylgUOoA==","signatures":[{"sig":"MEQCICN3od+V21wiTq6/Pf9Q2dOTNglWYj53aCX5CgjMZaePAiA0IZWpjJh2sZGaucbZNxMsHs40lwS3KTesuZuGC1onxA==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2921391,"size":731369,"noattachment":false,"key":"/tldts/-/tldts-5.7.48.tgz"},"main":"dist/cjs/index.js","types":"dist/types/index.d.ts","module":"dist/es6/index.js","gitHead":"4289ce5f12839c6ea6d30be08d9f3c164ddeb007","scripts":{"lint":"tslint --config ../../tslint.json --project ./tsconfig.json","test":"nyc mocha --config ../../.mocharc.js","build":"tsc --build ./tsconfig.json","clean":"rimraf dist coverage","bundle":"tsc --build ./tsconfig.bundle.json && rollup --config ./rollup.config.ts","prepack":"yarn run bundle"},"_npmUser":{"name":"remusao","email":"remi.berson@pm.me"},"repository":{"url":"git+ssh://git@github.com/remusao/tldts.git","type":"git"},"_npmVersion":"lerna/4.0.0/node@v14.18.0+x64 (linux)","description":"Library to work against complex domain names, subdomains and URIs.","directories":{},"_nodeVersion":"14.18.0","dependencies":{"tldts-core":"^5.7.48"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"nyc":"^15.0.1","chai":"^4.2.0","mocha":"^9.0.0","rimraf":"^3.0.0","rollup":"^2.50.4","tslint":"^6.0.0","typescript":"^4.3.2","@types/chai":"^4.2.18","@types/node":"^16.3.2","tldts-tests":"^5.7.48","@types/mocha":"^9.0.0","rollup-plugin-terser":"^7.0.2","tslint-config-prettier":"^1.18.0","rollup-plugin-sourcemaps":"^0.6.1","@rollup/plugin-node-resolve":"^13.0.0"},"_npmOperationalInternal":{"tmp":"tmp/tldts_5.7.48_1634201402619_0.8606019759499528","host":"s3://npm-registry-packages"},"readme":"# tldts - Blazing Fast URL Parsing\n\n`tldts` is a JavaScript library to extract hostnames, domains, public suffixes, top-level domains and subdomains from URLs.\n\n**Features**:\n\n1. Tuned for **performance** (order of 0.1 to 1 μs per input)\n2. Handles both URLs and hostnames\n3. Full Unicode/IDNA support\n4. Support parsing email addresses\n5. Detect IPv4 and IPv6 addresses\n6. Continuously updated version of the public suffix list\n7. **TypeScript**, ships with `umd`, `esm`, `cjs` bundles and _type definitions_\n8. Small bundles and small memory footprint\n9. Battle tested: full test coverage and production use\n\n# Install\n\n```bash\nnpm install --save tldts\n```\n\n# Usage\n\nUsing the command-line interface:\n\n```js\n$ npx tldts 'http://www.writethedocs.org/conf/eu/2017/'\n{\n  \"domain\": \"writethedocs.org\",\n  \"domainWithoutSuffix\": \"writethedocs\",\n  \"hostname\": \"www.writethedocs.org\",\n  \"isIcann\": true,\n  \"isIp\": false,\n  \"isPrivate\": false,\n  \"publicSuffix\": \"org\",\n  \"subdomain\": \"www\"\n}\n```\n\nProgrammatically:\n\n```js\nconst { parse } = require('tldts');\n\n// Retrieving hostname related informations of a given URL\nparse('http://www.writethedocs.org/conf/eu/2017/');\n// { domain: 'writethedocs.org',\n//   domainWithoutSuffix: 'writethedocs',\n//   hostname: 'www.writethedocs.org',\n//   isIcann: true,\n//   isIp: false,\n//   isPrivate: false,\n//   publicSuffix: 'org',\n//   subdomain: 'www' }\n```\n\nModern _ES6 modules import_ is also supported:\n\n```js\nimport { parse } from 'tldts';\n```\n\nAlternatively, you can try it _directly in your browser_ here: https://npm.runkit.com/tldts\n\n# API\n\n- `tldts.parse(url | hostname, options)`\n- `tldts.getHostname(url | hostname, options)`\n- `tldts.getDomain(url | hostname, options)`\n- `tldts.getFullDomain(url | hostname, options)`\n- `tldts.getPublicSuffix(url | hostname, options)`\n- `tldts.getSubdomain(url, | hostname, options)`\n- `tldts.getDomainWithoutSuffix(url | hostname, options)`\n\nThe behavior of `tldts` can be customized using an `options` argument for all\nthe functions exposed as part of the public API. This is useful to both change\nthe behavior of the library as well as fine-tune the performance depending on\nyour inputs.\n\n```js\n{\n  // Use suffixes from ICANN section (default: true)\n  allowIcannDomains: boolean;\n  // Use suffixes from Private section (default: false)\n  allowPrivateDomains: boolean;\n  // Extract and validate hostname (default: true)\n  // When set to `false`, inputs will be considered valid hostnames.\n  extractHostname: boolean;\n  // Validate hostnames after parsing (default: true)\n  // If a hostname is not valid, not further processing is performed. When set\n  // to `false`, inputs to the library will be considered valid and parsing will\n  // proceed regardless.\n  validateHostname: boolean;\n  // Perform IP address detection (default: true).\n  detectIp: boolean;\n  // Detect IANA special-use domains (RFC 6761 et al.) and expose the result as\n  // `isSpecialUse` (default: false). Off by default so the common path does no\n  // extra work; the field stays `null` unless this is enabled.\n  detectSpecialUse: boolean;\n  // Assume that both URLs and hostnames can be given as input (default: true)\n  // If set to `false` we assume only URLs will be given as input, which\n  // speed-ups processing.\n  mixedInputs: boolean;\n  // Specifies extra valid suffixes (default: null)\n  validHosts: string[] | null;\n}\n```\n\nThe `parse` method returns handy **properties about a URL or a hostname**.\n\n```js\nconst tldts = require('tldts');\n\ntldts.parse('https://spark-public.s3.amazonaws.com/dataanalysis/loansData.csv');\n// { domain: 'amazonaws.com',\n//   domainWithoutSuffix: 'amazonaws',\n//   hostname: 'spark-public.s3.amazonaws.com',\n//   isIcann: true,\n//   isIp: false,\n//   isPrivate: false,\n//   publicSuffix: 'com',\n//   subdomain: 'spark-public.s3' }\n\ntldts.parse(\n  'https://spark-public.s3.amazonaws.com/dataanalysis/loansData.csv',\n  { allowPrivateDomains: true },\n);\n// { domain: 'spark-public.s3.amazonaws.com',\n//   domainWithoutSuffix: 'spark-public',\n//   hostname: 'spark-public.s3.amazonaws.com',\n//   isIcann: false,\n//   isIp: false,\n//   isPrivate: true,\n//   publicSuffix: 's3.amazonaws.com',\n//   subdomain: '' }\n\ntldts.parse('gopher://domain.unknown/');\n// { domain: 'domain.unknown',\n//   domainWithoutSuffix: 'domain',\n//   hostname: 'domain.unknown',\n//   isIcann: false,\n//   isIp: false,\n//   isPrivate: false,\n//   publicSuffix: 'unknown',\n//   subdomain: '' }\n\ntldts.parse('https://192.168.0.0'); // IPv4\n// { domain: null,\n//   domainWithoutSuffix: null,\n//   hostname: '192.168.0.0',\n//   isIcann: null,\n//   isIp: true,\n//   isPrivate: null,\n//   publicSuffix: null,\n//   subdomain: null }\n\ntldts.parse('https://[::1]'); // IPv6\n// { domain: null,\n//   domainWithoutSuffix: null,\n//   hostname: '::1',\n//   isIcann: null,\n//   isIp: true,\n//   isPrivate: null,\n//   publicSuffix: null,\n//   subdomain: null }\n\ntldts.parse('tldts@emailprovider.co.uk'); // email\n// { domain: 'emailprovider.co.uk',\n//   domainWithoutSuffix: 'emailprovider',\n//   hostname: 'emailprovider.co.uk',\n//   isIcann: true,\n//   isIp: false,\n//   isPrivate: false,\n//   publicSuffix: 'co.uk',\n//   subdomain: '' }\n```\n\n| Property Name         | Type   | Description                                     |\n| :-------------------- | :----- | :---------------------------------------------- |\n| `hostname`            | `str`  | `hostname` of the input extracted automatically |\n| `domain`              | `str`  | Domain (tld + sld)                              |\n| `domainWithoutSuffix` | `str`  | Domain without public suffix                    |\n| `subdomain`           | `str`  | Sub domain (what comes after `domain`)          |\n| `publicSuffix`        | `str`  | Public Suffix (tld) of `hostname`               |\n| `isIcann`             | `bool` | Does TLD come from ICANN part of the list       |\n| `isPrivate`           | `bool` | Does TLD come from Private part of the list     |\n| `isIP`                | `bool` | Is `hostname` an IP address?                    |\n| `isSpecialUse`        | `bool` | Is `hostname` an IANA special-use domain?       |\n\n## Special-use domains (RFC 6761 / IANA)\n\nSet `{ detectSpecialUse: true }` to flag reserved special-use names such as `localhost`, `*.test`, `*.local`, `*.onion`, and `home.arpa` via the `isSpecialUse` result field. `isIcann`/`isPrivate` don't identify these: most aren't in the Public Suffix List, and the few that are (e.g. `onion`, `home.arpa`) appear there as ordinary ICANN suffixes. The field is `null` unless the option is enabled, so the default path does no extra work:\n\n```js\nparse('http://printer.local/', { detectSpecialUse: true });\n// { ...\n//   isSpecialUse: true,\n//   publicSuffix: 'local',\n//   subdomain: '' }\n```\n\nThe list tracks the IANA [Special-Use Domain Names](https://www.iana.org/assignments/special-use-domain-names/) registry.\n\n## Single purpose methods\n\nThese methods are shorthands if you want to retrieve only a single value (and\nwill perform better than `parse` because less work will be needed).\n\n### getHostname(url | hostname, options?)\n\nReturns the hostname from a given string.\n\n```javascript\nconst { getHostname } = require('tldts');\n\ngetHostname('google.com'); // returns `google.com`\ngetHostname('fr.google.com'); // returns `fr.google.com`\ngetHostname('fr.google.google'); // returns `fr.google.google`\ngetHostname('foo.google.co.uk'); // returns `foo.google.co.uk`\ngetHostname('t.co'); // returns `t.co`\ngetHostname('fr.t.co'); // returns `fr.t.co`\ngetHostname(\n  'https://user:password@example.co.uk:8080/some/path?and&query#hash',\n); // returns `example.co.uk`\n```\n\n### getDomain(url | hostname, options?)\n\nReturns the fully qualified domain from a given string.\n\n```javascript\nconst { getDomain } = require('tldts');\n\ngetDomain('google.com'); // returns `google.com`\ngetDomain('fr.google.com'); // returns `google.com`\ngetDomain('fr.google.google'); // returns `google.google`\ngetDomain('foo.google.co.uk'); // returns `google.co.uk`\ngetDomain('t.co'); // returns `t.co`\ngetDomain('fr.t.co'); // returns `t.co`\ngetDomain('https://user:password@example.co.uk:8080/some/path?and&query#hash'); // returns `example.co.uk`\n```\n\n### getFullDomain(url | hostname, options?)\n\nReturns the full domain — the subdomain together with the registrable domain (as\nreturned by `getDomain(...)`), i.e. the whole hostname _including_ any subdomain —\nor `null` when the input has no registrable domain (IP address, single label,\nbare public suffix, …). The result is the normalized hostname (lower-cased,\ntrailing dot stripped); it is not a DNS-absolute name (no trailing root dot) and\nno IDNA/punycode conversion is performed.\n\n```javascript\nconst { getFullDomain } = require('tldts');\n\ngetFullDomain('google.com'); // returns `google.com`\ngetFullDomain('fr.google.com'); // returns `fr.google.com`\ngetFullDomain('foo.google.co.uk'); // returns `foo.google.co.uk`\ngetFullDomain('t.co'); // returns `t.co`\ngetFullDomain('fr.t.co'); // returns `fr.t.co`\ngetFullDomain('1.2.3.4'); // returns null (no registrable domain)\ngetFullDomain('localhost'); // returns null\n```\n\n### getDomainWithoutSuffix(url | hostname, options?)\n\nReturns the domain (as returned by `getDomain(...)`) without the public suffix part.\n\n```javascript\nconst { getDomainWithoutSuffix } = require('tldts');\n\ngetDomainWithoutSuffix('google.com'); // returns `google`\ngetDomainWithoutSuffix('fr.google.com'); // returns `google`\ngetDomainWithoutSuffix('fr.google.google'); // returns `google`\ngetDomainWithoutSuffix('foo.google.co.uk'); // returns `google`\ngetDomainWithoutSuffix('t.co'); // returns `t`\ngetDomainWithoutSuffix('fr.t.co'); // returns `t`\ngetDomainWithoutSuffix(\n  'https://user:password@example.co.uk:8080/some/path?and&query#hash',\n); // returns `example`\n```\n\n### getSubdomain(url | hostname, options?)\n\nReturns the complete subdomain for a given string.\n\n```javascript\nconst { getSubdomain } = require('tldts');\n\ngetSubdomain('google.com'); // returns ``\ngetSubdomain('fr.google.com'); // returns `fr`\ngetSubdomain('google.co.uk'); // returns ``\ngetSubdomain('foo.google.co.uk'); // returns `foo`\ngetSubdomain('moar.foo.google.co.uk'); // returns `moar.foo`\ngetSubdomain('t.co'); // returns ``\ngetSubdomain('fr.t.co'); // returns `fr`\ngetSubdomain(\n  'https://user:password@secure.example.co.uk:443/some/path?and&query#hash',\n); // returns `secure`\n```\n\n### getPublicSuffix(url | hostname, options?)\n\nReturns the [public suffix][] for a given string.\n\n```javascript\nconst { getPublicSuffix } = require('tldts');\n\ngetPublicSuffix('google.com'); // returns `com`\ngetPublicSuffix('fr.google.com'); // returns `com`\ngetPublicSuffix('google.co.uk'); // returns `co.uk`\ngetPublicSuffix('s3.amazonaws.com'); // returns `com`\ngetPublicSuffix('s3.amazonaws.com', { allowPrivateDomains: true }); // returns `s3.amazonaws.com`\ngetPublicSuffix('tld.is.unknown'); // returns `unknown`\n```\n\n# Troubleshooting\n\n## Retrieving subdomain of `localhost` and custom hostnames\n\n`tldts` methods `getDomain` and `getSubdomain` are designed to **work only with _known and valid_ TLDs**.\nThis way, you can trust what a domain is.\n\n`localhost` is a valid hostname but not a TLD. You can pass additional options to each method exposed by `tldts`:\n\n```js\nconst tldts = require('tldts');\n\ntldts.getDomain('localhost'); // returns null\ntldts.getSubdomain('vhost.localhost'); // returns null\n\ntldts.getDomain('localhost', { validHosts: ['localhost'] }); // returns 'localhost'\ntldts.getSubdomain('vhost.localhost', { validHosts: ['localhost'] }); // returns 'vhost'\n```\n\n## Updating the TLDs List\n\n`tldts` made the opinionated choice of shipping with a list of suffixes directly\nin its bundle. There is currently no mechanism to update the lists yourself, but\nwe make sure that the version shipped is always up-to-date.\n\nIf you keep `tldts` updated, the lists should be up-to-date as well!\n\n# Performance\n\n`tldts` is the _fastest JavaScript library_ available for parsing hostnames. It is able to parse _millions of inputs per second_ (typically 2-3M depending on your hardware and inputs). It also offers granular options to fine-tune the behavior and performance of the library depending on the kind of inputs you are dealing with (e.g.: if you know you only manipulate valid hostnames you can disable the hostname extraction step with `{ extractHostname: false }`).\n\nPlease see [this detailed comparison](./comparison/comparison.md) with other available libraries.\n\n## Contributors\n\n`tldts` is based upon the excellent `tld.js` library and would not exist without\nthe many contributors who worked on the project:\n<a href=\"graphs/contributors\"><img src=\"https://opencollective.com/tldjs/contributors.svg?width=890\" /></a>\n\nThis project would not be possible without the amazing Mozilla's\n[public suffix list][]. Thank you for your hard work!\n\n# License\n\n[MIT License](LICENSE).\n\n[badge-ci]: https://secure.travis-ci.org/remusao/tldts.svg?branch=master\n[badge-downloads]: https://img.shields.io/npm/dm/tldts.svg\n[public suffix list]: https://publicsuffix.org/list/\n[list the recent changes]: https://github.com/publicsuffix/list/commits/master\n[changes Atom Feed]: https://github.com/publicsuffix/list/commits/master.atom\n[public suffix]: https://publicsuffix.org/learn/\n","publish_time":1634201402865,"maintainers":[{"name":"remusao","email":"remi.berson@pm.me"}],"_cnpm_publish_time":1634201402865,"dist-tags":{"canary":"5.6.65-canary.808.f42b3ecaee33e5bde4c2ec1c731092a25f9c6a2f.0","latest":"7.6.0"}}