currency-codes-country-codes-flags
v0.1.0
Published
Map currency codes to country codes and SVG flags with helpful lookup utilities.
Maintainers
Readme
currency-codes-country-codes-flags
Lightweight utilities and data to map ISO 4217 currency codes to ISO 3166 country codes and SVG flags. Ships with helpful lookup functions and returns flag file URLs that resolve to the package's flags/ directory.
Install
npm i currency-codes-country-codes-flagsUsage
import {
getCurrencyByCode,
getCurrenciesByCountryCode,
findCurrenciesByName,
getFlagUrlByCurrencyCode,
getFlagUrlByCountryCode,
getFlagUrlsForCurrency,
getAllCurrencyEntries,
} from "currency-codes-country-codes-flags";
const usd = getCurrencyByCode("USD");
// {
// currencyCode: 'USD',
// currencyName: 'United States Dollar',
// primaryCountryCode: 'US',
// otherCountryCodes: ['AS', 'EC', ...]
// }
const euroUsers = getCurrenciesByCountryCode("FR"); // [ { currencyCode: 'EUR', ... } ]
const searchByName = findCurrenciesByName("pound"); // GBP and others
const usFlagUrl = getFlagUrlByCountryCode("US"); // file URL to flags/us.svg
const eurFlagPrimary = getFlagUrlByCurrencyCode("EUR"); // flags/eu.svg
const eurFlagAll = getFlagUrlsForCurrency("EUR"); // { primary: flags/eu.svg, others: [flags/fr.svg, ...] }
const all = getAllCurrencyEntries();Flag URLs are built using import.meta.url and point to files inside the package's flags/ folder. You can use them as src in <img> tags or import through bundlers.
Which flag is returned for a currency used by many countries?
getFlagUrlByCurrencyCode(code)returns the flag of theprimaryCountryCodewe designate for that currency (for example,EUR→EUflag,USD→USflag). This provides a deterministic single flag per currency.- To access all flags used by a currency, use
getFlagUrlsForCurrency(code)which returns both the primary flag and an array of flags for all other countries using that currency.
API
getCurrencyByCode(code)→ currency entry ornullgetCurrenciesByCountryCode(countryCode)→ array of currency entriesgetPrimaryCountryForCurrency(currencyCode)→ country code ornullgetOtherCountriesForCurrency(currencyCode)→ array of country codesgetAllCountriesUsingCurrency(currencyCode)→ array of all country codes (primary + others)getCountriesForCurrency(currencyCode)→{ primary, others, all }getCurrencyCodesByCountryCode(countryCode)→ array of currency codesgetCurrenciesByExactName(name)→ array of currency entries with exact name match (including aliases)findCurrenciesByName(query)→ array of currency entriesgetFlagUrlByCountryCode(countryCode)→ file URL string ornullgetFlagUrlByCurrencyCode(currencyCode)→ primary flag URL ornullgetFlagUrlsForCurrency(currencyCode)→{ primary, others }getCurrencyCodes()→ array of currency codesgetCountryCodes()→ array of country codes that appear in the datasetsearch(query)→ heuristic search across codes, names, and country codes
Notes
- Multiple countries can share a currency. The
primaryCountryCodeis a representative ISO 3166-1 alpha-2 (e.g.,EUforEUR). All other users appear inotherCountryCodes. - This package references flag SVGs from its own
flags/directory. No remote calls or inlined SVGs.
License
MIT
