Skip to content

Commit

Permalink
Add getCountryFlagEmoji snippet
Browse files Browse the repository at this point in the history
  • Loading branch information
Firestorm980 committed Nov 4, 2023
1 parent 25dbc2b commit 602f567
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/content/snippets/debounce.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: Debounce
title: debounce
categories:
- JavaScript
- Performance
Expand Down
2 changes: 1 addition & 1 deletion src/content/snippets/emitEvent.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: Emit Event
title: emitEvent
categories:
- JavaScript
last_updated: '2022-11-13'
Expand Down
21 changes: 21 additions & 0 deletions src/content/snippets/getCountryFlagEmoji.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
title: getCountryFlagEmoji
categories:
- JavaScript
last_updated: '2023-11-4'
description: Automatically get the country flag emoji from the country code.
---
```js
/**
* Get the emoji flag for a country code.
* @link https://dev.to/jorik/country-code-to-flag-emoji-a21
* @link https://gomakethings.com/getting-emoji-from-country-codes-with-vanilla-javascript/
* @param {string} countryCode The two letter country code.
* @returns {string} The country emoji flag.
*/
function getCountryFlagEmoji (countryCode) {
return [...countryCode.toUpperCase()].map(char =>
String.fromCodePoint(127397 + char.charCodeAt())
).reduce((a, b) => a + b)
};
```

0 comments on commit 602f567

Please sign in to comment.