MCPcopy Create free account
hub / github.com/formatjs/formatjs / canonicalizeCountryCode

Function canonicalizeCountryCode

packages/utils/countryCodes.ts:14–26  ·  view source on GitHub ↗
(
  alpha3OrAlpha2?: string
)

Source from the content-addressed store, hash-verified

12 * @returns canonicalized 2 letter country code (uppercase) or undefined if not found
13 */
14export function canonicalizeCountryCode(
15 alpha3OrAlpha2?: string
16): string | undefined {
17 if (!alpha3OrAlpha2) {
18 return
19 }
20 const upper = alpha3OrAlpha2.toUpperCase()
21 // Lenient here, if it's already a 2 letter code, just return it
22 if (upper.length === 2) {
23 return COUNTRY_CODE_ALPHA2.has(upper) ? upper : undefined
24 }
25 return alpha3CountryCodes[upper as 'USA']
26}

Callers 3

defaultLocaleFunction · 0.85
defaultCurrencyFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected