Skip to content

Instantly share code, notes, and snippets.

@porsager
Last active May 9, 2020 20:06
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save porsager/9108b4d1eccb0c624401d2b347e50220 to your computer and use it in GitHub Desktop.
Save porsager/9108b4d1eccb0c624401d2b347e50220 to your computer and use it in GitHub Desktop.
Simple function to return an emoji flag from an ISO 3166-1 alpha-2 country code

Emoji Flag

preview here

Small function to return an emoji flag corresponding to a country code.

flag('DK') // returns '🇩🇰'
const flag = x => String.fromCodePoint(
  x.toUpperCase()[0].codePointAt(0) + 127397,
  x.toUpperCase()[1].codePointAt(0) + 127397
)
const flag = x => String.fromCodePoint(
x.toUpperCase()[0].codePointAt(0) + 127397,
x.toUpperCase()[1].codePointAt(0) + 127397
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment