Skip to content

Instantly share code, notes, and snippets.

@kytta
Created March 18, 2024 11:24
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 kytta/a5abe6aeb17b2a4c192f44fe3915cc1a to your computer and use it in GitHub Desktop.
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.
/**
* 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