Currency Codes TS
A TypeScript library for ISO 4217 currency codes. Efficiently lookup and validate currency codes, retrieve associated countries, and more.
This library is inspired by and originally forked from currency-codes. This version adds TypeScript support and will be periodically updated with the latest currency data.
Installation
npm install currency-codes-ts
Examples
Here's how you can use the library:
Code lookup
import { codes } from 'currency-codes-ts';
const euroInfo: CurrencyCodeRecord = codes('EUR');
console.log(euroInfo);
Number Lookup
import { number } from 'currency-codes-ts';
console.log(number(967));
Country Lookup
import { country } from 'currency-codes-ts';
console.log(country('Columbia'));
Get all Currency Codes
import { codes } from 'currency-codes-ts';
console.log(codes());
Get all Currency Numbers
import { numbers } from 'currency-codes-ts';
console.log(numbers());
Get all Countries
import { countries } from 'currency-codes-ts';
console.log(countries());
Get all currency records
import { data } from 'currency-codes-ts';
console.log(data);
Functions
code(code: string)
: Returns a CurrencyCodeRecord
object based on ISO 4217 currency code. Returns undefined
if not found.country(country: string)
: Returns an array of CurrencyCodeRecord
objects used in the given country.number(number: number | string)
: Returns a CurrencyCodeRecord
object based on ISO 4217 currency number. Returns undefined
if not found.codes()
: Returns an array of ISO 4217 currency codes.numbers()
: Returns an array of ISO 4217 currency numbers.countries()
: Returns an array of country names.
Properties
data
: Returns a CurrencyCodeRecord[]
array containing all the available currency records.publishDate
: Returns the ISO formatted date the currencies were last updated.
Types
CurrencyCodeRecord
: Defines the object returned on currency lookup. Includes properties like currency
, code
, countries
, and digits
.
interface CurrencyCodeRecord {
code: CurrencyCode;
number: string;
digits: number;
currency: string;
countries: Country[];
}
CurrencyCode
: The three-letter ISO 4217 code representing a currency (e.g., USD, EUR).
type CurrencyCode = "AED" | "AFN" | "ALL" | "AMD" | "[...]" | "ZMW" | "ZWL";
Country
: A string representing the name of a country.
type Country = "United Arab Emirates (The)" | "Afghanistan" | "Albania" | "Armenia" | "[...]" | "Zambia" | "Zimbabwe";
Contributing
You can update the package with the latest currency data by running
npm run iso
This will update the data.ts
and types.ts
file based on the ingested data.
To build simply run tsc
. This will create a build in the dist/
folder.
For contributions feel free to raise issues and pull requests.
License
MIT