Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
module.exports.getBaseDomain = function (hostname) {
// decode punycode if exists
if (hostname.indexOf('xn--') >= 0 &&
checkASCII(hostname)) {
try {
hostname = punycode.toUnicode(hostname)
} catch (e) {
console.error('punnycode.toUnicode() failure:', e)
}
}
let baseDomain = cachedBaseDomain.get(hostname)
if (baseDomain) {
return baseDomain
}
// search through PSL
var prevDomains = []
var curDomain = hostname
var nextDot = curDomain.indexOf('.')
var tld = 0
var suffix