{"name":"tldts","version":"3.0.2","keywords":["tld","sld","domain","browser","uri","url","domain name","subdomain","public suffix"],"author":{"name":"Rémi Berson"},"license":"MIT","_id":"tldts@3.0.2","contributors":[{"url":"https://oncletom.io","name":"Thomas Parisot"}],"homepage":"https://github.com/remusao/tldts","bugs":{"url":"https://github.com/remusao/tldts/issues"},"dist":{"shasum":"28ce00e41afd1a0450897f987a587022183e84eb","tarball":"http://registry-npm.ywwl.com/tldts/download/tldts-3.0.2.tgz","fileCount":35,"integrity":"sha512-5vcPwDwhUdBKLk7dSb86+w5y/33kPOwlUBwBRN3HvVBJGPwp5bO5uEoh3SMi6zCeyYD75cDJTfCW2F3p5lHhcw==","signatures":[{"sig":"MEQCIFyeIOJ77NHXcQ9KMbhNNtVNng/ZmqpTZOwd/fcLVD3/AiAORvmAbiQhFrVCxtEhldtSqtHamHCfX/4uI6JeJok9YA==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":1084606,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbtM0fCRA9TVsSAnZWagAAMT0P+wX+ssCSXWZK/27Hgo6a\nAgIwoAiPIzAZes01Oz27EeT4ynQhXhohw6L1TT80A5QoxHr8fKNx1RrKZkL6\nE5bBPNGQAwNfUl1sA7aUGWsgXxHv/MrygO9cAFvPcr1kFabKvJKREK0JU9J+\nbP6q6LzYdFfdNsr7mErCHyXJ+fbFzIbvYSVGMsj5XVDiYmgjyPF0d37Rwj0h\n5MU0sQ9nwb8/TNH6BRIh6Asdrie6j9tf8AzSWvjIz4JXIg9IBRjBSq/f1RPp\nXk50xRUccNbuSBUW5X6StPzkcdrbxR3wjd1fh4Sc6gJRWE/D9Bc3zeDYYwse\nk0H1NK1NyWgSCixSgUBNNGxEzUbJ5EMetWjtZxWl0jAsOXMSdrvn5KWnXkHX\nEBMKmHcfrqOyCqGZ9LWUWuyFsrCLHWtw/3qBhnXUDkWq8ReHRERekturcqiO\njbSFA1f171ClDia6fzVhQ/IYcXczdG2oilFqiWncw1lwo+s2syAKkQ8TkYBO\nGoxJboIokEDiSRgsY3j+3aEh9hLt7KuAvDulO98FtQxRcms2EMKB5pxAvsDs\nIuwf4u0B/FUkHMop1yxrVO2jmJCh2fdlNdbDYmmwzdZiJrPEBxCksDrAbUPR\nlyHOYoMp4eX0G6tCNnwvAYzfqYCX1+OL5m9z4chOgsVHT5Fj8DESRiW7hMvT\nR1qM\r\n=qAG6\r\n-----END PGP SIGNATURE-----\r\n","size":319555,"noattachment":false,"key":"/tldts/-/tldts-3.0.2.tgz"},"jest":{"preset":"ts-jest","globals":{"ts-jest":{"diagnostics":{"warnOnly":true}}},"moduleFileExtensions":["js","json","node","ts"]},"main":"dist/tldts.js","types":"dist/tldts.d.ts","module":"dist/tldts.es.js","engines":{"node":">= 6"},"gitHead":"d471c335085d144d5f0164e7691442350aa6cced","scripts":{"all":"npm install && npm run update && npm run clean && npm run build && npm run bundle","lint":"tslint -c tslint.json 'lib/**/*.ts'","test":"jest --coverage","build":"tsc -p . --module ES6 --outDir build","clean":"rm -rfv dist build","bundle":"rollup -c rollup.config.js && google-closure-compiler --js=./dist/tldts.js --js_output_file=./dist/tldts.min.js","update":"git submodule foreach git pull origin master && node ./bin/update.js","benchmark":"./bin/benchmark.js"},"_npmUser":{"name":"remusao","email":"remi@cliqz.com"},"repository":{"url":"git://github.com/remusao/tldts.git","type":"git"},"_npmVersion":"6.4.1","description":"Library to work against complex domain names, subdomains and URIs.","directories":{},"jsnext:main":"dist/tldts.es.js","_nodeVersion":"6.14.4","dependencies":{"punycode":"^2.1.1"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^23.5.0","rollup":"^0.65.2","tslint":"^5.11.0","ts-jest":"^23.10.0-beta.5","benchmark":"^2.1.4","typescript":"^3.0.3","@types/jest":"^23.3.2","@types/node":"^10.9.4","concurrently":"^4.0.1","rollup-plugin-cleanup":"^3.0.0","google-closure-compiler":"20180805.0.0","rollup-plugin-node-resolve":"^3.4.0"},"_npmOperationalInternal":{"tmp":"tmp/tldts_3.0.2_1538575646945_0.383591119123627","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":1538575647199,"maintainers":[{"name":"remusao","email":"remi.berson@pm.me"}],"_cnpm_publish_time":1538575647199,"dist-tags":{"canary":"5.6.65-canary.808.f42b3ecaee33e5bde4c2ec1c731092a25f9c6a2f.0","latest":"7.6.0"}}