• Version 4.1.0
  • Published
  • 269 kB
  • 3 dependencies
  • MIT license


npm i parse-domain
yarn add parse-domain
pnpm add parse-domain


Splits a hostname into subdomains, domain and (effective) top-level domains



variable NO_HOSTNAME

const NO_HOSTNAME: Symbol;


    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.


      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](

        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> &

                            type ParseResultReserved

                            type ParseResultReserved = ParseResultCommon<ParseResultType.Reserved> &

                              type ValidationError

                              type ValidationError = {
                              type: ValidationErrorType;
                              message: string;
                              column: number;

                                Package Files (4)

                                Dependencies (3)

                                Dev Dependencies (23)

                                Peer Dependencies (0)

                                No peer dependencies.


                                To add a badge like this badgeto your package's README, use the codes available below.

                                You may also use to create a custom badge linking to

                                • Markdown
                                • HTML
                                  <a href=""><img src="" alt=""></a>