forked from wojtekmaj/country-code-to-flag-emoji
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert to TypeScript (wojtekmaj#14)
- Loading branch information
Showing
9 changed files
with
409 additions
and
186 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,3 @@ | ||
{ | ||
"presets": ["@babel/env"], | ||
"env": { | ||
"production-esm": { | ||
"presets": [["@babel/env", { "modules": false }]] | ||
} | ||
} | ||
"presets": ["@babel/typescript", "@babel/env"] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
{ | ||
"extends": "wojtekmaj" | ||
"extends": [ | ||
"wojtekmaj", | ||
"plugin:@typescript-eslint/eslint-recommended", | ||
"plugin:@typescript-eslint/recommended" | ||
], | ||
"parser": "@typescript-eslint/parser", | ||
"plugins": ["@typescript-eslint"] | ||
} |
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
This file was deleted.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Translates 'a' to '🇦', 'b' to '🇧' and so on. | ||
function letterToLetterEmoji(letter: string): string { | ||
return String.fromCodePoint(letter.toLowerCase().charCodeAt(0) + 127365); | ||
} | ||
|
||
// Translates 'pl' to 'PL', 'en-US' to 'US' and so on. | ||
function countryCodeToCountry(countryCode: string): string { | ||
const country = countryCode.split('-').pop() as string; | ||
|
||
return country.toUpperCase(); | ||
} | ||
|
||
// Translates 'pl-PL' to 🇵🇱 and so on. | ||
export default function countryCodeToFlagEmoji(string: string): string | null { | ||
if (!string) { | ||
return null; | ||
} | ||
|
||
return Array.from(countryCodeToCountry(string)).map(letterToLetterEmoji).join(''); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"exclude": ["src/**/*.spec.ts"] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"compilerOptions": { | ||
"declaration": true, | ||
"esModuleInterop": true, | ||
"isolatedModules": true, | ||
"moduleResolution": "node", | ||
"outDir": "dist", | ||
"strict": true | ||
}, | ||
"include": ["src"] | ||
} |
Oops, something went wrong.