UNPKG

easy-currencies

Version:

A tool for easy conversion of currencies.

84 lines (83 loc) 2.59 kB
import { Provider, ProviderReference } from "./parts/providers"; import { Config, ProxyConfiguration } from "./parts/config"; export { Chainer as Convert } from "./parts/chainer"; /** * A simple map object for rates * * @export * @interface rateObject */ export interface rateObject { [currencyName: string]: number; } /** * Regular converter class definition. * * @export * @class Converter */ export declare class Converter { /** * Converter's main config object. * * @type {Config} * @memberof Converter */ config: Config; /** * Creates an instance of Converter. * @param {(...ProviderReference[] | undefined[] | string[])} config * @memberof Converter */ constructor(...config: ProviderReference[] | undefined[] | string[]); /** * Getters for active providers * * @readonly * @type {Provider[]} * @memberof Converter */ get providers(): Provider[]; get active(): Provider[]; add: Config["add"]; addProvider: Config["add"]; addMultiple: Config["addMultiple"]; addMultipleProviders: Config["addMultiple"]; remove: Config["remove"]; /** * Method to set the proxy configuration. * @param proxyConfiguration The proxy configuration. */ setProxyConfiguration: (proxyConfiguration: ProxyConfiguration) => void; /** * Conversion function (non chainable). * * @example * const converter = new Converter() * const converted = await converter.convert(15,"USD","EUR") * console.log(converted); * * @param {number} amount - amount to be converted * @param {string} from - base currency * @param {string} to - conversion currency * @param {any} rates - conversion rates, if they were pre-fetched * @returns {Promise<number>} - converted amount */ convert: (amount: number, from: string, to: string, rates?: any) => Promise<number>; /** * Performs safe multiplication to get the result amount. * @param {number} amount - amount to be converted * @param {string} to - conversion currency * @param {any} rates - conversion rates, if they were pre-fetched * @returns */ convertRate: (amount: number, to: string, rates?: any) => number; /** * Rate fetch function * @param {string} from - base currency * @param {string} to - conversion currency * @param {boolean} multiple - determines conversion mode * @returns */ getRates: (from: string, to: string, multiple?: boolean) => Promise<rateObject>; }