Socket
Socket
Sign inDemoInstall

parse-domain

Package Overview
Dependencies
10
Maintainers
10
Versions
53
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.0.0-beta.9 to 3.0.0-beta.10

34

build-cjs/src/parse-domain.d.ts

@@ -1,2 +0,2 @@

import { ValidationError } from "./sanitize";
import { ValidationError, SanitizationResultValidIp } from "./sanitize";
import { NO_HOSTNAME } from "./from-url";

@@ -10,4 +10,19 @@ export declare const RESERVED_TOP_LEVEL_DOMAINS: string[];

Invalid = "INVALID",
/**
* This parse result is returned if the given hostname was an IPv4 or IPv6.
*/
Ip = "IP",
/**
* This parse result is returned when the given hostname
* - is the root domain (the empty string `""`)
* - belongs to the top-level domain `localhost`, `local`, `example`, `invalid` or `test`
*/
Reserved = "RESERVED",
/**
* This parse result is returned when the given hostname is valid and does not belong to a reserved top-level domain, but is not listed in the public suffix list.
*/
NotListed = "NOT_LISTED",
/**
* This parse result is returned when the given hostname belongs to a top-level domain that is listed in the public suffix list.
*/
Listed = "LISTED"

@@ -31,10 +46,11 @@ }

};
declare type ParseResultCommonValid = {
declare type ParseResultCommonValidDomain = {
/**
* An array with labels that were separated by a dot character in the given hostname.
* An array of labels that were separated by a dot character in the given hostname.
*/
domains: Array<Label>;
labels: Array<Label>;
};
export declare type ParseResultReserved = ParseResultCommon<ParseResultType.Reserved> & ParseResultCommonValid;
export declare type ParseResultNotListed = ParseResultCommon<ParseResultType.NotListed> & ParseResultCommonValid;
export declare type ParseResultIp = ParseResultCommon<ParseResultType.Ip> & Pick<SanitizationResultValidIp, "ipVersion">;
export declare type ParseResultReserved = ParseResultCommon<ParseResultType.Reserved> & ParseResultCommonValidDomain;
export declare type ParseResultNotListed = ParseResultCommon<ParseResultType.NotListed> & ParseResultCommonValidDomain;
declare type ParseResultListedDomains = {

@@ -54,3 +70,3 @@ /**

};
export declare type ParseResultListed = ParseResultCommon<ParseResultType.Listed> & ParseResultCommonValid & ParseResultListedDomains & {
export declare type ParseResultListed = ParseResultCommon<ParseResultType.Listed> & ParseResultCommonValidDomain & ParseResultListedDomains & {
/**

@@ -61,7 +77,7 @@ * The parse result according to ICANN only without private top-level domains.

};
export declare type ParseResult = ParseResultInvalid | ParseResultReserved | ParseResultNotListed | ParseResultListed;
export declare type ParseResult = ParseResultInvalid | ParseResultIp | ParseResultReserved | ParseResultNotListed | ParseResultListed;
/**
* Splits the given hostname in topLevelDomains, a domain and subDomains.
*/
export declare const parseDomain: (input: string | typeof NO_HOSTNAME) => ParseResult;
export declare const parseDomain: (hostname: string | typeof NO_HOSTNAME) => ParseResult;
export {};

@@ -20,4 +20,19 @@ "use strict";

ParseResultType["Invalid"] = "INVALID";
/**
* This parse result is returned if the given hostname was an IPv4 or IPv6.
*/
ParseResultType["Ip"] = "IP";
/**
* This parse result is returned when the given hostname
* - is the root domain (the empty string `""`)
* - belongs to the top-level domain `localhost`, `local`, `example`, `invalid` or `test`
*/
ParseResultType["Reserved"] = "RESERVED";
/**
* This parse result is returned when the given hostname is valid and does not belong to a reserved top-level domain, but is not listed in the public suffix list.
*/
ParseResultType["NotListed"] = "NOT_LISTED";
/**
* This parse result is returned when the given hostname belongs to a top-level domain that is listed in the public suffix list.
*/
ParseResultType["Listed"] = "LISTED";

@@ -40,12 +55,19 @@ })(ParseResultType = exports.ParseResultType || (exports.ParseResultType = {}));

