Created
March 18, 2024 11:24
-
-
Save kytta/a5abe6aeb17b2a4c192f44fe3915cc1a to your computer and use it in GitHub Desktop.
Get the emoji flag for an ISO-3166-1 alpha-2 country 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
/** | |
* Return the emoji flag for an ISO-3166-1 alpha-2 country code. | |
* | |
* The ISO code should be a string consisting of two latin characters | |
* (case-insensitive). Note that this method *does not* check the validity | |
* of the provided ISO code. | |
* | |
* @param {string} isoCode | |
* ISO-3166-1 alpha-2 country code | |
* @return {string} the emoji of the country's flag | |
*/ | |
const emojiFlag = (isoCode) => | |
String.fromCodePoint( | |
...Array.from(isoCode).map( | |
(letter) => | |
"🇦".codePointAt(0) - | |
"A".codePointAt(0) + | |
letter.toUpperCase().codePointAt(0), | |
), | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment