UNPKG

@barchart/common-js

Version:
126 lines (125 loc) 3.62 kB
/** * A component that represents an exchange rate, composed of a {@link Decimal} * value and two currencies -- a quote (i.e. the numerator) currency and a * base (i.e. denominator) currency. * * @public */ export default class Rate { /** * Creates a {@link Rate} instance, when given a value * * @public * @static * @param {number|string|Decimal} value - The rate. * @param {string} symbol - A string that can be parsed as a currency pair. * @returns {Rate} */ public static fromPair(value: number | string | Decimal, symbol: string): Rate; /** * Given a {@link Decimal} value in a known currency, output * a {@link Decimal} converted to an alternate currency. * * @public * @static * @param {Decimal} amount - The amount to convert. * @param {Currency} currency - The currency of the amount. * @param {Currency} desiredCurrency - The currency to convert to. * @param {...Rate} rates - A list of exchange rates to be used for the conversion. * @returns {Decimal} */ public static convert(amount: Decimal, currency: Currency, desiredCurrency: Currency, ...rates: Rate[]): Decimal; /** * Returns a list of rates which do no change. * * @public * @static * @returns {Rate[]} */ public static getStaticRates(): Rate[]; /** * @param {number|string|Decimal} value - The rate * @param {Currency} numerator - The quote currency * @param {Currency} denominator - The base currency */ constructor(value: number | string | Decimal, numerator: Currency, denominator: Currency); /** * The rate (as a {@link Decimal}) instance. * * @public * @returns {Decimal} */ public get decimal(): Decimal; /** * The rate (as a floating point number). * * @public * @returns {number} */ public get float(): number; /** * The numerator (i.e. quote) currency. In other words, * this is EUR of the EURUSD pair. * * @public * @returns {Currency} */ public get numerator(): Currency; /** * The quote (i.e. numerator) currency. In other words, * this is EUR of the EURUSD pair. * * @public * @returns {Currency} */ public get quote(): Currency; /** * The denominator (i.e. base) currency. In other words, * this is USD of the EURUSD pair. * * @public * @returns {Currency} */ public get denominator(): Currency; /** * The base (i.e. denominator) currency. In other words, * this is USD of the EURUSD pair. * * @public * @returns {Currency} */ public get base(): Currency; /** * Returns the equivalent rate with the numerator and denominator (i.e. the quote and base) * currencies. * * @public * @returns {Rate} */ public invert(): Rate; /** * Formats the currency pair as a string (e.g. "EURUSD" or "^EURUSD"). * * @public * @param {boolean=} useCarat - If true, a carat is used as a prefix to the resulting string. * @returns {string} */ public formatPair(useCarat?: boolean | undefined): string; /** * Returns the Barchart symbol for the exchange rate. * * @public * @return {string} */ public getSymbol(): string; /** * Returns a string representation. * * @public * @returns {string} */ public toString(): string; #private; } import Decimal from './Decimal.js'; import Currency from './Currency.js';