DEV Community

Discussion on: Add Country Flags to Your App With This API - countryflags.io alternative

Collapse
 
jonrandy profile image
Jon Randy 🎖️

You can just use one line of JS - without any API at all:

const getFlagEmoji = countryCode=>String.fromCodePoint(...[...countryCode.toUpperCase()].map(x=>0x1f1a5+x.charCodeAt(0)))

getFlagEmoji('gb') // 🇬🇧
getFlagEmoji('za') // 🇿🇦
getFlagEmoji('th') // 🇹🇭
Enter fullscreen mode Exit fullscreen mode
Collapse
 
jeremypersing profile image
Jeremy Persing

I looked into this solution but Windows 10 doesn't seem to support flag emojis. This is the example on Windows
Windows Version
compared to other operating systems.
Everything else
Also, one of the drawbacks that I encountered working with other flag APIs is that you can only access a flag by its 2 letter country code. This became a pain to work with because the API that was supplying me with country data didn't include a 2 letter country code. That's why at countryflagsapi you can get a country's flag by the country's name, two letter code, three letter code, or UN Code. But if the application has access to the two letter country code and doesn't mind not having flags being shown on Windows 10, I think your solution is the way to go.

Collapse
 
jonrandy profile image
Comment marked as low quality/non-constructive by the community. View Code of Conduct
Jon Randy 🎖️

Man, Windows is a total joke... why do people still use it?