Last active
November 1, 2020 13:28
-
-
Save Niels-NTG/8ac6bebe90c147c52f4f3b1d5f0a16e7 to your computer and use it in GitHub Desktop.
Construct flag emoji from ISO 3166-1 2 letter country code
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
/* | |
* Constructs an emoji flag using a supported ISO 3166-1 2 letter country code. | |
* | |
* Per character in the input string it shifts it 127365 code points from the ASCII lower case | |
* characters to Regional Indicator Symbol series, which is used to construct flag emoji. | |
* | |
* @param {String} regionCode String starting with a supported ISO 3166-1 2 letter region code. | |
* @returns {String} Emoji flag character constructed from 2 regional indicator symbols. | |
*/ | |
function flag(regionCode = '') { | |
return regionCode.toLowerCase().split('', 2).reduce((m, char) => { | |
return m + String.fromCodePoint(char.codePointAt(0) + 127365) | |
}, '') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment