( alpha3OrAlpha2?: string )
| 12 | * @returns canonicalized 2 letter country code (uppercase) or undefined if not found |
| 13 | */ |
| 14 | export 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 | } |
no outgoing calls
no test coverage detected