This repository contains a list of all existing Top-Level Domains (TLDs) that can be registered.
This includes:
- gTLD: Generic top-level domain
- grTLD: Generic restricted top-level domain
- sTLD: Sponsored top-level domain
- ccTLD: Country code top-level domain
npm install top-level-domains
# or
yarn add top-level-domains
// ESM
import { tlds, isTld, getPunycode, searchTlds, getAllTlds } from 'top-level-domains';
// CommonJS
const { tlds, isTld, getPunycode, searchTlds, getAllTlds } = require('top-level-domains');
// Check if a string is a valid TLD
console.log(isTld('com')); // true
console.log(isTld('notarealtld')); // false
// Get the punycode representation of a TLD
console.log(getPunycode('台灣')); // 'xn--kpry57d'
// Search for TLDs containing a string
const results = searchTlds('com');
console.log(results); // Returns all TLDs containing 'com'
// Get all TLDs as an array of strings
const allTlds = getAllTlds();
console.log(allTlds); // Returns all TLDs as an array of strings
Each TLD entry in the data.json
file is structured as follows:
{
"tld": "example",
"punycode": "example"
}
For internationalized domain names (IDNs), the punycode representation is different:
{
"tld": "台灣",
"punycode": "xn--kpry57d"
}
Contributions are welcome! If you'd like to contribute to this project, please follow these steps:
- Fork the repository
- Create a new branch for your feature or bugfix
- Make your changes
- Run
npm run test
to ensure all tests are passing - Run
npm run sort
to ensure the TLD list is properly sorted - Submit a pull request
MIT