667 lines
167 KiB
JavaScript
667 lines
167 KiB
JavaScript
|
'use strict';
|
||
|
|
||
|
/**
|
||
|
* Check if `vhost` is a valid suffix of `hostname` (top-domain)
|
||
|
*
|
||
|
* It means that `vhost` needs to be a suffix of `hostname` and we then need to
|
||
|
* make sure that: either they are equal, or the character preceding `vhost` in
|
||
|
* `hostname` is a '.' (it should not be a partial label).
|
||
|
*
|
||
|
* * hostname = 'not.evil.com' and vhost = 'vil.com' => not ok
|
||
|
* * hostname = 'not.evil.com' and vhost = 'evil.com' => ok
|
||
|
* * hostname = 'not.evil.com' and vhost = 'not.evil.com' => ok
|
||
|
*/
|
||
|
function shareSameDomainSuffix(hostname, vhost) {
|
||
|
if (hostname.endsWith(vhost)) {
|
||
|
return (hostname.length === vhost.length ||
|
||
|
hostname[hostname.length - vhost.length - 1] === '.');
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
/**
|
||
|
* Given a hostname and its public suffix, extract the general domain.
|
||
|
*/
|
||
|
function extractDomainWithSuffix(hostname, publicSuffix) {
|
||
|
// Locate the index of the last '.' in the part of the `hostname` preceding
|
||
|
// the public suffix.
|
||
|
//
|
||
|
// examples:
|
||
|
// 1. not.evil.co.uk => evil.co.uk
|
||
|
// ^ ^
|
||
|
// | | start of public suffix
|
||
|
// | index of the last dot
|
||
|
//
|
||
|
// 2. example.co.uk => example.co.uk
|
||
|
// ^ ^
|
||
|
// | | start of public suffix
|
||
|
// |
|
||
|
// | (-1) no dot found before the public suffix
|
||
|
const publicSuffixIndex = hostname.length - publicSuffix.length - 2;
|
||
|
const lastDotBeforeSuffixIndex = hostname.lastIndexOf('.', publicSuffixIndex);
|
||
|
// No '.' found, then `hostname` is the general domain (no sub-domain)
|
||
|
if (lastDotBeforeSuffixIndex === -1) {
|
||
|
return hostname;
|
||
|
}
|
||
|
// Extract the part between the last '.'
|
||
|
return hostname.slice(lastDotBeforeSuffixIndex + 1);
|
||
|
}
|
||
|
/**
|
||
|
* Detects the domain based on rules and upon and a host string
|
||
|
*/
|
||
|
function getDomain$1(suffix, hostname, options) {
|
||
|
// Check if `hostname` ends with a member of `validHosts`.
|
||
|
if (options.validHosts !== null) {
|
||
|
const validHosts = options.validHosts;
|
||
|
for (const vhost of validHosts) {
|
||
|
if ( /*@__INLINE__*/shareSameDomainSuffix(hostname, vhost)) {
|
||
|
return vhost;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
let numberOfLeadingDots = 0;
|
||
|
if (hostname.startsWith('.')) {
|
||
|
while (numberOfLeadingDots < hostname.length &&
|
||
|
hostname[numberOfLeadingDots] === '.') {
|
||
|
numberOfLeadingDots += 1;
|
||
|
}
|
||
|
}
|
||
|
// If `hostname` is a valid public suffix, then there is no domain to return.
|
||
|
// Since we already know that `getPublicSuffix` returns a suffix of `hostname`
|
||
|
// there is no need to perform a string comparison and we only compare the
|
||
|
// size.
|
||
|
if (suffix.length === hostname.length - numberOfLeadingDots) {
|
||
|
return null;
|
||
|
}
|
||
|
// To extract the general domain, we start by identifying the public suffix
|
||
|
// (if any), then consider the domain to be the public suffix with one added
|
||
|
// level of depth. (e.g.: if hostname is `not.evil.co.uk` and public suffix:
|
||
|
// `co.uk`, then we take one more level: `evil`, giving the final result:
|
||
|
// `evil.co.uk`).
|
||
|
return /*@__INLINE__*/ extractDomainWithSuffix(hostname, suffix);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Return the part of domain without suffix.
|
||
|
*
|
||
|
* Example: for domain 'foo.com', the result would be 'foo'.
|
||
|
*/
|
||
|
function getDomainWithoutSuffix$1(domain, suffix) {
|
||
|
// Note: here `domain` and `suffix` cannot have the same length because in
|
||
|
// this case we set `domain` to `null` instead. It is thus safe to assume
|
||
|
// that `suffix` is shorter than `domain`.
|
||
|
return domain.slice(0, -suffix.length - 1);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @param url - URL we want to extract a hostname from.
|
||
|
* @param urlIsValidHostname - hint from caller; true if `url` is already a valid hostname.
|
||
|
*/
|
||
|
function extractHostname(url, urlIsValidHostname) {
|
||
|
let start = 0;
|
||
|
let end = url.length;
|
||
|
let hasUpper = false;
|
||
|
// If url is not already a valid hostname, then try to extract hostname.
|
||
|
if (!urlIsValidHostname) {
|
||
|
// Special handling of data URLs
|
||
|
if (url.startsWith('data:')) {
|
||
|
return null;
|
||
|
}
|
||
|
// Trim leading spaces
|
||
|
while (start < url.length && url.charCodeAt(start) <= 32) {
|
||
|
start += 1;
|
||
|
}
|
||
|
// Trim trailing spaces
|
||
|
while (end > start + 1 && url.charCodeAt(end - 1) <= 32) {
|
||
|
end -= 1;
|
||
|
}
|
||
|
// Skip scheme.
|
||
|
if (url.charCodeAt(start) === 47 /* '/' */ &&
|
||
|
url.charCodeAt(start + 1) === 47 /* '/' */) {
|
||
|
start += 2;
|
||
|
}
|
||
|
else {
|
||
|
const indexOfProtocol = url.indexOf(':/', start);
|
||
|
if (indexOfProtocol !== -1) {
|
||
|
// Implement fast-path for common protocols. We expect most protocols
|
||
|
// should be one of these 4 and thus we will not need to perform the
|
||
|
// more expansive validity check most of the time.
|
||
|
const protocolSize = indexOfProtocol - start;
|
||
|
const c0 = url.charCodeAt(start);
|
||
|
const c1 = url.charCodeAt(start + 1);
|
||
|
const c2 = url.charCodeAt(start + 2);
|
||
|
const c3 = url.charCodeAt(start + 3);
|
||
|
const c4 = url.charCodeAt(start + 4);
|
||
|
if (protocolSize === 5 &&
|
||
|
c0 === 104 /* 'h' */ &&
|
||
|
c1 === 116 /* 't' */ &&
|
||
|
c2 === 116 /* 't' */ &&
|
||
|
c3 === 112 /* 'p' */ &&
|
||
|
c4 === 115 /* 's' */) ;
|
||
|
else if (protocolSize === 4 &&
|
||
|
c0 === 104 /* 'h' */ &&
|
||
|
c1 === 116 /* 't' */ &&
|
||
|
c2 === 116 /* 't' */ &&
|
||
|
c3 === 112 /* 'p' */) ;
|
||
|
else if (protocolSize === 3 &&
|
||
|
c0 === 119 /* 'w' */ &&
|
||
|
c1 === 115 /* 's' */ &&
|
||
|
c2 === 115 /* 's' */) ;
|
||
|
else if (protocolSize === 2 &&
|
||
|
c0 === 119 /* 'w' */ &&
|
||
|
c1 === 115 /* 's' */) ;
|
||
|
else {
|
||
|
// Check that scheme is valid
|
||
|
for (let i = start; i < indexOfProtocol; i += 1) {
|
||
|
const lowerCaseCode = url.charCodeAt(i) | 32;
|
||
|
if (!(((lowerCaseCode >= 97 && lowerCaseCode <= 122) || // [a, z]
|
||
|
(lowerCaseCode >= 48 && lowerCaseCode <= 57) || // [0, 9]
|
||
|
lowerCaseCode === 46 || // '.'
|
||
|
lowerCaseCode === 45 || // '-'
|
||
|
lowerCaseCode === 43) // '+'
|
||
|
)) {
|
||
|
return null;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
// Skip 0, 1 or more '/' after ':/'
|
||
|
start = indexOfProtocol + 2;
|
||
|
while (url.charCodeAt(start) === 47 /* '/' */) {
|
||
|
start += 1;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
// Detect first occurrence of '/', '?' or '#'. We also keep track of the
|
||
|
// last occurrence of '@', ']' or ':' to speed-up subsequent parsing of
|
||
|
// (respectively), identifier, ipv6 or port.
|
||
|
let indexOfIdentifier = -1;
|
||
|
let indexOfClosingBracket = -1;
|
||
|
let indexOfPort = -1;
|
||
|
for (let i = start; i < end; i += 1) {
|
||
|
const code = url.charCodeAt(i);
|
||
|
if (code === 35 || // '#'
|
||
|
code === 47 || // '/'
|
||
|
code === 63 // '?'
|
||
|
) {
|
||
|
end = i;
|
||
|
break;
|
||
|
}
|
||
|
else if (code === 64) {
|
||
|
// '@'
|
||
|
indexOfIdentifier = i;
|
||
|
}
|
||
|
else if (code === 93) {
|
||
|
// ']'
|
||
|
indexOfClosingBracket = i;
|
||
|
}
|
||
|
else if (code === 58) {
|
||
|
// ':'
|
||
|
indexOfPort = i;
|
||
|
}
|
||
|
else if (code >= 65 && code <= 90) {
|
||
|
hasUpper = true;
|
||
|
}
|
||
|
}
|
||
|
// Detect identifier: '@'
|
||
|
if (indexOfIdentifier !== -1 &&
|
||
|
indexOfIdentifier > start &&
|
||
|
indexOfIdentifier < end) {
|
||
|
start = indexOfIdentifier + 1;
|
||
|
}
|
||
|
// Handle ipv6 addresses
|
||
|
if (url.charCodeAt(start) === 91 /* '[' */) {
|
||
|
if (indexOfClosingBracket !== -1) {
|
||
|
return url.slice(start + 1, indexOfClosingBracket).toLowerCase();
|
||
|
}
|
||
|
return null;
|
||
|
}
|
||
|
else if (indexOfPort !== -1 && indexOfPort > start && indexOfPort < end) {
|
||
|
// Detect port: ':'
|
||
|
end = indexOfPort;
|
||
|
}
|
||
|
}
|
||
|
// Trim trailing dots
|
||
|
while (end > start + 1 && url.charCodeAt(end - 1) === 46 /* '.' */) {
|
||
|
end -= 1;
|
||
|
}
|
||
|
const hostname = start !== 0 || end !== url.length ? url.slice(start, end) : url;
|
||
|
if (hasUpper) {
|
||
|
return hostname.toLowerCase();
|
||
|
}
|
||
|
return hostname;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Check if a hostname is an IP. You should be aware that this only works
|
||
|
* because `hostname` is already garanteed to be a valid hostname!
|
||
|
*/
|
||
|
function isProbablyIpv4(hostname) {
|
||
|
// Cannot be shorted than 1.1.1.1
|
||
|
if (hostname.length < 7) {
|
||
|
return false;
|
||
|
}
|
||
|
// Cannot be longer than: 255.255.255.255
|
||
|
if (hostname.length > 15) {
|
||
|
return false;
|
||
|
}
|
||
|
let numberOfDots = 0;
|
||
|
for (let i = 0; i < hostname.length; i += 1) {
|
||
|
const code = hostname.charCodeAt(i);
|
||
|
if (code === 46 /* '.' */) {
|
||
|
numberOfDots += 1;
|
||
|
}
|
||
|
else if (code < 48 /* '0' */ || code > 57 /* '9' */) {
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
return (numberOfDots === 3 &&
|
||
|
hostname.charCodeAt(0) !== 46 /* '.' */ &&
|
||
|
hostname.charCodeAt(hostname.length - 1) !== 46 /* '.' */);
|
||
|
}
|
||
|
/**
|
||
|
* Similar to isProbablyIpv4.
|
||
|
*/
|
||
|
function isProbablyIpv6(hostname) {
|
||
|
if (hostname.length < 3) {
|
||
|
return false;
|
||
|
}
|
||
|
let start = hostname.startsWith('[') ? 1 : 0;
|
||
|
let end = hostname.length;
|
||
|
if (hostname[end - 1] === ']') {
|
||
|
end -= 1;
|
||
|
}
|
||
|
// We only consider the maximum size of a normal IPV6. Note that this will
|
||
|
// fail on so-called "IPv4 mapped IPv6 addresses" but this is a corner-case
|
||
|
// and a proper validation library should be used for these.
|
||
|
if (end - start > 39) {
|
||
|
return false;
|
||
|
}
|
||
|
let hasColon = false;
|
||
|
for (; start < end; start += 1) {
|
||
|
const code = hostname.charCodeAt(start);
|
||
|
if (code === 58 /* ':' */) {
|
||
|
hasColon = true;
|
||
|
}
|
||
|
else if (!(((code >= 48 && code <= 57) || // 0-9
|
||
|
(code >= 97 && code <= 102) || // a-f
|
||
|
(code >= 65 && code <= 90)) // A-F
|
||
|
)) {
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
return hasColon;
|
||
|
}
|
||
|
/**
|
||
|
* Check if `hostname` is *probably* a valid ip addr (either ipv6 or ipv4).
|
||
|
* This *will not* work on any string. We need `hostname` to be a valid
|
||
|
* hostname.
|
||
|
*/
|
||
|
function isIp(hostname) {
|
||
|
return isProbablyIpv6(hostname) || isProbablyIpv4(hostname);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Implements fast shallow verification of hostnames. This does not perform a
|
||
|
* struct check on the content of labels (classes of Unicode characters, etc.)
|
||
|
* but instead check that the structure is valid (number of labels, length of
|
||
|
* labels, etc.).
|
||
|
*
|
||
|
* If you need stricter validation, consider using an external library.
|
||
|
*/
|
||
|
function isValidAscii(code) {
|
||
|
return ((code >= 97 && code <= 122) || (code >= 48 && code <= 57) || code > 127);
|
||
|
}
|
||
|
/**
|
||
|
* Check if a hostname string is valid. It's usually a preliminary check before
|
||
|
* trying to use getDomain or anything else.
|
||
|
*
|
||
|
* Beware: it does not check if the TLD exists.
|
||
|
*/
|
||
|
function isValidHostname (hostname) {
|
||
|
if (hostname.length > 255) {
|
||
|
return false;
|
||
|
}
|
||
|
if (hostname.length === 0) {
|
||
|
return false;
|
||
|
}
|
||
|
if (
|
||
|
/*@__INLINE__*/ !isValidAscii(hostname.charCodeAt(0)) &&
|
||
|
hostname.charCodeAt(0) !== 46 && // '.' (dot)
|
||
|
hostname.charCodeAt(0) !== 95 // '_' (underscore)
|
||
|
) {
|
||
|
return false;
|
||
|
}
|
||
|
// Validate hostname according to RFC
|
||
|
let lastDotIndex = -1;
|
||
|
let lastCharCode = -1;
|
||
|
const len = hostname.length;
|
||
|
for (let i = 0; i < len; i += 1) {
|
||
|
const code = hostname.charCodeAt(i);
|
||
|
if (code === 46 /* '.' */) {
|
||
|
if (
|
||
|
// Check that previous label is < 63 bytes long (64 = 63 + '.')
|
||
|
i - lastDotIndex > 64 ||
|
||
|
// Check that previous character was not already a '.'
|
||
|
lastCharCode === 46 ||
|
||
|
// Check that the previous label does not end with a '-' (dash)
|
||
|
lastCharCode === 45 ||
|
||
|
// Check that the previous label does not end with a '_' (underscore)
|
||
|
lastCharCode === 95) {
|
||
|
return false;
|
||
|
}
|
||
|
lastDotIndex = i;
|
||
|
}
|
||
|
else if (!( /*@__INLINE__*/(isValidAscii(code) || code === 45 || code === 95))) {
|
||
|
// Check if there is a forbidden character in the label
|
||
|
return false;
|
||
|
}
|
||
|
lastCharCode = code;
|
||
|
}
|
||
|
return (
|
||
|
// Check that last label is shorter than 63 chars
|
||
|
len - lastDotIndex - 1 <= 63 &&
|
||
|
// Check that the last character is an allowed trailing label character.
|
||
|
// Since we already checked that the char is a valid hostname character,
|
||
|
// we only need to check that it's different from '-'.
|
||
|
lastCharCode !== 45);
|
||
|
}
|
||
|
|
||
|
function setDefaultsImpl({ allowIcannDomains = true, allowPrivateDomains = false, detectIp = true, extractHostname = true, mixedInputs = true, validHosts = null, validateHostname = true, }) {
|
||
|
return {
|
||
|
allowIcannDomains,
|
||
|
allowPrivateDomains,
|
||
|
detectIp,
|
||
|
extractHostname,
|
||
|
mixedInputs,
|
||
|
validHosts,
|
||
|
validateHostname,
|
||
|
};
|
||
|
}
|
||
|
const DEFAULT_OPTIONS = /*@__INLINE__*/ setDefaultsImpl({});
|
||
|
function setDefaults(options) {
|
||
|
if (options === undefined) {
|
||
|
return DEFAULT_OPTIONS;
|
||
|
}
|
||
|
return /*@__INLINE__*/ setDefaultsImpl(options);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Returns the subdomain of a hostname string
|
||
|
*/
|
||
|
function getSubdomain$1(hostname, domain) {
|
||
|
// If `hostname` and `domain` are the same, then there is no sub-domain
|
||
|
if (domain.length === hostname.length) {
|
||
|
return '';
|
||
|
}
|
||
|
return hostname.slice(0, -domain.length - 1);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Implement a factory allowing to plug different implementations of suffix
|
||
|
* lookup (e.g.: using a trie or the packed hashes datastructures). This is used
|
||
|
* and exposed in `tldts.ts` and `tldts-experimental.ts` bundle entrypoints.
|
||
|
*/
|
||
|
function getEmptyResult() {
|
||
|
return {
|
||
|
domain: null,
|
||
|
domainWithoutSuffix: null,
|
||
|
hostname: null,
|
||
|
isIcann: null,
|
||
|
isIp: null,
|
||
|
isPrivate: null,
|
||
|
publicSuffix: null,
|
||
|
subdomain: null,
|
||
|
};
|
||
|
}
|
||
|
function resetResult(result) {
|
||
|
result.domain = null;
|
||
|
result.domainWithoutSuffix = null;
|
||
|
result.hostname = null;
|
||
|
result.isIcann = null;
|
||
|
result.isIp = null;
|
||
|
result.isPrivate = null;
|
||
|
result.publicSuffix = null;
|
||
|
result.subdomain = null;
|
||
|
}
|
||
|
function parseImpl(url, step, suffixLookup, partialOptions, result) {
|
||
|
const options = /*@__INLINE__*/ setDefaults(partialOptions);
|
||
|
// Very fast approximate check to make sure `url` is a string. This is needed
|
||
|
// because the library will not necessarily be used in a typed setup and
|
||
|
// values of arbitrary types might be given as argument.
|
||
|
if (typeof url !== 'string') {
|
||
|
return result;
|
||
|
}
|
||
|
// Extract hostname from `url` only if needed. This can be made optional
|
||
|
// using `options.extractHostname`. This option will typically be used
|
||
|
// whenever we are sure the inputs to `parse` are already hostnames and not
|
||
|
// arbitrary URLs.
|
||
|
//
|
||
|
// `mixedInput` allows to specify if we expect a mix of URLs and hostnames
|
||
|
// as input. If only hostnames are expected then `extractHostname` can be
|
||
|
// set to `false` to speed-up parsing. If only URLs are expected then
|
||
|
// `mixedInputs` can be set to `false`. The `mixedInputs` is only a hint
|
||
|
// and will not change the behavior of the library.
|
||
|
if (!options.extractHostname) {
|
||
|
result.hostname = url;
|
||
|
}
|
||
|
else if (options.mixedInputs) {
|
||
|
result.hostname = extractHostname(url, isValidHostname(url));
|
||
|
}
|
||
|
else {
|
||
|
result.hostname = extractHostname(url, false);
|
||
|
}
|
||
|
if (step === 0 /* FLAG.HOSTNAME */ || result.hostname === null) {
|
||
|
return result;
|
||
|
}
|
||
|
// Check if `hostname` is a valid ip address
|
||
|
if (options.detectIp) {
|
||
|
result.isIp = isIp(result.hostname);
|
||
|
if (result.isIp) {
|
||
|
return result;
|
||
|
}
|
||
|
}
|
||
|
// Perform optional hostname validation. If hostname is not valid, no need to
|
||
|
// go further as there will be no valid domain or sub-domain.
|
||
|
if (options.validateHostname &&
|
||
|
options.extractHostname &&
|
||
|
!isValidHostname(result.hostname)) {
|
||
|
result.hostname = null;
|
||
|
return result;
|
||
|
}
|
||
|
// Extract public suffix
|
||
|
suffixLookup(result.hostname, options, result);
|
||
|
if (step === 2 /* FLAG.PUBLIC_SUFFIX */ || result.publicSuffix === null) {
|
||
|
return result;
|
||
|
}
|
||
|
// Extract domain
|
||
|
result.domain = getDomain$1(result.publicSuffix, result.hostname, options);
|
||
|
if (step === 3 /* FLAG.DOMAIN */ || result.domain === null) {
|
||
|
return result;
|
||
|
}
|
||
|
// Extract subdomain
|
||
|
result.subdomain = getSubdomain$1(result.hostname, result.domain);
|
||
|
if (step === 4 /* FLAG.SUB_DOMAIN */) {
|
||
|
return result;
|
||
|
}
|
||
|
// Extract domain without suffix
|
||
|
result.domainWithoutSuffix = getDomainWithoutSuffix$1(result.domain, result.publicSuffix);
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
function fastPathLookup (hostname, options, out) {
|
||
|
// Fast path for very popular suffixes; this allows to by-pass lookup
|
||
|
// completely as well as any extra allocation or string manipulation.
|
||
|
if (!options.allowPrivateDomains && hostname.length > 3) {
|
||
|
const last = hostname.length - 1;
|
||
|
const c3 = hostname.charCodeAt(last);
|
||
|
const c2 = hostname.charCodeAt(last - 1);
|
||
|
const c1 = hostname.charCodeAt(last - 2);
|
||
|
const c0 = hostname.charCodeAt(last - 3);
|
||
|
if (c3 === 109 /* 'm' */ &&
|
||
|
c2 === 111 /* 'o' */ &&
|
||
|
c1 === 99 /* 'c' */ &&
|
||
|
c0 === 46 /* '.' */) {
|
||
|
out.isIcann = true;
|
||
|
out.isPrivate = false;
|
||
|
out.publicSuffix = 'com';
|
||
|
return true;
|
||
|
}
|
||
|
else if (c3 === 103 /* 'g' */ &&
|
||
|
c2 === 114 /* 'r' */ &&
|
||
|
c1 === 111 /* 'o' */ &&
|
||
|
c0 === 46 /* '.' */) {
|
||
|
out.isIcann = true;
|
||
|
out.isPrivate = false;
|
||
|
out.publicSuffix = 'org';
|
||
|
return true;
|
||
|
}
|
||
|
else if (c3 === 117 /* 'u' */ &&
|
||
|
c2 === 100 /* 'd' */ &&
|
||
|
c1 === 101 /* 'e' */ &&
|
||
|
c0 === 46 /* '.' */) {
|
||
|
out.isIcann = true;
|
||
|
out.isPrivate = false;
|
||
|
out.publicSuffix = 'edu';
|
||
|
return true;
|
||
|
}
|
||
|
else if (c3 === 118 /* 'v' */ &&
|
||
|
c2 === 111 /* 'o' */ &&
|
||
|
c1 === 103 /* 'g' */ &&
|
||
|
c0 === 46 /* '.' */) {
|
||
|
out.isIcann = true;
|
||
|
out.isPrivate = false;
|
||
|
out.publicSuffix = 'gov';
|
||
|
return true;
|
||
|
}
|
||
|
else if (c3 === 116 /* 't' */ &&
|
||
|
c2 === 101 /* 'e' */ &&
|
||
|
c1 === 110 /* 'n' */ &&
|
||
|
c0 === 46 /* '.' */) {
|
||
|
out.isIcann = true;
|
||
|
out.isPrivate = false;
|
||
|
out.publicSuffix = 'net';
|
||
|
return true;
|
||
|
}
|
||
|
else if (c3 === 101 /* 'e' */ &&
|
||
|
c2 === 100 /* 'd' */ &&
|
||
|
c1 === 46 /* '.' */) {
|
||
|
out.isIcann = true;
|
||
|
out.isPrivate = false;
|
||
|
out.publicSuffix = 'de';
|
||
|
return true;
|
||
|
}
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
const exceptions = (function () {
|
||
|
const _0 = [1, {}], _1 = [0, { "city": _0 }];
|
||
|
const exceptions = [0, { "ck": [0, { "www": _0 }], "jp": [0, { "kawasaki": _1, "kitakyushu": _1, "kobe": _1, "nagoya": _1, "sapporo": _1, "sendai": _1, "yokohama": _1 }] }];
|
||
|
return exceptions;
|
||
|
})();
|
||
|
const rules = (function () {
|
||
|
const _2 = [1, {}], _3 = [2, {}], _4 = [1, { "gov": _2, "com": _2, "org": _2, "net": _2, "edu": _2 }], _5 = [0, { "*": _3 }], _6 = [2, { "preview": _3 }], _7 = [0, { "relay": _3 }], _8 = [2, { "staging": _3 }], _9 = [2, { "id": _3 }], _10 = [1, { "blogspot": _3 }], _11 = [1, { "gov": _2 }], _12 = [0, { "notebook": _3, "studio": _3 }], _13 = [0, { "labeling": _3, "notebook": _3, "studio": _3 }], _14 = [0, { "notebook": _3 }], _15 = [0, { "labeling": _3, "notebook": _3, "notebook-fips": _3, "studio": _3 }], _16 = [0, { "notebook": _3, "notebook-fips": _3, "studio": _3, "studio-fips": _3 }], _17 = [0, { "*": _2 }], _18 = [0, { "cloud": _3 }], _19 = [1, { "co": _3 }], _20 = [0, { "objects": _3 }], _21 = [2, { "nodes": _3 }], _22 = [0, { "my": _5 }], _23 = [0, { "s3": _3, "s3-accesspoint": _3, "s3-website": _3 }], _24 = [0, { "s3": _3, "s3-accesspoint": _3 }], _25 = [0, { "execute-api": _3, "emrappui-prod": _3, "emrnotebooks-prod": _3, "emrstudio-prod": _3, "dualstack": _24, "s3": _3, "s3-accesspoint": _3, "s3-object-lambda": _3, "s3-website": _3 }], _26 = [0, { "direct": _3 }], _27 = [0, { "webview-assets": _3 }], _28 = [0, { "vfs": _3, "webview-assets": _3 }], _29 = [0, { "execute-api": _3, "emrappui-prod": _3, "emrnotebooks-prod": _3, "emrstudio-prod": _3, "dualstack": _23, "s3": _3, "s3-accesspoint": _3, "s3-object-lambda": _3, "s3-website": _3, "aws-cloud9": _27, "cloud9": _28 }], _30 = [0, { "execute-api": _3, "emrappui-prod": _3, "emrnotebooks-prod": _3, "emrstudio-prod": _3, "dualstack": _24, "s3": _3, "s3-accesspoint": _3, "s3-object-lambda": _3, "s3-website": _3, "aws-cloud9": _27, "cloud9": _28 }], _31 = [0, { "execute-api": _3, "emrappui-prod": _3, "emrnotebooks-prod": _3, "emrstudio-prod": _3, "dualstack": _23, "s3": _3, "s3-accesspoint": _3, "s3-object-lambda": _3, "s3-website": _3, "analytics-gateway": _3, "aws-cloud9": _27, "cloud9": _28 }], _32 = [0, { "s3": _3, "s3-accesspoint": _3, "s3-accesspoint-fips": _3, "s3-fips": _3, "s3-website": _3 }], _33 = [0, { "execute-api": _3, "emrappui-prod": _3, "emrnotebooks-prod": _3, "emrstudio-prod": _3, "dualstack": _32, "s3": _3, "s3-accesspoint": _3, "s3-accesspoint-fips": _3, "s3-fips": _3, "s3-object-lambda": _3, "s3-website": _3, "aws-cloud9": _27, "cloud9": _28 }], _34 = [0, { "s3": _3, "s3-accesspoint": _3, "s3-accesspoint-fips": _3, "s3-fips": _3 }], _35 = [0, { "execute-api": _3, "emrappui-prod": _3, "emrnotebooks-prod": _3, "emrstudio-prod": _3, "dualstack": _34, "s3": _3, "s3-accesspoint": _3, "s3-accesspoint-fips": _3, "s3-fips": _3, "s3-object-lambda": _3, "s3-website": _3 }], _36 = [0, { "auth": _3 }], _37 = [0, { "auth": _3, "auth-fips": _3 }], _38 = [0, { "apps": _3 }], _39 = [0, { "paas": _3 }], _40 = [2, { "eu": _3 }], _41 = [0, { "app": _3 }], _42 = [0, { "site": _3 }], _43 = [0, { "pages": _3 }], _44 = [1, { "com": _2, "edu": _2, "net": _2, "org": _2 }], _45 = [0, { "j": _3 }], _46 = [0, { "p": _3 }], _47 = [0, { "user": _3 }], _48 = [1, { "ybo": _3 }], _49 = [0, { "shop": _3 }], _50 = [0, { "cust": _3, "reservd": _3 }], _51 = [0, { "cust": _3 }], _52 = [1, { "gov": _2, "edu": _2, "mil": _2, "com": _2, "org": _2, "net": _2 }], _53 = [0, { "s3": _3 }], _54 = [1, { "edu": _2, "biz": _2, "net": _2, "org": _2, "gov": _2, "info": _2, "com": _2 }], _55 = [1, { "gov": _2, "blogspot": _3 }], _56 = [1, { "framer": _3 }], _57 = [0, { "forgot": _3 }], _58 = [0, { "cdn": _3 }], _59 = [1, { "gs": _2 }], _60 = [0, { "nes": _2 }], _61 = [1, { "k12": _2, "cc": _2, "lib": _2 }], _62 = [1, { "cc": _2, "lib": _2 }];
|
||
|
const rules = [0, { "ac": [1, { "com": _2, "edu": _2, "gov": _2, "net": _2, "mil": _2, "org": _2, "drr": _3, "feedback": _3, "forms": _3 }], "ad": [1, { "nom": _2 }], "ae": [1, { "co": _2, "net": _2, "org": _2, "sch": _2, "ac": _2, "gov": _2, "mil": _2, "blogspot": _3 }], "aero": [1, { "airline": _2, "airport": _2, "accident-investigation": _2, "accident-prevention": _2, "aerobatic": _2, "aeroclub": _2, "aerodrome": _2, "agents": _2, "air-surveillance": _2, "air-traffic-control": _2, "aircraft": _2, "airtraffic": _2, "ambulance": _2, "association": _2, "author": _2, "ballooning": _2, "broker": _2, "caa": _2, "cargo": _2, "catering": _2, "certification": _2, "championship": _2, "charter": _2, "civilaviation": _2, "club": _2, "conference": _2, "consultant": _2, "consulting": _2, "control": _2, "council": _2, "crew": _2, "design": _2, "dgca": _2, "educator": _2, "emergency": _2, "engine": _2, "engineer": _2, "entertainment": _2, "equipment": _2, "exchange": _2, "express": _2, "federation": _2, "flight": _2, "freight": _2, "fuel": _2, "gliding": _2, "government": _2, "groundhandling": _2, "group": _2, "hanggliding": _2, "homebuilt": _2, "insurance": _2, "journal": _2, "journalist": _2, "leasing": _2, "logistics": _2, "magazine": _2, "maintenance": _2, "marketplace": _2, "media": _2, "microlight": _2, "modelling": _2, "navigation": _2, "parachuting": _2, "paragliding": _2, "passenger-association": _2, "pilot": _2, "press": _2, "production": _2, "recreation": _2, "repbody": _2, "res": _2, "research": _2, "rotorcraft": _2, "safety": _2, "scientist": _2, "services": _2, "show": _2, "skydiving": _2, "software": _2, "student": _2, "taxi": _2, "trader": _2, "trading": _2, "trainer": _2, "union": _2, "workinggroup": _2, "works": _2 }], "af": _4, "ag": [1, { "com": _2, "org": _2, "net": _2, "co": _2, "nom": _2 }], "ai": [1, { "off": _2, "com": _2, "net": _2, "org": _2, "uwu": _3, "framer": _3 }], "al": [1, { "com": _2, "edu": _2, "gov": _2, "mil": _2, "net": _2, "org": _2, "blogspot": _3 }], "am": [1, { "co": _2, "com": _2, "commune": _2, "net": _2, "org": _2, "radio": _3, "blogspot": _3 }], "ao": [1, { "ed": _2, "gv": _2, "og": _2, "co": _2, "pb": _2, "it": _2 }], "aq": _2, "ar": [1, { "bet": _2, "com": _10, "coop": _2, "edu": _2, "gob": _2, "gov": _2, "int": _2, "mil": _2, "musica": _2, "mutual": _2, "net": _2, "org": _2, "senasa": _2, "tur": _2 }], "arpa": [1, { "e164": _2, "in-addr": _2, "ip6": _2, "iris": _2, "uri": _2, "urn": _2 }], "as": _11, "asia": [1, { "cloudns": _3, "daemon": _3, "dix": _3 }], "at": [1, { "ac": [1, { "sth": _2 }], "co": _10, "gv": _2, "or": _2, "funkfeuer": [0, { "wien": _3 }], "futurecms": [0, { "*": _3, "ex": _5, "in": _5 }], "futurehosting": _3, "futuremailing": _3, "ortsinfo": [0, { "ex": _5, "kunden": _5 }], "biz": _3, "info": _3, "123webseite": _3, "priv": _3, "myspreadshop": _3, "12hp": _3, "2ix": _3, "4lima": _3, "lima-city": _3 }], "au": [1, { "com": [1, { "blogspot": _3, "cloudlets": [0, { "mel": _3 }], "myspreadshop": _3 }], "net": _2, "org": _2, "edu": [1, { "act": _2, "catholic": _2, "nsw": [1, { "schools": _2 }], "nt": _2, "qld": _2, "sa": _2, "tas": _2, "vic": _2, "wa": _2 }], "gov": [1, { "qld": _2, "sa": _2, "tas": _2, "vic": _2, "wa": _2 }], "asn": _2, "id": _2, "info": _2, "conf": _2, "oz": _2, "act": _2, "nsw": _2, "nt": _2, "qld": _2, "sa": _2, "tas": _2, "vic": _2, "wa": _2 }], "aw": [1, { "com": _2 }], "ax": _2, "az": [1, { "com": _2, "net": _2, "int": _2, "gov": _2, "org": _2, "edu": _2, "info": _2, "pp": _2, "mil": _2, "name": _2, "pro": _2, "biz": _2 }], "ba": [1, { "com": _2, "edu": _2, "gov": _2, "mil": _2, "net": _2, "org": _2, "blogspot": _3, "rs": _3 }], "bb": [1, { "biz": _2, "co": _2, "com": _2, "edu": _2, "gov": _2, "info": _2, "net": _2, "org": _2, "store": _2, "tv": _2 }], "bd": _17, "be": [1, { "ac": _2, "cloudns": _3, "webhosting": _3, "blogspot": _3, "interhostsolutions": _18, "kuleuven": [0, { "ezproxy": _3 }], "123website": _3, "myspreadshop": _3, "transurl": _5 }], "bf": _11, "bg": [1, { "0": _2, "1": _2, "2": _2, "3": _2, "4": _2, "5": _2, "6": _2, "7": _2,
|
||
|
return rules;
|
||
|
})();
|
||
|
|
||
|
/**
|
||
|
* Lookup parts of domain in Trie
|
||
|
*/
|
||
|
function lookupInTrie(parts, trie, index, allowedMask) {
|
||
|
let result = null;
|
||
|
let node = trie;
|
||
|
while (node !== undefined) {
|
||
|
// We have a match!
|
||
|
if ((node[0] & allowedMask) !== 0) {
|
||
|
result = {
|
||
|
index: index + 1,
|
||
|
isIcann: node[0] === 1 /* RULE_TYPE.ICANN */,
|
||
|
isPrivate: node[0] === 2 /* RULE_TYPE.PRIVATE */,
|
||
|
};
|
||
|
}
|
||
|
// No more `parts` to look for
|
||
|
if (index === -1) {
|
||
|
break;
|
||
|
}
|
||
|
const succ = node[1];
|
||
|
node = Object.prototype.hasOwnProperty.call(succ, parts[index])
|
||
|
? succ[parts[index]]
|
||
|
: succ['*'];
|
||
|
index -= 1;
|
||
|
}
|
||
|
return result;
|
||
|
}
|
||
|
/**
|
||
|
* Check if `hostname` has a valid public suffix in `trie`.
|
||
|
*/
|
||
|
function suffixLookup(hostname, options, out) {
|
||
|
var _a;
|
||
|
if (fastPathLookup(hostname, options, out)) {
|
||
|
return;
|
||
|
}
|
||
|
const hostnameParts = hostname.split('.');
|
||
|
const allowedMask = (options.allowPrivateDomains ? 2 /* RULE_TYPE.PRIVATE */ : 0) |
|
||
|
(options.allowIcannDomains ? 1 /* RULE_TYPE.ICANN */ : 0);
|
||
|
// Look for exceptions
|
||
|
const exceptionMatch = lookupInTrie(hostnameParts, exceptions, hostnameParts.length - 1, allowedMask);
|
||
|
if (exceptionMatch !== null) {
|
||
|
out.isIcann = exceptionMatch.isIcann;
|
||
|
out.isPrivate = exceptionMatch.isPrivate;
|
||
|
out.publicSuffix = hostnameParts.slice(exceptionMatch.index + 1).join('.');
|
||
|
return;
|
||
|
}
|
||
|
// Look for a match in rules
|
||
|
const rulesMatch = lookupInTrie(hostnameParts, rules, hostnameParts.length - 1, allowedMask);
|
||
|
if (rulesMatch !== null) {
|
||
|
out.isIcann = rulesMatch.isIcann;
|
||
|
out.isPrivate = rulesMatch.isPrivate;
|
||
|
out.publicSuffix = hostnameParts.slice(rulesMatch.index).join('.');
|
||
|
return;
|
||
|
}
|
||
|
// No match found...
|
||
|
// Prevailing rule is '*' so we consider the top-level domain to be the
|
||
|
// public suffix of `hostname` (e.g.: 'example.org' => 'org').
|
||
|
out.isIcann = false;
|
||
|
out.isPrivate = false;
|
||
|
out.publicSuffix = (_a = hostnameParts[hostnameParts.length - 1]) !== null && _a !== void 0 ? _a : null;
|
||
|
}
|
||
|
|
||
|
// For all methods but 'parse', it does not make sense to allocate an object
|
||
|
// every single time to only return the value of a specific attribute. To avoid
|
||
|
// this un-necessary allocation, we use a global object which is re-used.
|
||
|
const RESULT = getEmptyResult();
|
||
|
function parse(url, options = {}) {
|
||
|
return parseImpl(url, 5 /* FLAG.ALL */, suffixLookup, options, getEmptyResult());
|
||
|
}
|
||
|
function getHostname(url, options = {}) {
|
||
|
/*@__INLINE__*/ resetResult(RESULT);
|
||
|
return parseImpl(url, 0 /* FLAG.HOSTNAME */, suffixLookup, options, RESULT).hostname;
|
||
|
}
|
||
|
function getPublicSuffix(url, options = {}) {
|
||
|
/*@__INLINE__*/ resetResult(RESULT);
|
||
|
return parseImpl(url, 2 /* FLAG.PUBLIC_SUFFIX */, suffixLookup, options, RESULT)
|
||
|
.publicSuffix;
|
||
|
}
|
||
|
function getDomain(url, options = {}) {
|
||
|
/*@__INLINE__*/ resetResult(RESULT);
|
||
|
return parseImpl(url, 3 /* FLAG.DOMAIN */, suffixLookup, options, RESULT).domain;
|
||
|
}
|
||
|
function getSubdomain(url, options = {}) {
|
||
|
/*@__INLINE__*/ resetResult(RESULT);
|
||
|
return parseImpl(url, 4 /* FLAG.SUB_DOMAIN */, suffixLookup, options, RESULT)
|
||
|
.subdomain;
|
||
|
}
|
||
|
function getDomainWithoutSuffix(url, options = {}) {
|
||
|
/*@__INLINE__*/ resetResult(RESULT);
|
||
|
return parseImpl(url, 5 /* FLAG.ALL */, suffixLookup, options, RESULT)
|
||
|
.domainWithoutSuffix;
|
||
|
}
|
||
|
|
||
|
exports.getDomain = getDomain;
|
||
|
exports.getDomainWithoutSuffix = getDomainWithoutSuffix;
|
||
|
exports.getHostname = getHostname;
|
||
|
exports.getPublicSuffix = getPublicSuffix;
|
||
|
exports.getSubdomain = getSubdomain;
|
||
|
exports.parse = parse;
|
||
|
//# sourceMappingURL=index.js.map
|