*/
exports.parseDomain = (input) => {
const sanitizationResult = sanitize_1.sanitize(input);
exports.parseDomain = (hostname) => {
const sanitizationResult = sanitize_1.sanitize(hostname);
if (sanitizationResult.type === sanitize_1.SanitizationResultType.Error) {
return {
type: ParseResultType.Invalid,
hostname: input,
hostname,
errors: sanitizationResult.errors,
};
}
const { originalInput: hostname, labels } = sanitizationResult;
if (sanitizationResult.type === sanitize_1.SanitizationResultType.ValidIp) {
return {
type: ParseResultType.Ip,
hostname: sanitizationResult.ip,
ipVersion: sanitizationResult.ipVersion,
};
}
const { labels, domain } = sanitizationResult;
if (hostname === "" ||

@@ -55,4 +77,4 @@ exports.RESERVED_TOP_LEVEL_DOMAINS.includes(labels[labels.length - 1])) {

type: ParseResultType.Reserved,
hostname,
domains: labels,
hostname: domain,
labels,
};

@@ -68,4 +90,4 @@ }

type: ParseResultType.NotListed,
hostname,
domains: labels,
hostname: domain,
labels,
};

@@ -75,4 +97,4 @@ }

const indexOfIcannDomain = labels.length - icannTlds.length - 1;
return Object.assign({ hostname, type: ParseResultType.Listed, domains: labels, icann: splitLabelsIntoDomains(labels, indexOfIcannDomain) }, splitLabelsIntoDomains(labels, indexOfPublicSuffixDomain));
return Object.assign({ type: ParseResultType.Listed, hostname: domain, labels, icann: splitLabelsIntoDomains(labels, indexOfIcannDomain) }, splitLabelsIntoDomains(labels, indexOfPublicSuffixDomain));
};
//# sourceMappingURL=parse-domain.js.map

@@ -0,1 +1,2 @@

import isIp from "is-ip";
import { Label } from "./parse-domain";

@@ -16,8 +17,14 @@ import { NO_HOSTNAME } from "./from-url";

export declare enum SanitizationResultType {
Ok = "OK",
ValidIp = "VALID_IP",
ValidDomain = "VALID_DOMAIN",
Error = "ERROR"
}
export declare type SanitizationResultOk = {
type: SanitizationResultType.Ok;
originalInput: string;
export declare type SanitizationResultValidIp = {
type: SanitizationResultType.ValidIp;
ip: string;
ipVersion: Exclude<ReturnType<typeof isIp.version>, undefined>;
};
export declare type SanitizationResultValidDomain = {
type: SanitizationResultType.ValidDomain;
domain: string;
labels: Array<Label>;

@@ -27,6 +34,5 @@ };

type: SanitizationResultType.Error;
originalInput: string | unknown;
errors: Array<ValidationError>;
};
export declare type SanitizationResult = SanitizationResultOk | SanitizationResultError;
export declare type SanitizationResult = SanitizationResultValidIp | SanitizationResultValidDomain | SanitizationResultError;
export declare const sanitize: (input: string | typeof NO_HOSTNAME) => SanitizationResult;
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
// eslint-disable-next-line import/default
const is_ip_1 = __importDefault(require("is-ip"));
// See https://en.wikipedia.org/wiki/Domain_name

@@ -20,3 +25,4 @@ // See https://tools.ietf.org/html/rfc1034

(function (SanitizationResultType) {
SanitizationResultType["Ok"] = "OK";
SanitizationResultType["ValidIp"] = "VALID_IP";
SanitizationResultType["ValidDomain"] = "VALID_DOMAIN";
SanitizationResultType["Error"] = "ERROR";

@@ -67,14 +73,24 @@ })(SanitizationResultType = exports.SanitizationResultType || (exports.SanitizationResultType = {}));

