Last active
February 6, 2023 15:57
-
-
Save jebarjonet/c6b05d7f43327856320de5a1a89aaffb to your computer and use it in GitHub Desktop.
Transforms a country code (ISO 3166-1 alpha-2) into corresponding flag emoji
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
import { toUpper } from 'lodash' | |
export const codeToFlag = (code: string): string => | |
String.fromCodePoint( | |
...toUpper(code) | |
.split('') | |
.map(c => 127397 + c.charCodeAt(0)), | |
) | |
// codeToFlag('fr') => π«π· | |
// codeToFlag('gb') => π¬π§ | |
// codeToFlag('jp') => π―π΅ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment