prop/assets/js/format.ts
Graham McIntire a9a355be2a
feat(format): miles-primary distance formatting sitewide
Add Microwaveprop.Format.distance_km/1 and a matching formatDistanceKm
helper for the JS side. Both emit "X mi (Y km)" with one decimal under
10 mi and whole numbers above.

Replace the ad-hoc format_dist/format_km_mi helpers with the shared
formatter and update every user-facing distance render: contact
detail, contacts index column, user profile contact/involving tables,
path finder summary + sounding list, contacts map line popups, beacon
coverage tooltip, and propagation map range estimate + rain scatter
cell popup.
2026-04-18 15:53:40 -05:00

11 lines
463 B
TypeScript

// Miles are the primary distance unit across the site. Km appears
// parenthetically so metric readers aren't lost. Keep this in sync
// with Microwaveprop.Format.distance_km/1 on the server side.
export function formatDistanceKm(km: number | null | undefined): string {
if (km == null) return "—"
const mi = km / 1.609344
if (mi < 10) {
return `${mi.toFixed(1)} mi (${km.toFixed(1)} km)`
}
return `${Math.round(mi)} mi (${Math.round(km)} km)`
}