-
-
Save 0xlkda/d8136dcabe1dc992b306eed5dd4b1b0a to your computer and use it in GitHub Desktop.
Get country flag using its 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
// ISO 3166-1 alpha-2 | |
// ⚠️ No support for IE 11 | |
// Source: all over the internet | |
function countryToFlag(code) { | |
let isoCode = code.split("-").pop() | |
return typeof String.fromCodePoint !== 'undefined' | |
? isoCode | |
.toUpperCase() | |
.replace(/./g, (char) => String.fromCodePoint(char.charCodeAt(0) + 127397)) | |
: isoCode; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment