UNPKG

typescript-libraries

Version:
152 lines (151 loc) 4.27 kB
import { TSCurrencies, TSCurrency } from './TSCurrencies'; declare class TSMoney { amount: number; currency: string; /** * Creates a new TSMoney instance. The created TSMoney instances is a value object thus it is immutable. * * @param {Number} amount * @param {Object/String} currency * @returns {TSMoney} * @constructor */ constructor(amount: number, currency: any | string); static fromInteger(amount: number | any, currency?: string): TSMoney; static fromDecimal(amount: number | any, currency?: string | any, rounder?: string | Function): TSMoney; /** * Returns true if the two instances of TSMoney are equal, false otherwise. * * @param {TSMoney} other * @returns {Boolean} */ equals(other: TSMoney): boolean; /** * Adds the two objects together creating a new TSMoney instance that holds the result of the operation. * * @param {TSMoney} other * @returns {TSMoney} */ add(other: TSMoney): TSMoney; /** * Subtracts the two objects creating a new TSMoney instance that holds the result of the operation. * * @param {TSMoney} other * @returns {TSMoney} */ subtract(other: TSMoney): TSMoney; /** * Multiplies the object by the multiplier returning a new TSMoney instance that holds the result of the operation. * * @param {Number} multiplier * @param {Function} [fn=Math.round] * @returns {TSMoney} */ multiply(multiplier: number, fn?: Function): TSMoney; /** * Divides the object by the multiplier returning a new TSMoney instance that holds the result of the operation. * * @param {Number} divisor * @param {Function} [fn=Math.round] * @returns {TSMoney} */ divide(divisor: number, fn?: Function): TSMoney; /** * Allocates fund bases on the ratios provided returing an array of objects as a product of the allocation. * * @param {Array} other * @returns {Array.TSMoney} */ allocate(ratios: number[]): TSMoney[]; /** * Compares two instances of TSMoney. * * @param {TSMoney} other * @returns {Number} */ compare(other: TSMoney): number; /** * Checks whether the value represented by this object is greater than the other. * * @param {TSMoney} other * @returns {boolean} */ greaterThan(other: TSMoney): boolean; /** * Checks whether the value represented by this object is greater or equal to the other. * * @param {TSMoney} other * @returns {boolean} */ greaterThanOrEqual(other: TSMoney): boolean; /** * Checks whether the value represented by this object is less than the other. * * @param {TSMoney} other * @returns {boolean} */ lessThan(other: TSMoney): boolean; /** * Checks whether the value represented by this object is less than or equal to the other. * * @param {TSMoney} other * @returns {boolean} */ lessThanOrEqual(other: TSMoney): boolean; /** * Returns true if the amount is zero. * * @returns {boolean} */ isZero(): boolean; /** * Returns true if the amount is positive. * * @returns {boolean} */ isPositive(): boolean; /** * Returns true if the amount is negative. * * @returns {boolean} */ isNegative(): boolean; /** * Returns the decimal value as a float. * * @returns {number} */ toDecimal(): number; /** * Returns the decimal value as a string. * * @returns {string} */ toString(): string; /** * Returns a serialised version of the instance. * * @returns {{amount: number, currency: string}} */ toJSON(): { amount: number; currency: string; }; /** * Returns the amount represented by this object. * * @returns {number} */ getAmount(): number; /** * Returns the currency represented by this object. * * @returns {string} */ getCurrency(): string; /** * Returns the full currency object */ getCurrencyInfo(): TSCurrency; } export { TSMoney, TSCurrencies };