UNPKG

get-etld

Version:

Returns the effective top-level domain (eTLD) of the current web page without the use of a public suffix list.

30 lines (26 loc) 848 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; /** * Retrieves the effective top-level domain. * @param {Object} window The browser's window object * @param {Function} getApexDomain Function returning * the apex domain. * @returns {string} The effective top-level domain. */ var _default = function _default(window, getApexDomain) { var apexDomain = getApexDomain(); if (apexDomain) { // apex domains always have at least one period return apexDomain.split(".").slice(1).join("."); } else { // apexDomain is undefined in unique cases like "localhost" // where the hostname is a restricted effective top-level domain // and not an apex domain. return window.location.hostname; } }; exports["default"] = _default; module.exports = exports.default;