dyna-currencies
is a currency converter.
Currently it doesn't fetch currency rates from any service. You have to provide the currency rates.
Written in Typescript, runs everywhere.
import {DynaCurrencies} from 'dyna-currencies';
const dynaCurrencies = new DynaCurrencies();
dynaCurrencies.updateRates({"usd": 1, "eur": 0.85});
let usdPrice = dynaCurrencies.convert(2.45, 'eur', 'usd', true);
console.log(usdPrice); // 2.88
Update the partially. You can pass so many rates you want (not all of them).
When no rates are updated, the many convert functions return null.
Clears all rates (added/updated with update
).
convert(value: number, fromCurrency: string, toCurrency: string, round: boolean = false): number | null
Set round
to true to round the currency according to the decimals of the target currency.
Converts the currency, and the output instead of a number is the IDynaLabelCurrency interface where is friendly for the Yahoo Intl.
It converts a DynaPrice object.
Get all currencies as a dictionary.
Get all currencies to array for drop-down controls, etc..
Get all currencies that a country can hold.
Get the main currency for a country.
Return null when no rates are loaded or when it countryCode is wrong.
It returns the number of all updated rates.
It returns all the updated rates.
When updated last time
interface ICurrencyRates { [currencyName: string]: number | undefined; }
interface ICurrencies { [currencyName: string]: ICurrency; }
interface ICurrency { code: string; symbol: string; name: string; namePlural: string; symbolNative: string; decimalDigits: number; rounding: number; }
interface ICountries { [currencyName: string]: ICountry | undefined; }
interface ICountry { name: string; native: string; phone: string; continent: string; capital: string; currency: string; languages: string[]; }
interface IDynaLabelCurrency extends IDynaLabel { values: { value: number; decimals: number; currencyName: string; currencyNamePlural: string; currencyCode: string; currencySymbol: string; currencySymbolNative: string; } }
interface IDynaLabel { // object used for ui labels, where the content of it is used also for translations text?: string; // the text will be applied if the tk not found (as default text) tk?: string; // the translation key values?: { // values are used inside the translated text (obtained by the tk) [key: string]: string | number; }; }