diff options
Diffstat (limited to 'bin/wiki/ImportarDesdeURL/node_modules/tldts/dist/es6/src/suffix-trie.js')
-rw-r--r-- | bin/wiki/ImportarDesdeURL/node_modules/tldts/dist/es6/src/suffix-trie.js | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/bin/wiki/ImportarDesdeURL/node_modules/tldts/dist/es6/src/suffix-trie.js b/bin/wiki/ImportarDesdeURL/node_modules/tldts/dist/es6/src/suffix-trie.js new file mode 100644 index 00000000..5168e849 --- /dev/null +++ b/bin/wiki/ImportarDesdeURL/node_modules/tldts/dist/es6/src/suffix-trie.js @@ -0,0 +1,61 @@ +import { fastPathLookup, } from 'tldts-core'; +import { exceptions, rules } from './data/trie'; +/** + * Lookup parts of domain in Trie + */ +function lookupInTrie(parts, trie, index, allowedMask) { + var result = null; + var node = trie; + while (node !== undefined) { + // We have a match! + if ((node.$ & allowedMask) !== 0) { + result = { + index: index + 1, + isIcann: node.$ === 1 /* ICANN */, + isPrivate: node.$ === 2 /* PRIVATE */ + }; + } + // No more `parts` to look for + if (index === -1) { + break; + } + var succ = node.succ; + node = succ && (succ[parts[index]] || succ['*']); + index -= 1; + } + return result; +} +/** + * Check if `hostname` has a valid public suffix in `trie`. + */ +export default function suffixLookup(hostname, options, out) { + if (fastPathLookup(hostname, options, out) === true) { + return; + } + var hostnameParts = hostname.split('.'); + var allowedMask = (options.allowPrivateDomains === true ? 2 /* PRIVATE */ : 0) | + (options.allowIcannDomains === true ? 1 /* ICANN */ : 0); + // Look for exceptions + var 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 + var 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 = hostnameParts[hostnameParts.length - 1]; +} +//# sourceMappingURL=suffix-trie.js.map
\ No newline at end of file |