amis-rpc-design/node_modules/tldjs/lib/tld-exists.js
2023-10-07 19:42:30 +08:00

29 lines
520 B
JavaScript

'use strict';
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);
};