Rocky_Mountain_Vending/.pnpm-store/v10/files/38/57d4c07037bbe87934d97f7eda8ffb9ca6395755c207490eba9e453660d06e9e94053f5b8cb238fba7c3be52535b013bd43127cea564c12180c0317da66846
DMleadgen 46d973904b
Initial commit: Rocky Mountain Vending website
Next.js website for Rocky Mountain Vending company featuring:
- Product catalog with Stripe integration
- Service areas and parts pages
- Admin dashboard with Clerk authentication
- SEO optimized pages with JSON-LD structured data

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-12 16:22:15 -07:00

87 lines
1.8 KiB
Text

import {
fastPathLookup,
IPublicSuffix,
ISuffixLookupOptions,
} from 'tldts-core';
import { exceptions, ITrie, rules } from './data/trie';
interface IMatch {
index: number;
}
/**
* Lookup parts of domain in Trie
*/
function lookupInTrie(
parts: string[],
trie: ITrie,
index: number,
): IMatch | null {
let result: IMatch | null = null;
let node: ITrie | undefined = trie;
while (node !== undefined) {
// We have a match!
if (node[0] === 1) {
result = {
index: index + 1,
};
}
// No more `parts` to look for
if (index === -1) {
break;
}
const succ: { [label: string]: ITrie } = 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: string,
options: ISuffixLookupOptions,
out: IPublicSuffix,
): void {
if (fastPathLookup(hostname, options, out)) {
return;
}
const hostnameParts = hostname.split('.');
// Look for exceptions
const exceptionMatch = lookupInTrie(
hostnameParts,
exceptions,
hostnameParts.length - 1,
);
if (exceptionMatch !== null) {
out.publicSuffix = hostnameParts.slice(exceptionMatch.index + 1).join('.');
return;
}
// Look for a match in rules
const rulesMatch = lookupInTrie(
hostnameParts,
rules,
hostnameParts.length - 1,
);
if (rulesMatch !== null) {
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.publicSuffix = hostnameParts[hostnameParts.length - 1] ?? null;
}