peerigon / parse-domain

Splits a hostname into subdomains, domain and (effective) top-level domains.
MIT License
503 stars 71 forks source link

Domain is incorrectly splitting for gov.uk domain #135

Closed vinayakwadhwa closed 2 years ago

vinayakwadhwa commented 2 years ago

both gov and uk are considered as TLDs instead of gov being treated as domain

jhnns commented 2 years ago

.gov.uk is listed in the public suffix list and thus the effective top-level domain (see this for clarification).

You're probably looking for result.icann:

const parseResult = parseDomain("something.gov.uk");
const { subDomains, domain, topLevelDomains } = parseResult.icann;

console.log(subDomains); // ["something"]
console.log(domain); // "gov"
console.log(topLevelDomains); // ["uk"]