MCPcopy Create free account
hub / github.com/ZingerLittleBee/ServerBee / countryCodeToName

Function countryCodeToName

apps/web/src/lib/utils.ts:34–48  ·  view source on GitHub ↗
(code: string | null | undefined, locale = 'en')

Source from the content-addressed store, hash-verified

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.
34export 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. */

Callers 2

CountryFlagFunction · 0.90
toOptionFunction · 0.90

Calls 1

regionNamesForFunction · 0.85

Tested by

no test coverage detected