Created
June 14, 2021 02:28
-
-
Save hieunc229/fa74865534351300c10056b0e6566511 to your computer and use it in GitHub Desktop.
Get country flag using its code
This file contains hidden or 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