Let’s turn an ISO country code into a Unicode emoji, shall we?
Ever since the first introduction of emojis in Unicode 6.0 the number of available pictograms keeps exploding. One particularly nice addition were regional indicator symbols which allow for the first time to display a visual representation of a flag without the help of images.
Wouldn’t it be nice to be able to easily convert a regular ISO 3166-1 alpha-2 country code to its respective Unicode emoji flag?
Here we go ....
'GB'.toUpperCase().replace(/./g, char => String.fromCodePoint(char.charCodeAt(0)+127397) );
This will turn “GB” into 🇬🇧 (if it displays 🇬🇧 instead of the British flag, your system does not support emoji flags yet).
For the sake of completeness, converting from an emoji flag to the country code is equally easy with
'🇬🇧'.replace(/../g, cp => String.fromCharCode(cp.codePointAt(0)-127397) );