Skip to content

Latest commit

 

History

78 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

npm (tag) License npm

country-to-currency

Maps country codes (ISO 3166-1 alpha-2) to their default currency codes (ISO 4217).

âš¡ Just 3 KB uncompressed (1.2 KB gzipped), no external dependencies.

🎯 Work with browsers, NodeJS, and DenoJS. JavaScript and TypeScript.

Install

npm i country-to-currency

Note: Version 3.x dropped the support to Universal Module Definition (UMD), in favor of the (modern) EcmaScript Modules (ESM).

Usage

This library exports a default object that maps country codes to currency codes.

👉 Examples available in the folder examples.

TypeScript

From version 1.1.0 on, there are two union types available (TypeScript 3.4+ only):

  • Currencies, that contains all the currencies;
  • Countries, that contains all the countries.

Example using TypeScript on NodeJS:

import countryToCurrency, { Currencies, Countries } from "country-to-currency";

Browser - without installing anything

<script type="module" >
  // import countryToCurrency from "https://unpkg.com/country-to-currency/index.esm.js"; // v2.x
  import countryToCurrency from "https://unpkg.com/country-to-currency"; // v3.x
  console.log( countryToCurrency[ 'US' ] ); // USD
</script>

NodeJS

Example with ESM:

import countryToCurrency from 'country-to-currency';
console.log( countryToCurrency[ 'US' ] ); // USD

Example with CJS (require);

// const countryToCurrency = require( 'country-to-currency' ); // v1.x and v2.0.2+
const { default: countryToCurrency } = require( 'country-to-currency' ); // v3+
console.log( countryToCurrency[ 'US' ] ); // USD

Deno

// import countryToCurrency from "https://unpkg.com/country-to-currency/index.esm.js"; // v2.x
import countryToCurrency from "https://unpkg.com/country-to-currency"; // v3.x
console.log( countryToCurrency[ 'US' ] ); // USD

Currency symbols

Do you also need currency symbols? See how to get them. 💲

Notes

  • Total countries: 251
    • Imported: 249
    • Included: 5
    • Fixed: 2
  • Currencies assumed:
Country Currency Details Legacy Thanks to
Antarctica (AQ) USD Antarctica has no official currency @thiagodp
Palestine (PS) ILS Google @thiagodp
South Georgia and the South Sandwich Islands (GS) FKP Wikipedia and https://gov.gs @danielrentz, @thiagodp
Netherlands Antilles (AN) ANG Legacy support. In 2026 Netherlands Antilles was split into separate countries. Yes @jayPare, @thiagodp
El Salvador (SV) USD Since 2001. Wikipedia @chaitanya-d, @thiagodp
Kosovo (XK) EUR Wikipedia and Geo Names @dukesilverr, @thiagodp
Buthan (BT) BTN According to Wikipedia @thiagodp

Contribute

Suggestions? Please open an Issue. Pull Requests? Make sure to edit generate.js instead of index.ts.

License

This library is inspired by Michael Rhodes' currency-code-map. The current project adds new currencies, fixes, offers support to browsers and DenoJS, updates dependencies, and provides new internal scripts.

MIT © Thiago Delgado Pinto

About

💵 Maps country codes (ISO 3166-1-alpha-2) to their default currency codes (ISO 4217)

Topics

Resources

Stars

59 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages