Namespace: Urls:evaluateBaseDomain

Urls:evaluateBaseDomain

Source:

Methods

evaluateBaseDomain(domain, additionalTopLevelDomainsopt, nullable) → {String}

Walks a domain string (e.g. foobar.barfoo.co.uk) backwards, separated by dots, skips over all top level domains it finds and includes the first non-TLD value to retrieve the base domain without any subdomains (e.g. barfoo.co.uk).

This is not completely fool-proof in case of very exotic TLDs, but quite robust in most cases.

This method is particularly helpful if you want to set a domain cookie while being on a subdomain.

Parameters:
Name Type Attributes Default Description
domain String

the domain string (hostname), which should be evaluated; you may also provide a full, parsable URL, from which to extract the hostname

additionalTopLevelDomains Array.<String> <optional>
<nullable>
null

this function uses a list of common TLDs, if yours is missing, you may provide it, using this parameter

Source:
Returns:
the evaluated base domain string
Type
String
Example
evaluateBaseDomain('foobar.barfoo.co.uk');
=> 'barfoo.co.uk'
evaluateBaseDomain('https://foobar.barfoo.co.uk/?foo=bar');
=> 'barfoo.co.uk'