aboutsummaryrefslogtreecommitdiffstats
path: root/vanilla/node_modules/tldts/dist/es6/src/suffix-trie.js
diff options
context:
space:
mode:
authorAdam Mathes <adam@adammathes.com>2026-02-13 21:34:48 -0800
committerAdam Mathes <adam@adammathes.com>2026-02-13 21:34:48 -0800
commit76cb9c2a39d477a64824a985ade40507e3bbade1 (patch)
tree41e997aa9c6f538d3a136af61dae9424db2005a9 /vanilla/node_modules/tldts/dist/es6/src/suffix-trie.js
parent819a39a21ac992b1393244a4c283bbb125208c69 (diff)
downloadneko-76cb9c2a39d477a64824a985ade40507e3bbade1.tar.gz
neko-76cb9c2a39d477a64824a985ade40507e3bbade1.tar.bz2
neko-76cb9c2a39d477a64824a985ade40507e3bbade1.zip
feat(vanilla): add testing infrastructure and tests (NK-wjnczv)
Diffstat (limited to 'vanilla/node_modules/tldts/dist/es6/src/suffix-trie.js')
-rw-r--r--vanilla/node_modules/tldts/dist/es6/src/suffix-trie.js64
1 files changed, 64 insertions, 0 deletions
diff --git a/vanilla/node_modules/tldts/dist/es6/src/suffix-trie.js b/vanilla/node_modules/tldts/dist/es6/src/suffix-trie.js
new file mode 100644
index 0000000..cb8adab
--- /dev/null
+++ b/vanilla/node_modules/tldts/dist/es6/src/suffix-trie.js
@@ -0,0 +1,64 @@
+import { fastPathLookup, } from 'tldts-core';
+import { exceptions, rules } from './data/trie';
+/**
+ * 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 */) !== 0,
+ isPrivate: (node[0] & 2 /* RULE_TYPE.PRIVATE */) !== 0,
+ };
+ }
+ // 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`.
+ */
+export default 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;
+}
+//# sourceMappingURL=suffix-trie.js.map \ No newline at end of file