parse-domain

  • Version 4.1.0
  • Published
  • 269 kB
  • 3 dependencies
  • 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

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) => 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 domain localhost, local, example, invalid or test

        enum ValidationErrorType

        enum ValidationErrorType {
        NoHostname = 'NO_HOSTNAME',
        DomainMaxLength = 'DOMAIN_MAX_LENGTH',
        LabelMinLength = 'LABEL_MIN_LENGTH',
        LabelMaxLength = 'LABEL_MAX_LENGTH',
        LabelInvalidCharacter = 'LABEL_INVALID_CHARACTER',
        }

          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 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 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 (3)

                                Dev Dependencies (23)

                                Peer Dependencies (0)

                                No peer dependencies.

                                Badge

                                To add a badge like this onejsDocs.io badgeto 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>