type: SanitizationResultType.Error,
originalInput: input,
errors: [createNoHostnameError(input)],
};
}
if (input.length > DOMAIN_LENGTH_MAX) {
const inputTrimmed = input.trim();
// IPv6 addresses are surrounded by square brackets in URLs
// See https://tools.ietf.org/html/rfc3986#section-3.2.2
const inputTrimmedAsIp = inputTrimmed.replace(/^\[|]$/g, "");
const ipVersion = is_ip_1.default.version(inputTrimmedAsIp);
if (ipVersion !== undefined) {
return {
type: SanitizationResultType.ValidIp,
ip: inputTrimmedAsIp,
ipVersion,
};
}
if (inputTrimmed.length > DOMAIN_LENGTH_MAX) {
return {
type: SanitizationResultType.Error,
originalInput: input,
errors: [createDomainMaxLengthError(input)],
errors: [createDomainMaxLengthError(inputTrimmed)],
};
}
const labels = input.split(LABEL_SEPARATOR);
const labels = inputTrimmed.split(LABEL_SEPARATOR);
const lastLabel = labels[labels.length - 1];

@@ -92,3 +108,3 @@ // If the last label is the special root label, ignore it

if (invalidCharacter) {
labelValidationErrors.push(createLabelInvalidCharacterError(label, invalidCharacter[0], invalidCharacter.index));
labelValidationErrors.push(createLabelInvalidCharacterError(label, invalidCharacter[0], invalidCharacter.index + 1));
}

@@ -109,3 +125,2 @@ else if (

type: SanitizationResultType.Error,
originalInput: input,
errors: labelValidationErrors,

@@ -115,4 +130,4 @@ };

return {
type: SanitizationResultType.Ok,
originalInput: input,
type: SanitizationResultType.ValidDomain,
domain: inputTrimmed,
labels,

@@ -119,0 +134,0 @@ };

@@ -8,3 +8,3 @@ "use strict";

type: "LISTED",
domains: ["www", "example", "com"],
labels: ["www", "example", "com"],
subDomains: ["www"],

@@ -22,3 +22,3 @@ domain: "example",

type: "LISTED",
domains: ["www", "example", "co", "uk"],
labels: ["www", "example", "co", "uk"],
subDomains: ["www"],

@@ -36,3 +36,3 @@ domain: "example",

type: "LISTED",
domains: ["www", "example", "cloudfront", "net"],
labels: ["www", "example", "cloudfront", "net"],
subDomains: ["www"],

@@ -52,3 +52,3 @@ domain: "example",

type: "LISTED",
domains: ["www", "xn--85x722f", "xn--55qx5d", "cn"],
labels: ["www", "xn--85x722f", "xn--55qx5d", "cn"],
subDomains: ["www"],

@@ -55,0 +55,0 @@ domain: "xn--85x722f",

@@ -1,2 +0,2 @@

import { ValidationError } from "./sanitize";
import { ValidationError, SanitizationResultValidIp } from "./sanitize";
import { NO_HOSTNAME } from "./from-url";

@@ -10,4 +10,19 @@ export declare const RESERVED_TOP_LEVEL_DOMAINS: string[];

Invalid = "INVALID",
/**
* This parse result is returned if the given hostname was an IPv4 or IPv6.
*/
Ip = "IP",
/**
* This parse result is returned when the given hostname
* - is the root domain (the empty string `""`)
* - belongs to the top-level domain `localhost`, `local`, `example`, `invalid` or `test`
*/
Reserved = "RESERVED",
/**
* This parse result is returned when the given hostname is valid and does not belong to a reserved top-level domain, but is not listed in the public suffix list.
*/
NotListed = "NOT_LISTED",
/**
* This parse result is returned when the given hostname belongs to a top-level domain that is listed in the public suffix list.
*/
Listed = "LISTED"

@@ -31,10 +46,11 @@ }

};
declare type ParseResultCommonValid = {
declare type ParseResultCommonValidDomain = {
/**
* An array with labels that were separated by a dot character in the given hostname.
* An array of labels that were separated by a dot character in the given hostname.
*/
domains: Array<Label>;
labels: Array<Label>;
};
export declare type ParseResultReserved = ParseResultCommon<ParseResultType.Reserved> & ParseResultCommonValid;
export declare type ParseResultNotListed = ParseResultCommon<ParseResultType.NotListed> & ParseResultCommonValid;
export declare type ParseResultIp = ParseResultCommon<ParseResultType.Ip> & Pick<SanitizationResultValidIp, "ipVersion">;
export declare type ParseResultReserved = ParseResultCommon<ParseResultType.Reserved> & ParseResultCommonValidDomain;
export declare type ParseResultNotListed = ParseResultCommon<ParseResultType.NotListed> & ParseResultCommonValidDomain;
declare type ParseResultListedDomains = {

@@ -54,3 +70,3 @@ /**

};
export declare type ParseResultListed = ParseResultCommon<ParseResultType.Listed> & ParseResultCommonValid & ParseResultListedDomains & {
export declare type ParseResultListed = ParseResultCommon<ParseResultType.Listed> & ParseResultCommonValidDomain & ParseResultListedDomains & {
/**

@@ -61,7 +77,7 @@ * The parse result according to ICANN only without private top-level domains.

};
export declare type ParseResult = ParseResultInvalid | ParseResultReserved | ParseResultNotListed | ParseResultListed;
export declare type ParseResult = ParseResultInvalid | ParseResultIp | ParseResultReserved | ParseResultNotListed | ParseResultListed;
/**
* Splits the given hostname in topLevelDomains, a domain and subDomains.
*/
export declare const parseDomain: (input: string | typeof NO_HOSTNAME) => ParseResult;
export declare const parseDomain: (hostname: string | typeof NO_HOSTNAME) => ParseResult;
export {};
import { icannTrie, privateTrie } from "./serialized-tries";
import { lookUpTldsInTrie } from "./trie/look-up";
import { sanitize, SanitizationResultType } from "./sanitize";
import { sanitize, SanitizationResultType, } from "./sanitize";
import { parseTrie } from "./trie/parse-trie";

@@ -18,4 +18,19 @@ export const RESERVED_TOP_LEVEL_DOMAINS = [

ParseResultType["Invalid"] = "INVALID";
/**
* This parse result is returned if the given hostname was an IPv4 or IPv6.
*/
ParseResultType["Ip"] = "IP";
/**
* This parse result is returned when the given hostname
* - is the root domain (the empty string `""`)
* - belongs to the top-level domain `localhost`, `local`, `example`, `invalid` or `test`
*/
ParseResultType["Reserved"] = "RESERVED";
/**
* This parse result is returned when the given hostname is valid and does not belong to a reserved top-level domain, but is not listed in the public suffix list.
*/
ParseResultType["NotListed"] = "NOT_LISTED";
/**
* This parse result is returned when the given hostname belongs to a top-level domain that is listed in the public suffix list.
*/
ParseResultType["Listed"] = "LISTED";

@@ -38,12 +53,19 @@ })(ParseResultType || (ParseResultType = {}));

*/
export const parseDomain = (input) => {
const sanitizationResult = sanitize(input);
export const parseDomain = (hostname) => {
const sanitizationResult = sanitize(hostname);
if (sanitizationResult.type === SanitizationResultType.Error) {
return {
type: ParseResultType.Invalid,
hostname: input,
hostname,
errors: sanitizationResult.errors,
};
}
const { originalInput: hostname, labels } = sanitizationResult;
if (sanitizationResult.type === SanitizationResultType.ValidIp) {
return {
type: ParseResultType.Ip,
hostname: sanitizationResult.ip,
ipVersion: sanitizationResult.ipVersion,
};
}
const { labels, domain } = sanitizationResult;
if (hostname === "" ||

@@ -53,4 +75,4 @@ RESERVED_TOP_LEVEL_DOMAINS.includes(labels[labels.length - 1])) {

type: ParseResultType.Reserved,
hostname,
domains: labels,
hostname: domain,
labels,
};

@@ -66,4 +88,4 @@ }

type: ParseResultType.NotListed,
hostname,
domains: labels,
hostname: domain,
labels,
};

@@ -73,4 +95,4 @@ }

