top-level-domains
Version:
A comprehensive list of all existing Top-Level Domains (TLDs) that can be registered
56 lines (55 loc) • 1.66 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.tlds = void 0;
exports.getAllTlds = getAllTlds;
exports.isTld = isTld;
exports.getPunycode = getPunycode;
exports.searchTlds = searchTlds;
const data_json_1 = __importDefault(require("../data.json"));
/**
* The complete list of all TLDs
*/
exports.tlds = data_json_1.default;
/**
* Get all TLDs as an array of strings
* @returns Array of TLD strings (e.g., ["com", "org", "net", ...])
*/
function getAllTlds() {
return exports.tlds.map(entry => entry.tld);
}
/**
* Check if a string is a valid TLD
* @param tld The TLD to check
* @returns True if the TLD exists in the list
*/
function isTld(tld) {
return exports.tlds.some(entry => entry.tld.toLowerCase() === tld.toLowerCase());
}
/**
* Get the punycode representation of a TLD
* @param tld The TLD to get the punycode for
* @returns The punycode representation or null if the TLD doesn't exist
*/
function getPunycode(tld) {
const entry = exports.tlds.find(entry => entry.tld.toLowerCase() === tld.toLowerCase());
return entry ? entry.punycode : null;
}
/**
* Filter TLDs by a search string
* @param search The search string
* @returns Array of TLD entries that match the search
*/
function searchTlds(search) {
const searchLower = search.toLowerCase();
return exports.tlds.filter(entry => entry.tld.toLowerCase().includes(searchLower));
}
exports.default = {
tlds: exports.tlds,
getAllTlds,
isTld,
getPunycode,
searchTlds
};