aboutsummaryrefslogtreecommitdiffstats
path: root/vanilla/node_modules/tldts-core/src/domain.ts
diff options
context:
space:
mode:
authorAdam Mathes <adam@adammathes.com>2026-02-14 14:46:37 -0800
committerAdam Mathes <adam@adammathes.com>2026-02-14 14:46:37 -0800
commitafa87af01c79a9baa539f2992d32154d2a4739bd (patch)
tree92c7416db734270a2fee1d72ee9cc119379ff8e1 /vanilla/node_modules/tldts-core/src/domain.ts
parent3b927e84d200402281f68181cd4253bc77e5528d (diff)
downloadneko-afa87af01c79a9baa539f2992d32154d2a4739bd.tar.gz
neko-afa87af01c79a9baa539f2992d32154d2a4739bd.tar.bz2
neko-afa87af01c79a9baa539f2992d32154d2a4739bd.zip
task: delete vanilla js prototype\n\n- Removed vanilla/ directory and web/dist/vanilla directory\n- Updated Makefile, Dockerfile, and CI workflow to remove vanilla references\n- Cleaned up web/web.go to remove vanilla embed and routes\n- Verified build and tests pass\n\nCloses NK-2tcnmq
Diffstat (limited to 'vanilla/node_modules/tldts-core/src/domain.ts')
-rw-r--r--vanilla/node_modules/tldts-core/src/domain.ts100
1 files changed, 0 insertions, 100 deletions
diff --git a/vanilla/node_modules/tldts-core/src/domain.ts b/vanilla/node_modules/tldts-core/src/domain.ts
deleted file mode 100644
index 640d33e..0000000
--- a/vanilla/node_modules/tldts-core/src/domain.ts
+++ /dev/null
@@ -1,100 +0,0 @@
-import { IOptions } from './options';
-
-/**
- * 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: string, vhost: string): boolean {
- 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: string,
- publicSuffix: string,
-): string {
- // 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
- */
-export default function getDomain(
- suffix: string,
- hostname: string,
- options: IOptions,
-): string | null {
- // 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);
-}