MCPcopy Create free account
hub / github.com/adcontextprotocol/adcp / normalizeDomain

Function normalizeDomain

server/src/services/property-check.ts:55–79  ·  view source on GitHub ↗

* Normalize a raw domain input to its canonical form. * Returns the canonical form and the reason code if the input was changed.

(raw: string)

Source from the content-addressed store, hash-verified

53 * Returns the canonical form and the reason code if the input was changed.
54 */
55function normalizeDomain(raw: string): NormalizeResult {
56 const trimmed = raw.trim();
57
58 // Strip protocol, path, query, fragment, trailing slash
59 let canonical = trimmed
60 .replace(/^https?:\/\//i, '')
61 .replace(/[/?#].*$/, '')
62 .replace(/\.$/, '') // trailing FQDN dot
63 .replace(/\/$/, '')
64 .toLowerCase();
65
66 let reason: string | null = null;
67
68 if (canonical.startsWith('www.')) {
69 canonical = canonical.slice(4);
70 reason = 'www_stripped';
71 } else if (canonical.startsWith('m.')) {
72 canonical = canonical.slice(2);
73 reason = 'm_stripped';
74 } else if (canonical !== trimmed.replace(/^https?:\/\//i, '').replace(/[/?#].*$/, '').replace(/\.$/, '').replace(/\/$/, '').toLowerCase()) {
75 reason = 'normalized';
76 }
77
78 return { canonical, reason };
79}
80
81export class PropertyCheckService {
82 async check(domains: string[]): Promise<CheckResult> {

Callers 1

checkMethod · 0.70

Calls 1

trimMethod · 0.65

Tested by

no test coverage detected