(code: string | null | undefined, locale = 'en')
| 32 | // Localized country/region name from an ISO 3166-1 alpha-2 code (e.g. "JP" -> "Japan" |
| 33 | // / "日本"). Falls back to the uppercased code when the runtime can't resolve a name. |
| 34 | export function countryCodeToName(code: string | null | undefined, locale = 'en'): string { |
| 35 | if (!code || code.length !== 2) { |
| 36 | return '' |
| 37 | } |
| 38 | const upper = code.toUpperCase() |
| 39 | const names = regionNamesFor(locale) |
| 40 | if (!names) { |
| 41 | return upper |
| 42 | } |
| 43 | try { |
| 44 | return names.of(upper) ?? upper |
| 45 | } catch { |
| 46 | return upper |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | /** ISO `{from, to}` window ending now and reaching `hours` back — the query |
| 51 | * window shape every records/anomalies endpoint expects. */ |
no test coverage detected