Last active
September 12, 2023 09:13
-
-
Save fuxi-de/1892561610d7d9dbc4a32ccf2ea15765 to your computer and use it in GitHub Desktop.
Get a Flag Emoji by the ISO country code derived from this DEV.to article -> https://dev.to/jorik/country-code-to-flag-emoji-a21
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const utf16A = 65; | |
const unicodeRegionA = 127462; | |
const flagBaseChar = unicodeRegionA - utf16A; | |
const exampleCountryCode = 'DE' | |
const getFlagByCountryCode = (countryCode: string) => { | |
const codePoints = countryCode | |
.toUpperCase() | |
.split('') | |
.map((char) => flagBaseChar + char.charCodeAt(0)); | |
return String.fromCodePoint(...codePoints); | |
} | |
getFlagByCountryCode(exampleCountryCode) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment