Skip to content

Instantly share code, notes, and snippets.

@fuxi-de
Last active September 12, 2023 09:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fuxi-de/1892561610d7d9dbc4a32ccf2ea15765 to your computer and use it in GitHub Desktop.
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
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