amis-rpc-design/node_modules/tldjs/lib/tld-exists.js

29 lines
520 B
JavaScript
Raw Normal View History

2023-10-07 19:42:30 +08:00
'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);
};