What is tlds?
The tlds npm package provides a list of top-level domains (TLDs) as recognized by the Internet Assigned Numbers Authority (IANA). This package can be used to validate domain names, parse URLs, and perform operations that require knowledge of valid TLDs.
What are tlds's main functionalities?
Get the full list of TLDs
This feature allows you to retrieve the full list of TLDs. You can use this list to check if a domain's TLD is valid or to enumerate all possible TLDs.
const tlds = require('tlds');
console.log(tlds); // Outputs the array of TLDs
Check if a TLD exists
This feature allows you to check if a specific TLD exists in the list of valid TLDs. This can be useful for validating domain names or filtering user input.
const tlds = require('tlds');
const isTldValid = tlds.includes('com');
console.log(isTldValid); // Outputs true
Other packages similar to tlds
psl
The 'psl' package, also known as 'public suffix list', is a Node.js module that allows you to work with the public suffix list from Mozilla. It provides functionalities to parse domain names and extract the TLD, which is similar to what 'tlds' offers. However, 'psl' also includes additional features such as finding the domain root and checking if a domain is a public suffix.