Last active
February 9, 2022 18:13
-
-
Save jaandrle/9cf83097b1636cd80ed0d5acb7563381 to your computer and use it in GitHub Desktop.
Create emoji flag (not only in JS, the logic is the same for others)
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
/* jshint esversion: 6,-W097, -W040, browser: true, expr: true, undef: true */ | |
/** | |
* Flags emojis are just concation of two emoji letters (see [1]). | |
* Inspired by [2]. | |
* | |
* - [1] https://apps.timwhitlock.info/emoji/tables/iso3166 | |
* - [2] https://twitter.com/rauschma/status/1491189507261333505 | |
* | |
* @param {string|string[]} country Two letters (e.g. 'cs', 'us', …) | |
* @returns {string} | |
* @example | |
* console.log(createEmojiFlag("cz")); //🇨🇿 | |
*/ | |
function createEmojiFlag([ l1, l2 ]){ | |
const a= "a".codePointAt(0) - 0x1F1E6; | |
return [ l1, l2 ].map(l=> String.fromCodePoint(l.toLowerCase().codePointAt(0) - a)).join(""); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment