diff options
| author | Adam Mathes <adam@adammathes.com> | 2026-02-13 21:34:48 -0800 |
|---|---|---|
| committer | Adam Mathes <adam@adammathes.com> | 2026-02-13 21:34:48 -0800 |
| commit | 76cb9c2a39d477a64824a985ade40507e3bbade1 (patch) | |
| tree | 41e997aa9c6f538d3a136af61dae9424db2005a9 /vanilla/node_modules/tldts-core/src/lookup | |
| parent | 819a39a21ac992b1393244a4c283bbb125208c69 (diff) | |
| download | neko-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-core/src/lookup')
| -rw-r--r-- | vanilla/node_modules/tldts-core/src/lookup/fast-path.ts | 80 | ||||
| -rw-r--r-- | vanilla/node_modules/tldts-core/src/lookup/interface.ts | 10 |
2 files changed, 90 insertions, 0 deletions
diff --git a/vanilla/node_modules/tldts-core/src/lookup/fast-path.ts b/vanilla/node_modules/tldts-core/src/lookup/fast-path.ts new file mode 100644 index 0000000..f80898f --- /dev/null +++ b/vanilla/node_modules/tldts-core/src/lookup/fast-path.ts @@ -0,0 +1,80 @@ +import { IPublicSuffix, ISuffixLookupOptions } from './interface'; + +export default function ( + hostname: string, + options: ISuffixLookupOptions, + out: IPublicSuffix, +): boolean { + // 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: number = hostname.length - 1; + const c3: number = hostname.charCodeAt(last); + const c2: number = hostname.charCodeAt(last - 1); + const c1: number = hostname.charCodeAt(last - 2); + const c0: number = 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; +} diff --git a/vanilla/node_modules/tldts-core/src/lookup/interface.ts b/vanilla/node_modules/tldts-core/src/lookup/interface.ts new file mode 100644 index 0000000..495a642 --- /dev/null +++ b/vanilla/node_modules/tldts-core/src/lookup/interface.ts @@ -0,0 +1,10 @@ +export interface IPublicSuffix { + isIcann: boolean | null; + isPrivate: boolean | null; + publicSuffix: string | null; +} + +export interface ISuffixLookupOptions { + allowIcannDomains: boolean; + allowPrivateDomains: boolean; +} |
