Index: lib/url.js |
=================================================================== |
rename from lib/domain.js |
rename to lib/url.js |
--- a/lib/domain.js |
+++ b/lib/url.js |
@@ -59,31 +59,31 @@ |
* <code>com</code>, in that order. |
* |
* @param {string} domain The domain. |
* @param {boolean} [includeBlank] Whether to include the blank suffix at the |
* end. |
* |
* @yields {string} The next suffix for the domain. |
*/ |
-function* suffixes(domain, includeBlank = false) |
+function* domainSuffixes(domain, includeBlank = false) |
{ |
while (domain != "") |
{ |
yield domain; |
let dotIndex = domain.indexOf("."); |
domain = dotIndex == -1 ? "" : domain.substr(dotIndex + 1); |
} |
if (includeBlank) |
yield ""; |
} |
-exports.suffixes = suffixes; |
+exports.domainSuffixes = domainSuffixes; |
/** |
* Checks whether the given hostname is a domain. |
* |
* @param {string} hostname |
* @returns {boolean} |
*/ |
function isDomain(hostname) |
@@ -98,22 +98,22 @@ |
} |
/** |
* Gets the base domain for the given hostname. |
* |
* @param {string} hostname |
* @returns {string} |
*/ |
-function getDomain(hostname) |
+function getBaseDomain(hostname) |
{ |
let slices = []; |
let cutoff = NaN; |
- for (let suffix of suffixes(hostname)) |
+ for (let suffix of domainSuffixes(hostname)) |
{ |
slices.push(suffix); |
let offset = publicSuffixMap.get(suffix); |
if (typeof offset != "undefined") |
{ |
cutoff = slices.length - 1 - offset; |
@@ -125,17 +125,17 @@ |
return slices.length > 2 ? slices[slices.length - 2] : hostname; |
if (cutoff <= 0) |
return hostname; |
return slices[cutoff]; |
} |
-exports.getDomain = getDomain; |
+exports.getBaseDomain = getBaseDomain; |
/** |
* Checks whether a request's origin is different from its document's origin. |
* |
* @param {URL} url The request URL. |
* @param {string} documentHostname The IDNA-encoded hostname of the document. |
* |
* @returns {boolean} |
@@ -151,12 +151,12 @@ |
documentHostname = documentHostname.replace(/\.+$/, ""); |
if (requestHostname == documentHostname) |
return false; |
if (!isDomain(requestHostname) || !isDomain(documentHostname)) |
return true; |
- return getDomain(requestHostname) != getDomain(documentHostname); |
+ return getBaseDomain(requestHostname) != getBaseDomain(documentHostname); |
} |
exports.isThirdParty = isThirdParty; |