/** * Currency configuration for a specific locale */ interface Currency { /** ISO 4217 currency code (e.g., 'COP', 'USD') */ code: string; /** Currency symbol (e.g., '$', 'R$') */ symbol: string; /** Number of decimal places (usually 2, but some currencies use 0) */ decimals: number; /** Thousands separator (e.g., '.' for CO, ',' for US) */ thousandsSeparator: string; /** Decimal separator (e.g., ',' for CO, '.' for US) */ decimalSeparator: string; /** Symbol position: 'before' or 'after' the amount */ symbolPosition: 'before' | 'after'; /** Space between symbol and amount */ symbolSpacing: boolean; } /** * Options for formatting money */ interface FormatOptions { /** Whether to show the currency symbol */ showSymbol?: boolean; /** Whether to show decimal places */ showDecimals?: boolean; /** Override the default symbol position */ symbolPosition?: 'before' | 'after'; } /** * Result of a money distribution operation */ type DistributionResult = Money[]; /** * Represents an immutable monetary value with safe integer arithmetic */ interface IMoney { /** The amount in the smallest unit (cents) */ readonly cents: number; /** The currency configuration */ readonly currency: Currency; /** Add another money value */ add(other: IMoney): IMoney; /** Subtract another money value */ subtract(other: IMoney): IMoney; /** Multiply by a factor */ multiply(factor: number): IMoney; /** Divide by a divisor */ divide(divisor: number): IMoney; /** Distribute evenly without losing cents */ distribute(parts: number): IMoney[]; /** Format for display */ format(options?: FormatOptions): string; /** Get the decimal amount */ toDecimal(): number; /** Check equality */ equals(other: IMoney): boolean; /** Check if greater than */ greaterThan(other: IMoney): boolean; /** Check if less than */ lessThan(other: IMoney): boolean; /** Check if zero */ isZero(): boolean; /** Check if positive */ isPositive(): boolean; /** Check if negative */ isNegative(): boolean; } /** * Immutable Money class that uses integer arithmetic for precision */ declare class Money implements IMoney { readonly cents: number; readonly currency: Currency; private constructor(); /** * Create money from cents (smallest unit) */ static fromCents(cents: number, currency: Currency): Money; /** * Create money from a decimal amount * @example Money.fromDecimal(100.50, USD) creates $100.50 */ static fromDecimal(amount: number, currency: Currency): Money; /** * Create zero money */ static zero(currency: Currency): Money; /** * Add another money value (must be same currency) */ add(other: IMoney): Money; /** * Subtract another money value (must be same currency) */ subtract(other: IMoney): Money; /** * Multiply by a factor (rounds to nearest cent) */ multiply(factor: number): Money; /** * Divide by a divisor (rounds to nearest cent) */ divide(divisor: number): Money; /** * Distribute money evenly without losing cents * The remainder is distributed to the first parts * @example $100 / 3 = [$33.34, $33.33, $33.33] */ distribute(parts: number): Money[]; /** * Distribute money according to ratios * @example $100 with ratios [1, 2, 2] = [$20, $40, $40] */ distributeByRatios(ratios: number[]): Money[]; /** * Format money for display */ format(options?: FormatOptions): string; /** * Get the decimal representation */ toDecimal(): number; /** * Check equality with another money value */ equals(other: IMoney): boolean; /** * Check if greater than another money value */ greaterThan(other: IMoney): boolean; /** * Check if less than another money value */ lessThan(other: IMoney): boolean; /** * Check if greater than or equal */ greaterThanOrEqual(other: IMoney): boolean; /** * Check if less than or equal */ lessThanOrEqual(other: IMoney): boolean; /** * Check if zero */ isZero(): boolean; /** * Check if positive */ isPositive(): boolean; /** * Check if negative */ isNegative(): boolean; /** * Get absolute value */ abs(): Money; /** * Negate the value */ negate(): Money; /** * Calculate a percentage of this money * @example money.percentage(10) returns 10% of the amount */ percentage(percent: number): Money; /** * Add a percentage to this money * @example money.addPercentage(19) adds 19% (like tax) */ addPercentage(percent: number): Money; /** * Subtract a percentage from this money * @example money.subtractPercentage(10) subtracts 10% (like discount) */ subtractPercentage(percent: number): Money; /** * Get the minimum of this and another money value */ min(other: IMoney): Money; /** * Get the maximum of this and another money value */ max(other: IMoney): Money; /** * Clamp this money between a minimum and maximum */ clamp(minValue: IMoney, maxValue: IMoney): Money; /** * Get cents (smallest unit) */ toCents(): number; /** * Check if within a range (inclusive) */ isBetween(min: IMoney, max: IMoney): boolean; /** * Sum multiple money values */ static sum(values: IMoney[]): Money; /** * Get the minimum from an array of money values */ static minimum(values: IMoney[]): Money; /** * Get the maximum from an array of money values */ static maximum(values: IMoney[]): Money; /** * Calculate the average of money values */ static average(values: IMoney[]): Money; /** * Convert to JSON-serializable object */ toJSON(): { cents: number; currency: string; }; /** * String representation */ toString(): string; private formatInteger; private assertSameCurrency; } export { type Currency, type DistributionResult, type FormatOptions, type IMoney, Money };