parse-domain
- Version 8.2.2
- Published
- 192 kB
- 1 dependency
- MIT license
Install
npm i parse-domain
yarn add parse-domain
pnpm add parse-domain
Overview
Splits a hostname into subdomains, domain and (effective) top-level domains
Index
Variables
Functions
Enums
Type Aliases
Variables
variable NO_HOSTNAME
const NO_HOSTNAME: Symbol;
Functions
function fromUrl
fromUrl: (urlLike: string) => string | typeof NO_HOSTNAME;
function parseDomain
parseDomain: ( hostname: string | typeof NO_HOSTNAME, options?: ParseDomainOptions) => ParseResult;
Splits the given hostname in topLevelDomains, a domain and subDomains.
Enums
enum ParseResultType
enum ParseResultType { Invalid = 'INVALID', Ip = 'IP', Reserved = 'RESERVED', NotListed = 'NOT_LISTED', Listed = 'LISTED',}
member Invalid
Invalid = 'INVALID'
This parse result is returned in case the given hostname does not adhere to [RFC 1034](https://tools.ietf.org/html/rfc1034).
member Ip
Ip = 'IP'
This parse result is returned if the given hostname was an IPv4 or IPv6.
member Listed
Listed = 'LISTED'
This parse result is returned when the given hostname belongs to a top-level domain that is listed in the public suffix list.
member NotListed
NotListed = 'NOT_LISTED'
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.
member Reserved
Reserved = 'RESERVED'
This parse result is returned when the given hostname - is the root domain (the empty string
""
) - belongs to the top-level domainlocalhost
,local
,example
,invalid
ortest
enum Validation
enum Validation { Lax = 'LAX', Strict = 'STRICT',}
member Lax
Lax = 'LAX'
Allows any octets as labels but still restricts the length of labels and the overall domain.
See Also
https://www.rfc-editor.org/rfc/rfc2181#section-11
member Strict
Strict = 'STRICT'
Only allows ASCII letters, digits and hyphens (aka LDH), forbids hyphens at the beginning or end of a label and requires top-level domain names not to be all-numeric.
This is the default if no validation is configured.
See Also
https://datatracker.ietf.org/doc/html/rfc3696#section-2
enum ValidationErrorType
enum ValidationErrorType { NoHostname = 'NO_HOSTNAME', DomainMaxLength = 'DOMAIN_MAX_LENGTH', LabelMinLength = 'LABEL_MIN_LENGTH', LabelMaxLength = 'LABEL_MAX_LENGTH', LabelInvalidCharacter = 'LABEL_INVALID_CHARACTER', LastLabelInvalid = 'LAST_LABEL_INVALID',}
member DomainMaxLength
DomainMaxLength = 'DOMAIN_MAX_LENGTH'
member LabelInvalidCharacter
LabelInvalidCharacter = 'LABEL_INVALID_CHARACTER'
member LabelMaxLength
LabelMaxLength = 'LABEL_MAX_LENGTH'
member LabelMinLength
LabelMinLength = 'LABEL_MIN_LENGTH'
member LastLabelInvalid
LastLabelInvalid = 'LAST_LABEL_INVALID'
member NoHostname
NoHostname = 'NO_HOSTNAME'
Type Aliases
type ParseResult
type ParseResult = | ParseResultInvalid | ParseResultIp | ParseResultReserved | ParseResultNotListed | ParseResultListed;
type ParseResultInvalid
type ParseResultInvalid = ParseResultCommon<ParseResultType.Invalid> & { /** * An array of validation errors. */ errors: Array<ValidationError>;};
type ParseResultIp
type ParseResultIp = ParseResultCommon<ParseResultType.Ip> & Pick<SanitizationResultValidIp, 'ipVersion'>;
type ParseResultListed
type ParseResultListed = ParseResultCommon<ParseResultType.Listed> & ParseResultCommonValidDomain & ParseResultListedDomains & { /** * The parse result according to ICANN only without private top-level domains. */ icann: ParseResultListedDomains; };
type ParseResultNotListed
type ParseResultNotListed = ParseResultCommon<ParseResultType.NotListed> & ParseResultCommonValidDomain;
type ParseResultReserved
type ParseResultReserved = ParseResultCommon<ParseResultType.Reserved> & ParseResultCommonValidDomain;
type ValidationError
type ValidationError = { type: ValidationErrorType; message: string; column: number;};
Package Files (4)
Dependencies (1)
Dev Dependencies (19)
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/parse-domain
.
- Markdown[![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/parse-domain)
- HTML<a href="https://www.jsdocs.io/package/parse-domain"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 3458 ms. - Missing or incorrect documentation? Open an issue for this package.