const indexOfIcannDomain = labels.length - icannTlds.length - 1;
return Object.assign({ hostname, type: ParseResultType.Listed, domains: labels, icann: splitLabelsIntoDomains(labels, indexOfIcannDomain) }, splitLabelsIntoDomains(labels, indexOfPublicSuffixDomain));
return Object.assign({ type: ParseResultType.Listed, hostname: domain, labels, icann: splitLabelsIntoDomains(labels, indexOfIcannDomain) }, splitLabelsIntoDomains(labels, indexOfPublicSuffixDomain));
};
//# sourceMappingURL=parse-domain.js.map

@@ -0,1 +1,2 @@

import isIp from "is-ip";
import { Label } from "./parse-domain";

@@ -16,8 +17,14 @@ import { NO_HOSTNAME } from "./from-url";

export declare enum SanitizationResultType {
Ok = "OK",
ValidIp = "VALID_IP",
ValidDomain = "VALID_DOMAIN",
Error = "ERROR"
}
export declare type SanitizationResultOk = {
type: SanitizationResultType.Ok;
originalInput: string;
export declare type SanitizationResultValidIp = {
type: SanitizationResultType.ValidIp;
ip: string;
ipVersion: Exclude<ReturnType<typeof isIp.version>, undefined>;
};
export declare type SanitizationResultValidDomain = {
type: SanitizationResultType.ValidDomain;
domain: string;
labels: Array<Label>;

@@ -27,6 +34,5 @@ };

type: SanitizationResultType.Error;
originalInput: string | unknown;
errors: Array<ValidationError>;
};
export declare type SanitizationResult = SanitizationResultOk | SanitizationResultError;
export declare type SanitizationResult = SanitizationResultValidIp | SanitizationResultValidDomain | SanitizationResultError;
export declare const sanitize: (input: string | typeof NO_HOSTNAME) => SanitizationResult;

@@ -0,1 +1,3 @@

// eslint-disable-next-line import/default
import isIp from "is-ip";
// See https://en.wikipedia.org/wiki/Domain_name

@@ -18,3 +20,4 @@ // See https://tools.ietf.org/html/rfc1034

(function (SanitizationResultType) {
SanitizationResultType["Ok"] = "OK";
SanitizationResultType["ValidIp"] = "VALID_IP";
SanitizationResultType["ValidDomain"] = "VALID_DOMAIN";
SanitizationResultType["Error"] = "ERROR";

@@ -65,14 +68,24 @@ })(SanitizationResultType || (SanitizationResultType = {}));

type: SanitizationResultType.Error,
originalInput: input,
errors: [createNoHostnameError(input)],
};
}
if (input.length > DOMAIN_LENGTH_MAX) {
const inputTrimmed = input.trim();
// IPv6 addresses are surrounded by square brackets in URLs
// See https://tools.ietf.org/html/rfc3986#section-3.2.2
const inputTrimmedAsIp = inputTrimmed.replace(/^\[|]$/g, "");
const ipVersion = isIp.version(inputTrimmedAsIp);
if (ipVersion !== undefined) {
return {
type: SanitizationResultType.ValidIp,
ip: inputTrimmedAsIp,
ipVersion,
};
}
if (inputTrimmed.length > DOMAIN_LENGTH_MAX) {
return {
type: SanitizationResultType.Error,
originalInput: input,
errors: [createDomainMaxLengthError(input)],
errors: [createDomainMaxLengthError(inputTrimmed)],
};
}
const labels = input.split(LABEL_SEPARATOR);
const labels = inputTrimmed.split(LABEL_SEPARATOR);
const lastLabel = labels[labels.length - 1];

@@ -90,3 +103,3 @@ // If the last label is the special root label, ignore it

if (invalidCharacter) {
labelValidationErrors.push(createLabelInvalidCharacterError(label, invalidCharacter[0], invalidCharacter.index));
labelValidationErrors.push(createLabelInvalidCharacterError(label, invalidCharacter[0], invalidCharacter.index + 1));
}

@@ -107,3 +120,2 @@ else if (

type: SanitizationResultType.Error,
originalInput: input,
errors: labelValidationErrors,

@@ -113,4 +125,4 @@ };

return {
type: SanitizationResultType.Ok,
originalInput: input,
type: SanitizationResultType.ValidDomain,
domain: inputTrimmed,
labels,

@@ -117,0 +129,0 @@ };

@@ -6,3 +6,3 @@ import { deepStrictEqual } from "assert";

type: "LISTED",
domains: ["www", "example", "com"],
labels: ["www", "example", "com"],
subDomains: ["www"],

@@ -20,3 +20,3 @@ domain: "example",

type: "LISTED",
domains: ["www", "example", "co", "uk"],
labels: ["www", "example", "co", "uk"],
subDomains: ["www"],

@@ -34,3 +34,3 @@ domain: "example",

type: "LISTED",
domains: ["www", "example", "cloudfront", "net"],
labels: ["www", "example", "cloudfront", "net"],
subDomains: ["www"],

@@ -50,3 +50,3 @@ domain: "example",

type: "LISTED",
domains: ["www", "xn--85x722f", "xn--55qx5d", "cn"],
labels: ["www", "xn--85x722f", "xn--55qx5d", "cn"],
subDomains: ["www"],

@@ -53,0 +53,0 @@ domain: "xn--85x722f",

@@ -0,1 +1,8 @@

# [3.0.0-beta.10](https://github.com/peerigon/parse-domain/compare/v3.0.0-beta.9...v3.0.0-beta.10) (2020-04-23)
### Features
* Trigger beta release for next major version ([5443240](https://github.com/peerigon/parse-domain/commit/5443240d009b21284d707d6d22a1656970f8a699))
# [3.0.0-beta.9](https://github.com/peerigon/parse-domain/compare/v3.0.0-beta.8...v3.0.0-beta.9) (2020-04-20)

@@ -2,0 +9,0 @@

{
"name": "parse-domain",
"version": "3.0.0-beta.9",
"version": "3.0.0-beta.10",
"description": "Splits a hostname into subdomains, domain and (effective) top-level domains",

@@ -52,2 +52,3 @@ "keywords": [

"dependencies": {
"is-ip": "^3.1.0",
"node-fetch": "^2.6.0",

@@ -54,0 +55,0 @@ "punycode": "^2.1.1"

@@ -13,3 +13,3 @@ # parse-domain

Since domain name registrars organize their namespaces in different ways, it's not straight-forward to recognize subdomains, the domain and top-level domains in a hostname. **parse-domain** validates the given hostname against [RFC 1034](https://tools.ietf.org/html/rfc1034) and uses a [large list of known top-level domains](https://publicsuffix.org/list/public_suffix_list.dat) from publicsuffix.org to split a hostname into subdomains, domain and top-level domains:
Since 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. **parse-domain** validates the given hostname against [RFC 1034](https://tools.ietf.org/html/rfc1034) and uses a [large list of known top-level domains](https://publicsuffix.org/list/public_suffix_list.dat) from publicsuffix.org to do that:

@@ -30,5 +30,5 @@ ```javascript

This module uses a [trie](https://en.wikipedia.org/wiki/Trie) data structure under the hood to ensure the smallest possible library size and the fastest lookup. The library is roughly 30KB minified and gzipped.
This package has been designed for modern Node and browser environments. It assumes an ES2015 environment with `Symbol()` and the global [`URL` constructor](https://developer.mozilla.org/en-US/docs/Web/API/URL) available. You need to transpile it down to ES5 (e.g. by using [Babel](https://babeljs.io/)) if you need to support older environments.
This module also assumes an ES2015 environment. You need to transpile it down to ES5 (e.g. by using [Babel](https://babeljs.io/)) if you need to support older environments.
The 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. The library is roughly 30KB minified and gzipped.

@@ -82,6 +82,7 @@ <br />

When parsing a domain there are 4 possible results:
When parsing a hostname there are 5 possible results:
- invalid
- formally correct and the domain name
- it is an IPv4 or IPv6 address
- formally correct and the domain
- is reserved

@@ -107,2 +108,17 @@ - is not listed in the public suffix list

### 👉 IP addresses
If the given input is an IP address, `parseResult.type` will be `ParseResultType.Ip`:
```javascript
import {parseDomain, ParseResultType} from "parse-domain";
const parseResult = parseDomain("192.168.2.1");
console.log(parseResult.type === ParseResultType.Ip); // true
console.log(parseResult.ipVersion); // 4
```
It'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 domain. 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 out of a hostname (see [#102](https://github.com/peerigon/parse-domain/issues/102)).
### 👉 Reserved domains

@@ -126,3 +142,3 @@

console.log(parseResult.type === ParseResultType.Reserved); // true
console.log(parseResult.domains); // ["pecorino", "local"]
console.log(parseResult.labels); // ["pecorino", "local"]
```

@@ -140,3 +156,3 @@

console.log(parseResult.type === ParseResultType.NotListed); // true
console.log(parseResult.domains); // ["this", "is", "not-listed"]
console.log(parseResult.labels); // ["this", "is", "not-listed"]
```

@@ -159,3 +175,3 @@

If the hostname contains domains from the public suffix list, the `parseResult.type` will be `ParseResultType.Listed`:
If the hostname is listed in the public suffix list, the `parseResult.type` will be `ParseResultType.Listed`:

@@ -168,3 +184,3 @@ ```javascript

console.log(parseResult.type === ParseResultType.Listed); // true
console.log(parseResult.domains); // ["example", "co", "uk"]
console.log(parseResult.labels); // ["example", "co", "uk"]
```

@@ -202,3 +218,3 @@

default:
throw new Error(`${hostname} is an invalid domain`);
throw new Error(`${hostname} is an ip address or invalid domain`);
}

@@ -305,2 +321,3 @@ ```

Invalid: "INVALID",
Ip: "IP",
Reserved: "RESERVED",

@@ -390,2 +407,34 @@ NotListed: "NOT_LISTED",

<h3 id="api-ts-ParseResultIp">
🧬 <code>export ParseResultIp</code>
</h3>
This type describes the shape of the parse result that is returned when the given hostname was an IPv4 or IPv6 address.
```ts
type ParseResultIp = {
type: ParseResultType.Ip;
hostname: string;
ipVersion: 4 | 6;
};
// Example
{
type: "IP",
hostname: "192.168.0.1",
ipVersion: 4
}
```
According 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:
```js
// Recognized as IPv4 address
parseDomain("192.168.0.1");
// Both are recognized as proper IPv6 addresses
parseDomain("::");
parseDomain("[::]");
```
<h3 id="api-ts-ParseResultReserved">

@@ -404,3 +453,3 @@ 🧬 <code>export ParseResultReserved</code>

hostname: string;
domains: Array<string>;
labels: Array<string>;
};

@@ -413,3 +462,3 @@

hostname: "pecorino.local",
domains: ["pecorino", "local"]
labels: ["pecorino", "local"]
}

@@ -428,3 +477,3 @@ ```

hostname: string;
domains: Array<string>;
labels: Array<string>;
};

@@ -437,3 +486,3 @@

hostname: "this.is.not-listed",
domains: ["this", "is", "not-listed"]
labels: ["this", "is", "not-listed"]
}

@@ -446,3 +495,3 @@ ```

Describes 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:
Describes 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.

@@ -453,3 +502,3 @@ ```ts

hostname: string;
domains: Array<string>;
labels: Array<string>;
subDomains: Array<string>;

@@ -470,3 +519,3 @@ domain: string | undefined;

hostname: "parse-domain.github.io",
domains: ["parse-domain", "github", "io"]
labels: ["parse-domain", "github", "io"]
subDomains: [],

@@ -473,0 +522,0 @@ domain: "parse-domain",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc