Binary Passion
Published in

Binary Passion

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.

Emoji Flags

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) );

--

--

--

01010111 01100101 00100000 01100001 01110010 01100101 00100000 01100001 00100000 01100011 01110101 01110010 01101001 01101111 01110101 01110011 00100000 01100010 01110101 01101110 01100011 01101000 00101100 01100001 01110010 01100101 01101110 01110100 00100000 01110111 01100101

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
....

....

Animal Welfare, Software, Linguistics, Politics

More from Medium

My Journey to Change the Face of Competitive Sailing

Random Musings #45: Breathe Every Breath!

How To Write A Great MUN Position Paper — MUN Explained

self-reforestation