Created
August 8, 2020 20:22
-
-
Save freewayspb/3fcd269f2b7750c04a7fa3639f87be32 to your computer and use it in GitHub Desktop.
Method for convertation ISO country name to flag emoji
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
// ISO 3166-1 alpha-2 | |
// ⚠️ No support for IE 11 | |
const countryToFlag = isoCode => { | |
return typeof String.fromCodePoint !== 'undefined' | |
? isoCode.toUpperCase().replace(/./g, char => String.fromCodePoint(char.charCodeAt(0) + 127397)) | |
: isoCode | |
} | |
export default countryToFlag |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment