Created
April 13, 2018 13:33
-
-
Save bjjb/7bfb0ddb731021e650a9309c46bd05cd to your computer and use it in GitHub Desktop.
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
/* | |
* Converts the 2-letter code (such as "es" or "ie" to an emoji representing that country's flag. | |
* It works because a flag emoji, such as the German flag, is a combination of regional letter | |
* glyphs (🇩 🇪 without a space is rendered as 🇩🇪, the German (de) flag). Those glyphs start at | |
* 0x1f1e6 and end at 0x1f1ff. 'a' is 97. | |
*/ | |
const flagEmojiForCode = (code) => { | |
const h = code.toLowerCase().charCodeAt(0) + (0x1f1e6 - 97) | |
const l = code.toLowerCase().charCodeAt(1) + (0x1f1e6 - 97) | |
return String.fromCodePoint(h, l) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment