(host: string)
| 84 | * lowercased as-is — there is no unambiguous port to strip. |
| 85 | */ |
| 86 | export function stripPort(host: string): string { |
| 87 | if (host.startsWith('[')) { |
| 88 | const end = host.indexOf(']'); |
| 89 | return (end === -1 ? host : host.slice(0, end + 1)).toLowerCase(); |
| 90 | } |
| 91 | const firstColon = host.indexOf(':'); |
| 92 | if (firstColon === -1) { |
| 93 | return host.toLowerCase(); |
| 94 | } |
| 95 | const lastColon = host.lastIndexOf(':'); |
| 96 | if (firstColon === lastColon) { |
| 97 | const after = host.slice(lastColon + 1); |
| 98 | if (after.length > 0 && /^\d+$/.test(after)) { |
| 99 | return host.slice(0, lastColon).toLowerCase(); |
| 100 | } |
| 101 | } |
| 102 | // Multiple colons (bare IPv6) or a non-digit suffix — no port to strip. |
| 103 | return host.toLowerCase(); |
| 104 | } |
| 105 | |
| 106 | export function formatHostErrorMessage(host: string | undefined): string { |
| 107 | const normalizedHost = host === undefined || host.length === 0 ? undefined : stripPort(host); |
no outgoing calls
no test coverage detected