getRootDomain
Extract the root domain from a URL, correctly handling compound top-level domains so subdomains collapse to their registrable base.
Usage
getRootDomain extracts the root domain (top-level domain + second-level domain) from a URL.
import { getRootDomain } from '@movk/core'
getRootDomain('https://sub.example.com') // 'example.com'
getRootDomain('https://a.b.example.co.uk') // 'example.co.uk'
API
getRootDomain(url)
Get the root domain (TLD + second-level domain) from a URL.
Parameters
url
string required
The URL string.
Returns
returns
string
The root domain, or an empty string if parsing fails.
Changelog
No recent changes