npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tlds2

v2.2.16

Published

Comprehensive list of TLDs and subdomain registrars

Downloads

2,200

Readme

tlds2

tlds2 is an npm module that provides a comprehensive list of top-level domains (TLDs) from ICANN. It also includes subdomain and registrar identification for better domain control and parsing.

To access the complete TLD and registrar list, visit this link.

Installation

npm install tlds2

Usage

const tlds = require('tlds2');

console.log(tlds.top);
//=> ['aaa', 'aarp', 'abarth', 'abb', 'abbott', 'abbvie', 'abc', ...]

Getting the Complete List

You can obtain the detailed list of registrars that make up the ICANN domains. This allows you to identify domains like *.co.uk when the ICANN list only includes *.uk.

const tlds = require('tlds2');

console.log(tlds.list);
//=> ['aaa', 'aarp', 'abarth', 'abb', 'abbott', 'abbvie', 'abc', ...]

Feel free to explore the full capabilities of the tlds2 module to enhance your domain management and parsing functionalities.

Some APIs

check(domain)

Combines the usage of checkDomain() and checkTLD() to perform comprehensive domain validation.

Parameters

  • domain (string): The domain name to check.

Returns

An object with the following properties:

  • error (string|null): Error message if the domain is invalid, null if valid.
  • punycode (boolean): Indicates whether the domain contains punycode encoding.
  • org (string|null): The organization/domain part of the fully qualified domain name (FQDN) returned by checkTLD().
  • tld (string): The top-level domain (TLD) labels in reverse order, joined by a dot ('.') returned by checkTLD().
  • subDomain (string): The subdomain labels in reverse order, joined by a dot ('.') returned by `checkTLD().

Example

const {check} = require("./tlds2")

const result = check('example.com');
console.log(result);
// Output: { error: null, punycode: false, org: "example", tld: "com", subDomain: "" }

In the example above, the check() function is used to validate the domain name "example.com". The result object contains information about any errors, punycode encoding, organization/domain, TLD labels, and subdomain labels returned by checkTLD().

checkTLD(fqdn)

Checks the top-level domain (TLD) and subdomain of a fully qualified domain name (FQDN).

Parameters

  • fqdn (string): The fully qualified domain name to check.

Returns

An object with the following properties:

  • error (string | null): Error message if the TLD/subdomain is invalid, null if valid.
  • punycode (boolean): Indicates whether the TLD/subdomain contains punycode encoding.
  • validTLD (boolean): Indicates whether a valid TLD is present.
  • org (string | null): Organization/domain part of the FQDN.
  • tld (string): TLD labels in reverse order, joined with periods.
  • subDomain (string): Subdomain labels in reverse order, joined with periods.

Example

const {checkTLD} = require("./tlds2")
const fqdn = "sub.domain.example.com";
const result = checkTLD(fqdn);
console.log(result);

Output:

{
    error: null,
    punycode: false,
    validTLD: true,
    org: "example",
    tld: "com",
    subDomain: "sub.domain"
}

checkDomain(domain)

Checks a domain name for validity.

Parameters

  • domain (string): The domain name to check.

Returns

An object with the following properties:

  • error (string | null): An error message if the domain is invalid, or null if the domain is valid.
  • punycode (boolean): Indicates whether the domain contains punycode encoding.
  • info (string | undefined): Additional information about the error, if any.

Example

const {checkDomain} = require("./tlds2")

const domainInfo = checkDomain('example.com');
console.log(domainInfo);
// Output: { error: null, punycode: false }

const invalidDomain = checkDomain('-invalid.domain');
console.log(invalidDomain);
// Output: { error: 'Invalid domain', punycode: false, info: 'Invalid label encoding' }