currency-to-country
TypeScript icon, indicating that this package has built-in type declarations

0.1.2 • Public • Published

currency-to-country

Get country information via currency code

✨ Zero dependency package

npm

Installtion

pnpm add currency-to-country

Usage

1. Get a list of countries that uses a specific currency.

import getCountryByCurrency from 'currency-to-country';

const countries = getCountryByCurrency('NZD');

console.log(countries);

Outputs:

[
  {
    countryName: 'Cook Islands',
    countryCode: 'CK',
    currencyName: 'New Zealand Dollars',
    currencyCode: 'NZD',
    countryFlag: 'https://purecatamphetamine.github.io/country-flag-icons/3x2/CK.svg'
  },
  {
    countryName: 'New Zealand',
    countryCode: 'NZ',
    currencyName: 'New Zealand Dollars',
    currencyCode: 'NZD',
    countryFlag: 'https://purecatamphetamine.github.io/country-flag-icons/3x2/NZ.svg'
  },
  {
    countryName: 'Niue',
    countryCode: 'NU',
    currencyName: 'New Zealand Dollars',
    currencyCode: 'NZD',
    countryFlag: 'https://purecatamphetamine.github.io/country-flag-icons/3x2/NU.svg'
  },
  {
    countryName: 'Pitcairn',
    countryCode: 'PN',
    currencyName: 'New Zealand Dollars',
    currencyCode: 'NZD',
    countryFlag: 'https://purecatamphetamine.github.io/country-flag-icons/3x2/PN.svg'
  },
  {
    countryName: 'Tokelau',
    countryCode: 'TK',
    currencyName: 'New Zealand Dollars',
    currencyCode: 'NZD',
    countryFlag: 'https://purecatamphetamine.github.io/country-flag-icons/3x2/TK.svg'
  }
]

2. Get only one country for one currency

This is filtered by passing one of the country codes of the given currency into the priorityCountries option. You can basically pass a list of any country codes in this and if the currency matches with one of these countries; it will prioritize and return that country only. If all the country codes you passed does not match with the countries mapped to that currency, the package will simply return all the original countries that's mapped to the currency.

import getCountryByCurrency from 'currency-to-country';

// Now this will only return `New Zealand` as it has been
// prioriotized over the other countries for the given currency.
const country = getCountryByCurrency('NZD', { priorityCountries: ['NZ'] });

// This will still return an array but with a single item
console.log(country[0]);

Outputs:

{
    countryName: 'New Zealand',
    countryCode: 'NZ',
    currencyName: 'New Zealand Dollars',
    currencyCode: 'NZD',
    countryFlag: 'https://purecatamphetamine.github.io/country-flag-icons/3x2/NZ.svg'
}

💡 The country flags are comming from @purecatamphetamine/country-flag-icons

License

MIT © Rocktim Saikia

Package Sidebar

Install

npm i currency-to-country

Weekly Downloads

43

Version

0.1.2

License

MIT

Unpacked Size

94.2 kB

Total Files

6

Last publish

Collaborators

  • rocktimsaikia