-
-
Save cferdinandi/887a485cf835ee21cccf94b31584e433 to your computer and use it in GitHub Desktop.
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>getFlagEmoji.js</title> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
</head> | |
<body> | |
<script> | |
/** | |
* Get the flag emoji for the country | |
* @link https://dev.to/jorik/country-code-to-flag-emoji-a21 | |
* @param {String} countryCode The country code | |
* @return {String} The flag emoji | |
*/ | |
function getFlagEmoji (countryCode) { | |
let codePoints = countryCode.toUpperCase().split('').map(char => 127397 + char.charCodeAt()); | |
return String.fromCodePoint(...codePoints); | |
} | |
console.log(getFlagEmoji('us')); | |
console.log(getFlagEmoji('jp')); | |
console.log(getFlagEmoji('mx')); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment