Files
markitect-main/node_modules/tldts-core/src/lookup/fast-path.ts
tegwick c5a5b26797
Some checks failed
Test Suite / code-quality (push) Has been cancelled
Test Suite / unit-tests (3.11) (push) Has been cancelled
Test Suite / unit-tests (3.12) (push) Has been cancelled
Test Suite / security-scan (push) Has been cancelled
Test Suite / integration-tests (push) Has been cancelled
Test Suite / e2e-tests (push) Has been cancelled
Test Suite / performance-tests (push) Has been cancelled
Test Suite / test-summary (push) Has been cancelled
refactor: Still trying to reorganize edit mode to be more robust
2025-11-04 21:59:22 +01:00

81 lines
2.1 KiB
TypeScript

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;
}