tldjs
Version:
JavaScript API to work against complex domain names, subdomains and URIs.
17 lines (14 loc) • 326 B
JavaScript
;
/**
* Utility to extract the TLD from a hostname string
*
* @param {string} host
* @return {String}
*/
module.exports = function extractTldFromHost(hostname) {
var lastDotIndex = hostname.lastIndexOf('.');
if (lastDotIndex === -1) {
return null;
}
return hostname.substr(lastDotIndex + 1);
};