Skip to content

Instantly share code, notes, and snippets.

@cferdinandi
Created November 21, 2023 19:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cferdinandi/887a485cf835ee21cccf94b31584e433 to your computer and use it in GitHub Desktop.
Save cferdinandi/887a485cf835ee21cccf94b31584e433 to your computer and use it in GitHub Desktop.
<!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