Skip to content

Instantly share code, notes, and snippets.

@ferreiro
Last active September 30, 2021 07:52
Show Gist options
  • Save ferreiro/d300473d192db8c97fb593d4d72d1445 to your computer and use it in GitHub Desktop.
Save ferreiro/d300473d192db8c97fb593d4d72d1445 to your computer and use it in GitHub Desktop.
// Generated based on https://en.wikipedia.org/wiki/ISO_4217
// Make sure here you pass the two letters country code, if you find countryCodes with more digits
// and it's not in this list, make sure to add that.
const COUNTRY_CODE_TO_CURRENCY = {
// EUROS
AX: "EUR",
EU: "EUR",
AD: "EUR",
AT: "EUR",
BE: "EUR",
CY: "EUR",
EE: "EUR",
FI: "EUR",
FR: "EUR",
TF: "EUR",
DE: "EUR",
GR: "EUR",
GP: "EUR",
IE: "EUR",
IT: "EUR",
LV: "EUR",
LT: "EUR",
LU: "EUR",
MT: "EUR",
GF: "EUR",
MQ: "EUR",
YT: "EUR",
MC: "EUR",
ME: "EUR",
NL: "EUR",
PT: "EUR",
RE: "EUR",
BL: "EUR",
MF: "EUR",
PM: "EUR",
SM: "EUR",
SK: "EUR",
SI: "EUR",
ES: "EUR",
VA: "EUR",
// GBP
GB: "GBP",
IM: "GBP",
JE: "GBP",
GG: "GBP",
SHN: "GBP",
// INDIAN RUPEE
IN: "INR",
BT: "INR", // buthan
};
function getCurrency(countryCode) {
if (countryCode in CURRENCIES_BY_COUNTRIES) {
return COUNTRY_CODE_TO_CURRENCY[countryCode];
}
return "USD";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment