import BigNumber from 'bignumber.js'; import Currency, { CurrencyInputSettings } from '../Currency'; /** * @example * Basic usage * ```js * import { Money } from 'wealth' * let price = new Money('7856', 'USD'); // $78.56 * ``` */ export declare class Money { /** * Internal currency */ currency: Currency; /** * Internal value as a big number */ value: BigNumber; /** * BigNumber constructor used by this "Money" instance */ bigNumberConstructor: typeof BigNumber; /** * @example * Integer as value * ```js * let price = new Money(7856, 'USD'); // $78.56 * ``` * * @example * String integer as value * ```js * let price = new Money('7856', 'USD'); // $78.56 * ``` * * @example * String Float as value * ```js * let price = new Money('78.56', 'USD'); // $78.56 * ``` * * @example * Money instance as value * ```js * let price = new Money(new Money('78.56', 'USD'), 'USD'); // $78.56 - same as using clone() * ``` * * @example * Currency instance as currency * ```js * let price = new Money('7856', new Currency('USD')); // $78.56 * ``` * * @param value - integer, integer string, float string, instance of `Money` * @param currency - currency code as string, currency settings or instance of `Currency` */ constructor(value: number | string | Money, currency: string | CurrencyInputSettings | Currency); /** * Checks if the current currency is the same as that of the parameter * @param value - value to check currency against the current value * @returns - true if the current value has the same currency as the parameter */ hasSameCurrency(value: Money): Boolean; /** * Create a new money instance, holding an identical value and currency to the current one * @returns - the cloned money instance */ clone(): Money; /** * Get the current value as an instance of BigNumber * @returns - Internal BigNumber representation of the current value */ readonly amountAsBigNumber: BigNumber; /** * Get the current value as a string integer * @returns - String integer representation of the current value */ readonly amountAsStringInteger: string; /** * Get the current value as a string float * @returns - String float representation of the current value */ readonly amountAsStringFloat: string; /** * Get the current value as a string float (same as `amountAsStringFloat`) * @returns - String float representation of the current value */ readonly amount: string; /** * Get the current value as a string float (same as `amount`) * @returns - String float representation of the current value */ toString(): string; /** * Get the smallest unit of the current monetary value, i.e., 0.01 (aka penny) in a USD money * @returns - new Money instance holding the smallest unit of the current monetary value */ readonly smallestUnit: Money; /** * Get a simple object representing the current monetary value * @returns - object with a string integer value and currency code */ toJSON(): { amount: string; currency: string; }; /** * Check that the currency of the passed value matches the current currency. * If not, throw an error. * @param value - The money object which is used for currency check */ private checkValueCurrency; /** * Convert the constructor input value to an internal BigNumber instance * @param value - integer, integer string, float string, instance of `Money` * @param BN - BigNumber constructor used by this "Money" instance * @returns - Internal BigNumber instance */ private preProcessInputValue; /** * Generate a compatible BigNumber constructor * @returns - a new BigNumber constructor */ private generateBigNumberConstructor; /** * Creates a new instance of Money * @param value - integer, integer string, float string, instance of `Money` * @param currency - currency code as string, currency settings or instance of `Currency` */ static init(value: number | string | Money, currency: string | CurrencyInputSettings | Currency): Money; } export default Money;