{"name":"parse-domain","version":"8.2.2","description":"Splits a hostname into subdomains, domain and (effective) top-level domains","keywords":["domain","url","sub-domain","tld","parse","sanitize","top-level"],"type":"module","main":"./build/main.js","types":"./build/main.d.ts","scripts":{"test":"run-p test:*","test:suite":"vitest run --coverage","test:lint":"eslint --max-warnings 0 --cache --ext js,ts --ignore-path .gitignore .","test:format":"prettier --check .","test:types":"tsc --noEmit","build":"run-s build:*","build:cleanup":"rimraf build","build:tsc":"tsc -p ./tsconfig.build.json","build:update":"./bin/update.js","prepare":"run-p prepare:*","prepare:husky":"husky","prepare:build":"npm run build","update:psl-fixture":"npm run node -- ./src/scripts/update-psl-fixture.ts","update:dependencies":"updtr","node":"node --no-warnings --loader ts-node/esm/transpile-only","release":"semantic-release"},"bin":{"parse-domain-update":"bin/update.js"},"repository":{"type":"git","url":"git+https://github.com/peerigon/parse-domain.git"},"author":{"name":"peerigon","email":"developers@peerigon.com"},"license":"MIT","sideEffects":false,"lint-staged":{"*.{ts,tsx,js,cjs,mjs,jsx}":["eslint --cache --fix","prettier --write"],".github/workflows/*.{yml,yaml}":["pin-github-action --allow-empty","prettier --write"],"*.{json,css,md,yml,yaml}":"prettier --write"},"dependencies":{"is-ip":"^5.0.1"},"devDependencies":{"@semantic-release/changelog":"^6.0.3","@semantic-release/git":"^10.0.1","@types/node":"^20.14.12","@vitest/coverage-v8":"^2.0.4","eslint":"^8.57.0","eslint-config-peerigon":"^39.1.0","eslint-plugin-no-null":"^1.0.2","husky":"^9.1.2","lint-staged":"^15.2.7","nock":"^14.0.0-beta.9","npm-run-all":"^4.1.5","pin-github-action":"^1.9.1","prettier":"^3.3.3","rimraf":"^6.0.1","semantic-release":"^24.0.0","ts-node":"^10.9.2","typescript":"^5.5.4","updtr":"^4.1.0","vitest":"^2.0.4"},"publishConfig":{"provenance":true},"_id":"parse-domain@8.2.2","gitHead":"037ca568bd203fff11609d37c8c7a8a8a5df11e7","bugs":{"url":"https://github.com/peerigon/parse-domain/issues"},"homepage":"https://github.com/peerigon/parse-domain#readme","_nodeVersion":"22.6.0","_npmVersion":"10.8.2","dist":{"integrity":"sha512-CoksenD3UDqphCHlXIcNh/TX0dsYLHo6dSAUC/QBcJRWJXcV5rc1mwsS4WbhYGu4LD4Uxc0v3ZzGo+OHCGsLcw==","shasum":"1e88ac5b0cf268ceae6d08c34d53b2bf86de66e5","tarball":"http://registry-npm.ywwl.com/parse-domain/download/parse-domain-8.2.2.tgz","fileCount":69,"unpackedSize":191667,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/parse-domain@8.2.2","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIEuQVB0adqbV6j/tmngUqYiv6ZsoyN6PtNeAHohXYraXAiEA6YiMD7JPkzW1WO4UsfCtUwd7/4rwYhydJ50dBB4HkFA="}],"size":63837,"noattachment":false,"key":"/parse-domain/-/parse-domain-8.2.2.tgz"},"_npmUser":{"name":"peeri","email":"shared@peerigon.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/parse-domain_8.2.2_1723323575018_0.7037524170476273"},"_hasShrinkwrap":false,"readme":"# parse-domain\n\n**Splits a hostname into subdomains, domain and (effective) top-level domains.**\n\n[![Version on NPM](https://img.shields.io/npm/v/parse-domain?style=for-the-badge)](https://www.npmjs.com/package/parse-domain)\n[![Semantically released](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=for-the-badge)](https://github.com/semantic-release/semantic-release)\n[![Monthly downloads on NPM](https://img.shields.io/npm/dm/parse-domain?style=for-the-badge)](https://www.npmjs.com/package/parse-domain)<br>\n[![NPM Bundle size minified](https://img.shields.io/bundlephobia/min/parse-domain?style=for-the-badge)](https://bundlephobia.com/result?p=parse-domain)\n[![NPM Bundle size minified and gzipped](https://img.shields.io/bundlephobia/minzip/parse-domain?style=for-the-badge)](https://bundlephobia.com/result?p=parse-domain)<br>\n[![License](https://img.shields.io/npm/l/parse-domain?style=for-the-badge)](./LICENSE)\n\nSince domain name registrars organize their namespaces in different ways, it's not straight-forward to split a hostname into subdomains, the domain and top-level domains. In order to do that **parse-domain** uses a [large list of known top-level domains](https://publicsuffix.org/list/public_suffix_list.dat) from [publicsuffix.org](https://publicsuffix.org/):\n\n```javascript\nimport { parseDomain, ParseResultType } from \"parse-domain\";\n\nconst parseResult = parseDomain(\n  // This should be a string with basic latin letters only.\n  // More information below.\n  \"www.some.example.co.uk\",\n);\n\n// Check if the domain is listed in the public suffix list\nif (parseResult.type === ParseResultType.Listed) {\n  const { subDomains, domain, topLevelDomains } = parseResult;\n\n  console.log(subDomains); // [\"www\", \"some\"]\n  console.log(domain); // \"example\"\n  console.log(topLevelDomains); // [\"co\", \"uk\"]\n} else {\n  // Read more about other parseResult types below...\n}\n```\n\nThis package has been designed for modern Node and browser environments with ECMAScript modules support. It assumes an ES2015 environment with [`Symbol()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol), [`URL()`](https://developer.mozilla.org/en-US/docs/Web/API/URL) and [`TextDecoder()`](https://developer.mozilla.org/en-US/docs/Web/API/TextEncoder) globally available. You need to transpile it down to ES5 (e.g. by using [Babel](https://babeljs.io/)) if you need to support older environments.\n\nThe list of top-level domains is stored in a [trie](https://en.wikipedia.org/wiki/Trie) data structure and serialization format to ensure the fastest lookup and the smallest possible library size.\n\n<br />\n\n## Installation\n\n```sh\nnpm install parse-domain\n```\n\n## Updates\n\n💡 **Please note:** [publicsuffix.org](https://publicsuffix.org/) is updated several times per month. This package comes with a prebuilt list that has been downloaded at the time of `npm publish`. In order to get an up-to-date list, you should run `npx parse-domain-update` everytime you start or build your application. This will download the latest list from `https://publicsuffix.org/list/public_suffix_list.dat`.\n\n<br />\n\n## Expected input\n\n**⚠️ [`parseDomain`](#api-js-parseDomain) does not parse whole URLs**. You should only pass the [puny-encoded](https://en.wikipedia.org/wiki/Punycode) hostname section of the URL:\n\n| ❌ Wrong                                       | ✅ Correct           |\n| ---------------------------------------------- | -------------------- |\n| `https://user@www.example.com:8080/path?query` | `www.example.com`    |\n| `münchen.de`                                   | `xn--mnchen-3ya.de`  |\n| `食狮.com.cn?query`                            | `xn--85x722f.com.cn` |\n\nThere is the utility function [`fromUrl`](#api-js-fromUrl) which tries to extract the hostname from a (partial) URL and puny-encodes it:\n\n```javascript\nimport { parseDomain, fromUrl } from \"parse-domain\";\n\nconst { subDomains, domain, topLevelDomains } = parseDomain(\n  fromUrl(\"https://www.münchen.de?query\"),\n);\n\nconsole.log(subDomains); // [\"www\"]\nconsole.log(domain); // \"xn--mnchen-3ya\"\nconsole.log(topLevelDomains); // [\"de\"]\n\n// You can use the 'punycode' NPM package to decode the domain again\nimport { toUnicode } from \"punycode\";\n\nconsole.log(toUnicode(domain)); // \"münchen\"\n```\n\n[`fromUrl`](#api-js-fromUrl) parses the URL using [`new URL()`](https://developer.mozilla.org/en-US/docs/Web/API/URL). Depending on your target environments you need to make sure that there is a [polyfill](https://www.npmjs.com/package/whatwg-url) for it. It's globally available in [all modern browsers](https://caniuse.com/#feat=url) (no IE) and in [Node v10](https://nodejs.org/api/url.html#url_class_url).\n\n## Expected output\n\nWhen parsing a hostname there are 5 possible results:\n\n- invalid\n- it is an ip address\n- it is formally correct and the domain is\n  - reserved\n  - not listed in the public suffix list\n  - listed in the public suffix list\n\n[`parseDomain`](#api-js-parseDomain) returns a [`ParseResult`](#api-ts-ParseResult) with a `type` property that allows to distinguish these cases.\n\n### 👉 Invalid domains\n\nThe given input is first validated against [RFC 3696](https://datatracker.ietf.org/doc/html/rfc3696#section-2) (the domain labels are limited to basic latin letters, numbers and hyphens). If the validation fails, `parseResult.type` will be `ParseResultType.Invalid`:\n\n```javascript\nimport { parseDomain, ParseResultType } from \"parse-domain\";\n\nconst parseResult = parseDomain(\"münchen.de\");\n\nconsole.log(parseResult.type === ParseResultType.Invalid); // true\n```\n\nCheck out the [API](#api-ts-ValidationError) if you need more information about the validation error.\n\nIf you don't want the characters to be validated (e.g. because you need to allow underscores in hostnames), there's also a more relaxed validation mode (according to [RFC 2181](https://www.rfc-editor.org/rfc/rfc2181#section-11)).\n\n```javascript\nimport { parseDomain, ParseResultType, Validation } from \"parse-domain\";\n\nconst parseResult = parseDomain(\"_jabber._tcp.gmail.com\", {\n  validation: Validation.Lax,\n});\n\nconsole.log(parseResult.type === ParseResultType.Listed); // true\n```\n\nSee also [#134](https://github.com/peerigon/parse-domain/issues/134) for the discussion.\n\n### 👉 IP addresses\n\nIf the given input is an IP address, `parseResult.type` will be `ParseResultType.Ip`:\n\n```javascript\nimport { parseDomain, ParseResultType } from \"parse-domain\";\n\nconst parseResult = parseDomain(\"192.168.2.1\");\n\nconsole.log(parseResult.type === ParseResultType.Ip); // true\nconsole.log(parseResult.ipVersion); // 4\n```\n\nIt's debatable if a library for parsing domains should also accept IP addresses. In fact, you could argue that [`parseDomain`](#api-js-parseDomain) should reject an IP address as invalid. While this is true from a technical point of view, we decided to report IP addresses in a special way because we assume that a lot of people are using this library to make sense from an arbitrary hostname (see [#102](https://github.com/peerigon/parse-domain/issues/102)).\n\n### 👉 Reserved domains\n\nThere are 5 top-level domains that are not listed in the public suffix list but reserved according to [RFC 6761](https://tools.ietf.org/html/rfc6761) and [RFC 6762](https://tools.ietf.org/html/rfc6762):\n\n- `localhost`\n- `local`\n- `example`\n- `invalid`\n- `test`\n\nIn these cases, `parseResult.type` will be `ParseResultType.Reserved`:\n\n```javascript\nimport { parseDomain, ParseResultType } from \"parse-domain\";\n\nconst parseResult = parseDomain(\"pecorino.local\");\n\nconsole.log(parseResult.type === ParseResultType.Reserved); // true\nconsole.log(parseResult.labels); // [\"pecorino\", \"local\"]\n```\n\n### 👉 Domains that are not listed\n\nIf the given hostname is valid, but not listed in the downloaded public suffix list, `parseResult.type` will be `ParseResultType.NotListed`:\n\n```javascript\nimport { parseDomain, ParseResultType } from \"parse-domain\";\n\nconst parseResult = parseDomain(\"this.is.not-listed\");\n\nconsole.log(parseResult.type === ParseResultType.NotListed); // true\nconsole.log(parseResult.labels); // [\"this\", \"is\", \"not-listed\"]\n```\n\nIf a domain is not listed, it can be caused by an outdated list. Make sure to [update the list once in a while](#installation).\n\n⚠️ **Do not treat parseDomain as authoritative answer.** It cannot replace a real DNS lookup to validate if a given domain is known in a certain network.\n\n### 👉 Effective top-level domains\n\nTechnically, the term _top-level domain_ describes the very last domain in a hostname (`uk` in `example.co.uk`). Most people, however, use the term _top-level domain_ for the _public suffix_ which is a namespace [\"under which Internet users can directly register names\"](https://publicsuffix.org/).\n\nSome examples for public suffixes:\n\n- `com` in `example.com`\n- `co.uk` in `example.co.uk`\n- `co` in `example.co`\n- but also `com.co` in `example.com.co`\n\nIf the hostname is listed in the public suffix list, the `parseResult.type` will be `ParseResultType.Listed`:\n\n```javascript\nimport { parseDomain, ParseResultType } from \"parse-domain\";\n\nconst parseResult = parseDomain(\"example.co.uk\");\n\nconsole.log(parseResult.type === ParseResultType.Listed); // true\nconsole.log(parseResult.labels); // [\"example\", \"co\", \"uk\"]\n```\n\nNow `parseResult` will also provide a `subDomains`, `domain` and `topLevelDomains` property:\n\n```javascript\nconst { subDomains, domain, topLevelDomains } = parseResult;\n\nconsole.log(subDomains); // []\nconsole.log(domain); // \"example\"\nconsole.log(topLevelDomains); // [\"co\", \"uk\"]\n```\n\n### 👉 Switch over `parseResult.type` to distinguish between different parse results\n\nWe recommend switching over the `parseResult.type`:\n\n```javascript\nswitch (parseResult.type) {\n  case ParseResultType.Listed: {\n    const { hostname, topLevelDomains } = parseResult;\n\n    console.log(`${hostname} belongs to ${topLevelDomains.join(\".\")}`);\n    break;\n  }\n  case ParseResultType.Reserved:\n  case ParseResultType.NotListed: {\n    const { hostname } = parseResult;\n\n    console.log(`${hostname} is a reserved or unknown domain`);\n    break;\n  }\n  default:\n    throw new Error(`${hostname} is an ip address or invalid domain`);\n}\n```\n\n### ⚠️ Effective TLDs !== TLDs acknowledged by ICANN\n\nWhat's surprising to a lot of people is that the definition of public suffix means that regular user domains can become effective top-level domains:\n\n```javascript\nconst { subDomains, domain, topLevelDomains } = parseDomain(\n  \"parse-domain.github.io\",\n);\n\nconsole.log(subDomains); // []\nconsole.log(domain); // \"parse-domain\"\nconsole.log(topLevelDomains); // [\"github\", \"io\"] 🤯\n```\n\nIn this case, `github.io` is nothing else than a private domain name registrar. `github.io` is the _effective_ top-level domain and browsers are treating it like that (e.g. for setting [`document.domain`](https://developer.mozilla.org/en-US/docs/Web/API/Document/domain)).\n\nIf you want to deviate from the browser's understanding of a top-level domain and you're only interested in top-level domains acknowledged by [ICANN](https://en.wikipedia.org/wiki/ICANN), there's an `icann` property:\n\n```javascript\nconst parseResult = parseDomain(\"parse-domain.github.io\");\nconst { subDomains, domain, topLevelDomains } = parseResult.icann;\n\nconsole.log(subDomains); // [\"parse-domain\"]\nconsole.log(domain); // \"github\"\nconsole.log(topLevelDomains); // [\"io\"]\n```\n\n### ⚠️ `domain` can also be `undefined`\n\n```javascript\nconst { subDomains, domain, topLevelDomains } = parseDomain(\"co.uk\");\n\nconsole.log(subDomains); // []\nconsole.log(domain); // undefined\nconsole.log(topLevelDomains); // [\"co\", \"uk\"]\n```\n\n### ⚠️ `\"\"` is a valid (but reserved) domain\n\nThe empty string `\"\"` represents the [DNS root](https://en.wikipedia.org/wiki/DNS_root_zone) and is considered to be valid. `parseResult.type` will be `ParseResultType.Reserved` in that case:\n\n```javascript\nconst { type, subDomains, domain, topLevelDomains } = parseDomain(\"\");\n\nconsole.log(type === ParseResultType.Reserved); // true\nconsole.log(subDomains); // []\nconsole.log(domain); // undefined\nconsole.log(topLevelDomains); // []\n```\n\n## API\n\n🧩 = JavaScript export<br>\n🧬 = TypeScript export\n\n<h3 id=\"api-js-parseDomain\">\n🧩 <code>export parseDomain(hostname: string | typeof <a href=\"#api-js-NO_HOSTNAME\">NO_HOSTNAME</a>, options?: <a href=\"#api-ts-ParseDomainOptions\">ParseDomainOptions</a>): <a href=\"#api-ts-ParseResult\">ParseResult</a></code>\n</h3>\n\nTakes a hostname (e.g. `\"www.example.com\"`) and returns a [`ParseResult`](#api-ts-ParseResult). The hostname must only contain basic latin letters, digits, hyphens and dots. International hostnames must be puny-encoded. Does not throw an error, even with invalid input.\n\n```javascript\nimport { parseDomain } from \"parse-domain\";\n\nconst parseResult = parseDomain(\"www.example.com\");\n```\n\nUse `Validation.Lax` if you want to allow all characters:\n\n```javascript\nimport { parseDomain, Validation } from \"parse-domain\";\n\nconst parseResult = parseDomain(\"_jabber._tcp.gmail.com\", {\n  validation: Validation.Lax,\n});\n```\n\n<h3 id=\"api-js-fromUrl\">\n🧩 <code>export fromUrl(input: string): string | typeof <a href=\"#api-js-NO_HOSTNAME\">NO_HOSTNAME</a></code>\n</h3>\n\nTakes a URL-like string and tries to extract the hostname. Requires the global [`URL` constructor](https://developer.mozilla.org/en-US/docs/Web/API/URL) to be available on the platform. Returns the [`NO_HOSTNAME`](#api-js-NO_HOSTNAME) symbol if the input was not a string or the hostname could not be extracted. Take a look [at the test suite](/src/from-url.test.ts) for some examples. Does not throw an error, even with invalid input.\n\n<h3 id=\"api-js-NO_HOSTNAME\">\n🧩 <code>export NO_HOSTNAME: unique symbol</code>\n</h3>\n\n`NO_HOSTNAME` is a symbol that is returned by [`fromUrl`](#api-js-fromUrl) when it was not able to extract a hostname from the given string. When passed to [`parseDomain`](#api-js-parseDomain), it will always yield a [`ParseResultInvalid`](#api-ts-ParseResultInvalid).\n\n<h3 id=\"api-ts-ParseDomainOptions\">\n🧬 <code>export type ParseDomainOptions</code>\n</h3>\n\n```ts\nexport type ParseDomainOptions = {\n  /**\n   * If no validation is specified, Validation.Strict will be used.\n   **/\n  validation?: Validation;\n};\n```\n\n<h3 id=\"api-js-Validation\">\n🧩 <code>export Validation</code>\n</h3>\n\nAn object that holds all possible [Validation](#api-ts-Validation) `validation` values:\n\n```javascript\nexport const Validation = {\n  /**\n   * Allows any octets as labels\n   * but still restricts the length of labels and the overall domain.\n   *\n   * @see https://www.rfc-editor.org/rfc/rfc2181#section-11\n   **/\n  Lax: \"LAX\",\n\n  /**\n   * Only allows ASCII letters, digits and hyphens (aka LDH),\n   * forbids hyphens at the beginning or end of a label\n   * and requires top-level domain names not to be all-numeric.\n   *\n   * This is the default if no validation is configured.\n   *\n   * @see https://datatracker.ietf.org/doc/html/rfc3696#section-2\n   */\n  Strict: \"STRICT\",\n};\n```\n\n<h3 id=\"api-ts-Validation\">\n🧬 <code>export Validation</code>\n</h3>\n\nThis type represents all possible `validation` values.\n\n<h3 id=\"api-ts-ParseResult\">\n🧬 <code>export ParseResult</code>\n</h3>\n\nA `ParseResult` is either a [`ParseResultInvalid`](#api-ts-ParseResultInvalid), [`ParseResultIp`](#api-ts-ParseResultIp), [`ParseResultReserved`](#api-ts-ParseResultReserved), [`ParseResultNotListed`](#api-ts-ParseResultNotListed) or [`ParseResultListed`](#api-ts-ParseResultListed).\n\nAll parse results have a `type` property that is either `\"INVALID\"`, `\"IP\"`,`\"RESERVED\"`,`\"NOT_LISTED\"`or`\"LISTED\"`. Use the exported [ParseResultType](#api-js-ParseResultType) to check for the type instead of checking against string literals.\n\nAll parse results also have a `hostname` property that provides access to the sanitized hostname that was passed to [`parseDomain`](#api-js-parseDomain).\n\n<h3 id=\"api-js-ParseResultType\">\n🧩 <code>export ParseResultType</code>\n</h3>\n\nAn object that holds all possible [ParseResult](#api-ts-ParseResult) `type` values:\n\n```javascript\nconst ParseResultType = {\n  Invalid: \"INVALID\",\n  Ip: \"IP\",\n  Reserved: \"RESERVED\",\n  NotListed: \"NOT_LISTED\",\n  Listed: \"LISTED\",\n};\n```\n\n<h3 id=\"api-ts-ParseResultType\">\n🧬 <code>export ParseResultType</code>\n</h3>\n\nThis type represents all possible [ParseResult](#api-ts-ParseResult) `type` values.\n\n<h3 id=\"api-ts-ParseResultInvalid\">\n🧬 <code>export ParseResultInvalid</code>\n</h3>\n\nDescribes the shape of the parse result that is returned when the given hostname does not adhere to [RFC 1034](https://tools.ietf.org/html/rfc1034):\n\n- The hostname is not a string\n- The hostname is longer than 253 characters\n- A domain label is shorter than 1 character\n- A domain label is longer than 63 characters\n- A domain label contains a character that is not a basic latin character, digit or hyphen\n\n```ts\ntype ParseResultInvalid = {\n  type: ParseResultType.INVALID;\n  hostname: string | typeof NO_HOSTNAME;\n  errors: Array<ValidationError>;\n};\n\n// Example\n\n{\n  type: \"INVALID\",\n  hostname: \".com\",\n  errors: [...]\n}\n```\n\n<h3 id=\"api-ts-ValidationError\">\n🧬 <code>export ValidationError</code>\n</h3>\n\nDescribes the shape of a validation error as returned by [`parseDomain`](#api-js-parseDomain)\n\n```ts\ntype ValidationError = {\n  type: ValidationErrorType;\n  message: string;\n  column: number;\n};\n\n// Example\n\n{\n  type: \"LABEL_MIN_LENGTH\",\n  message: `Label \"\" is too short. Label is 0 octets long but should be at least 1.`,\n  column: 1,\n}\n```\n\n<h3 id=\"api-js-ValidationErrorType\">\n🧩 <code>export ValidationErrorType</code>\n</h3>\n\nAn object that holds all possible [ValidationError](#api-ts-ValidationError) `type` values:\n\n```javascript\nconst ValidationErrorType = {\n  NoHostname: \"NO_HOSTNAME\",\n  DomainMaxLength: \"DOMAIN_MAX_LENGTH\",\n  LabelMinLength: \"LABEL_MIN_LENGTH\",\n  LabelMaxLength: \"LABEL_MAX_LENGTH\",\n  LabelInvalidCharacter: \"LABEL_INVALID_CHARACTER\",\n  LastLabelInvalid: \"LAST_LABEL_INVALID\",\n};\n```\n\n<h3 id=\"api-ts-ValidationErrorType\">\n🧬 <code>export ValidationErrorType</code>\n</h3>\n\nThis type represents all possible `type` values of a [ValidationError](#api-ts-ValidationError).\n\n<h3 id=\"api-ts-ParseResultIp\">\n🧬 <code>export ParseResultIp</code>\n</h3>\n\nThis type describes the shape of the parse result that is returned when the given hostname was an IPv4 or IPv6 address.\n\n```ts\ntype ParseResultIp = {\n  type: ParseResultType.Ip;\n  hostname: string;\n  ipVersion: 4 | 6;\n};\n\n// Example\n\n{\n  type: \"IP\",\n  hostname: \"192.168.0.1\",\n  ipVersion: 4\n}\n```\n\nAccording to [RFC 3986](https://tools.ietf.org/html/rfc3986#section-3.2.2), IPv6 addresses need to be surrounded by `[` and `]` in URLs. [`parseDomain`](#api-js-parseDomain) accepts both IPv6 address with and without square brackets:\n\n```js\n// Recognized as IPv4 address\nparseDomain(\"192.168.0.1\");\n// Both are recognized as proper IPv6 addresses\nparseDomain(\"::\");\nparseDomain(\"[::]\");\n```\n\n<h3 id=\"api-ts-ParseResultReserved\">\n🧬 <code>export ParseResultReserved</code>\n</h3>\n\nThis type describes the shape of the parse result that is returned when the given hostname\n\n- is the root domain (the empty string `\"\"`)\n- belongs to the top-level domain `localhost`, `local`, `example`, `invalid` or `test`\n\n```ts\ntype ParseResultReserved = {\n  type: ParseResultType.Reserved;\n  hostname: string;\n  labels: Array<string>;\n};\n\n// Example\n\n{\n  type: \"RESERVED\",\n  hostname: \"pecorino.local\",\n  labels: [\"pecorino\", \"local\"]\n}\n```\n\n⚠️ Reserved IPs, such as `127.0.0.1`, will not be reported as reserved, but as <a href=\"#-export-parseresultip\">`ParseResultIp`</a>. See [#117](https://github.com/peerigon/parse-domain/issues/117).\n\n<h3 id=\"api-ts-ParseResultNotListed\">\n🧬 <code>export ParseResultNotListed</code>\n</h3>\n\nDescribes the shape of the parse result that is returned when the given hostname is valid and does not belong to a reserved top-level domain, but is not listed in the downloaded public suffix list.\n\n```ts\ntype ParseResultNotListed = {\n  type: ParseResultType.NotListed;\n  hostname: string;\n  labels: Array<string>;\n};\n\n// Example\n\n{\n  type: \"NOT_LISTED\",\n  hostname: \"this.is.not-listed\",\n  labels: [\"this\", \"is\", \"not-listed\"]\n}\n```\n\n<h3 id=\"api-ts-ParseResultListed\">\n🧬 <code>export ParseResultListed</code>\n</h3>\n\nDescribes the shape of the parse result that is returned when the given hostname belongs to a top-level domain that is listed in the public suffix list.\n\n```ts\ntype ParseResultListed = {\n  type: ParseResultType.Listed;\n  hostname: string;\n  labels: Array<string>;\n  subDomains: Array<string>;\n  domain: string | undefined;\n  topLevelDomains: Array<string>;\n  icann: {\n    subDomains: Array<string>;\n    domain: string | undefined;\n    topLevelDomains: Array<string>;\n  };\n};\n\n// Example\n\n{\n  type: \"LISTED\",\n  hostname: \"parse-domain.github.io\",\n  labels: [\"parse-domain\", \"github\", \"io\"]\n  subDomains: [],\n  domain: \"parse-domain\",\n  topLevelDomains: [\"github\", \"io\"],\n  icann: {\n    subDomains: [\"parse-domain\"],\n    domain: \"github\",\n    topLevelDomains: [\"io\"]\n  }\n}\n```\n\n## License\n\nMIT\n\n## Sponsors\n\n[<img src=\"https://assets.peerigon.com/peerigon/logo/peerigon-logo-flat-spinat.png\" width=\"150\" />](https://peerigon.com)\n","publish_time":1723323575221,"maintainers":[{"name":"jhnns","email":"mail@johannesewald.de"},{"name":"meaku","email":"michael.jaser@peerigon.com"},{"name":"peeri","email":"shared@peerigon.com"},{"name":"matthaias","email":"matthias.jahn@peerigon.com"},{"name":"leomelzer","email":"leonhard.melzer@peerigon.com"},{"name":"antosan","email":"sandeantony@gmail.com"},{"name":"moritzjacobs","email":"mail@moritzjacobs.de"},{"name":"hpohlmeyer","email":"henning.pohlmeyer@peerigon.com"}],"_cnpm_publish_time":1723323575221,"dist-tags":{"beta":"3.0.0-beta.10","latest":"8.4.0"}}