mirror of
https://github.com/CompassConnections/Compass.git
synced 2026-02-25 11:27:09 -05:00
* Test * Add pretty formatting * Fix Tests * Fix Tests * Fix Tests * Fix * Add pretty formatting fix * Fix * Test * Fix tests * Clean typeckech * Add prettier check * Fix api tsconfig * Fix api tsconfig * Fix tsconfig * Fix * Fix * Prettier
19 lines
556 B
TypeScript
19 lines
556 B
TypeScript
// web only. uses Intl https://caniuse.com/mdn-javascript_builtins_intl_displaynames
|
|
|
|
export function countryCodeToFlag(code?: string) {
|
|
if (!code || !getCountryName(code)) return null
|
|
|
|
const x = 0x1f1a5 + code.toUpperCase().charCodeAt(0)
|
|
const y = 0x1f1a5 + code.toUpperCase().charCodeAt(1)
|
|
|
|
return String.fromCodePoint(x, y)
|
|
}
|
|
|
|
export function getCountryName(code: string) {
|
|
const country = countries.of(code)
|
|
if (!country || country === code) return null
|
|
return country
|
|
}
|
|
|
|
const countries = new Intl.DisplayNames(['en'], {type: 'region'})
|