Files
Compass/web/lib/util/location.ts
Martin Braquet ba9b3cfb06 Add pretty formatting (#29)
* 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
2026-02-20 17:32:27 +01:00

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'})