Installation

npm install @easymoney/currencies

or

yarn add @easymoney/currencies

or

CDN

Description

The createCurrencyList function provides a way for a developer to create a custom currency repository. The class accepts an array of currency code and minor unit pairs. In case of an invalid array an exception is thrown.

Unit definitions

CurrencyList

interface CurrencyList {
contains: (currency: Currency) => boolean;
getCurrencies(): CurrencyMap;
subUnitFor(currency: Currency): number;
}

CurrencyMap

type CurrencyMap<C> = {
[code: string]: C;
};

Currency

type Currency = string | AnyCurrencyUnit;

AnyCurrencyUnit

interface AnyCurrencyUnit extends CurrencyUnit {
[key: string]: any;
}

CurrencyUnit

interface CurrencyUnit {
code: string;
minorUnit: number;
}