2e6ee9dad2
Follow-up to #78: - Use primaryIp() so href targets the first IP when data.ip is comma-separated (e.g. "192.168.1.1, 2001:db8::1") - Add primaryIp() helper to maskIp.ts - Add 4 tests covering single IP link, absent IP, multi-IP href, multi-IP display text
16 lines
411 B
TypeScript
16 lines
411 B
TypeScript
/**
|
|
* Mask the last two octets of an IPv4 address.
|
|
* e.g. "192.168.1.115" → "192.168.XX.XX"
|
|
* Non-IPv4 strings are returned unchanged.
|
|
*/
|
|
export function maskIp(ip: string): string {
|
|
const parts = ip.split('.')
|
|
if (parts.length === 4) return `${parts[0]}.${parts[1]}.XX.XX`
|
|
return ip
|
|
}
|
|
|
|
export function primaryIp(ip: string): string {
|
|
if (!ip?.trim()) return ''
|
|
return ip.split(',')[0].trim()
|
|
}
|