tldjs
Version:
JavaScript API to work against complex domain names, subdomains and URIs.
29 lines (22 loc) • 520 B
JavaScript
;
var extractTldFromHost = require('./from-host.js');
/**
* Checks if the TLD exists for a given hostname
*
* @api
* @param {string} rules
* @param {string} hostname
* @return {boolean}
*/
module.exports = function tldExists(rules, hostname) {
// Easy case, it's a TLD
if (rules.hasTld(hostname)) {
return true;
}
// Popping only the TLD of the hostname
var hostTld = extractTldFromHost(hostname);
if (hostTld === null) {
return false;
}
return rules.hasTld(hostTld);
};