dinero.js
Version:
Create, calculate, and format money in JavaScript and TypeScript
177 lines (164 loc) • 6.6 kB
JavaScript
import { A as halfEven, C as compare, D as halfUp, E as up, F as createDinero, I as assert, L as INVALID_AMOUNT_MESSAGE, M as halfAwayFromZero, N as down, O as halfTowardsZero, P as DineroComparisonOperator, R as INVALID_SCALE_MESSAGE, S as convert, T as add, _ as haveSameAmount, a as toDecimal, b as greaterThan, c as multiply, d as lessThanOrEqual, f as lessThan, g as haveSameCurrency, h as isNegative, i as toSnapshot, j as halfDown, k as halfOdd, l as minimum, m as isPositive, n as transformScale, o as subtract, p as isZero, r as toUnits, s as normalizeScale, t as trimScale, u as maximum, v as hasSubUnits, w as allocate, x as equal, y as greaterThanOrEqual } from "./trimScale-C3-DjbPM.js";
import { AED, AFN, ALL, AMD, AOA, ARS, AUD, AWG, AZN, BAM, BBD, BDT, BGN, BHD, BIF, BMD, BND, BOB, BOV, BRL, BSD, BTN, BWP, BYN, BZD, CAD, CDF, CHE, CHF, CHW, CLF, CLP, CNY, COP, COU, CRC, CUP, CVE, CZK, DJF, DKK, DOP, DZD, EGP, ERN, ETB, EUR, FJD, FKP, GBP, GEL, GHS, GIP, GMD, GNF, GTQ, GYD, HKD, HNL, HTG, HUF, IDR, ILS, INR, IQD, IRR, ISK, JMD, JOD, JPY, KES, KGS, KHR, KMF, KPW, KRW, KWD, KYD, KZT, LAK, LBP, LKR, LRD, LSL, LYD, MAD, MDL, MGA, MKD, MMK, MNT, MOP, MRU, MUR, MVR, MWK, MXN, MXV, MYR, MZN, NAD, NGN, NIO, NOK, NPR, NZD, OMR, PAB, PEN, PGK, PHP, PKR, PLN, PYG, QAR, RON, RSD, RUB, RWF, SAR, SBD, SCR, SDG, SEK, SGD, SHP, SLE, SOS, SRD, SSP, STN, SVC, SYP, SZL, THB, TJS, TMT, TND, TOP, TRY, TTD, TWD, TZS, UAH, UGX, USD, USN, UYI, UYU, UYW, UZS, VED, VES, VND, VUV, WST, XAD, XAF, XCD, XCG, XOF, XPF, YER, ZAR, ZMW, ZWG } from "./currencies/index.js";
//#region src/calculator/number/api/add.ts
/**
* Returns the sum of two numbers.
*
* @param augend - The number to add to.
* @param addend - The number to add.
*
* @returns The sum of the two numbers.
*/
const add$1 = (augend, addend) => {
return augend + addend;
};
//#endregion
//#region src/calculator/number/api/compare.ts
/**
* Compare two numbers.
*
* @param a - The first number to compare.
* @param b - The second number to compare.
*
* @returns Whether the two numbers are equal, or whether the first one is greater or less than the other.
*/
const compare$1 = (a, b) => {
if (a < b) return DineroComparisonOperator.LT;
if (a > b) return DineroComparisonOperator.GT;
return DineroComparisonOperator.EQ;
};
//#endregion
//#region src/calculator/number/api/decrement.ts
/**
* Returns an decremented number.
*
* @param value - The number to decrement.
*
* @returns The decremented number.
*/
const decrement = (value) => {
return value - 1;
};
//#endregion
//#region src/calculator/number/api/increment.ts
/**
* Returns an incremented number.
*
* @param value - The number to increment.
*
* @returns The incremented number.
*/
const increment = (value) => {
return value + 1;
};
//#endregion
//#region src/calculator/number/api/integerDivide.ts
/**
* Returns the quotient of two numbers with no fractional part.
*
* @param dividend - The number to divide.
* @param divisor - The number to divide with.
*
* @returns The quotient of the two numbers.
*/
const integerDivide = (dividend, divisor) => {
return Math.trunc(dividend / divisor);
};
//#endregion
//#region src/calculator/number/api/modulo.ts
/**
* Returns the remainder of two numbers.
*
* @param dividend - The number to divide.
* @param divisor - The number to divide with.
*
* @returns The remainder of the two numbers.
*/
const modulo = (dividend, divisor) => {
return dividend % divisor;
};
//#endregion
//#region src/calculator/number/api/multiply.ts
/**
* Returns the product of two numbers.
*
* @param multiplicand - The number to multiply.
* @param multiplier - The number to multiply with.
*
* @returns The product of the two numbers.
*/
const multiply$1 = (multiplicand, multiplier) => {
return multiplicand * multiplier;
};
//#endregion
//#region src/calculator/number/api/power.ts
/**
* Returns an number to the power of an exponent.
*
* @param base - The base number.
* @param exponent - The exponent to raise the base to.
*
* @returns The base to the power of the exponent.
*/
const power = (base, exponent) => {
return base ** exponent;
};
//#endregion
//#region src/calculator/number/api/subtract.ts
/**
* Returns the difference between two numbers.
*
* @param minuend - The number to subtract from.
* @param subtrahend - The number to subtract.
*
* @returns The difference of the two numbers.
*/
const subtract$1 = (minuend, subtrahend) => {
return minuend - subtrahend;
};
//#endregion
//#region src/calculator/number/api/zero.ts
/**
* Return zero as a number.
*
* @returns Zero as a number.
*/
function zero() {
return 0;
}
//#endregion
//#region src/calculator/number/calculator.ts
const calculator = {
add: add$1,
compare: compare$1,
decrement,
increment,
integerDivide,
modulo,
multiply: multiply$1,
power,
subtract: subtract$1,
zero
};
//#endregion
//#region src/dinero.ts
/**
* Create a Dinero object.
*
* @param options.amount - The amount in minor currency units.
* @param options.currency - The currency.
* @param options.scale - The number of decimal places to represent.
*
* @returns The created Dinero object.
*
* @public
*/
const dinero = createDinero({
calculator,
onCreate({ amount, scale }) {
assert(Number.isInteger(amount), INVALID_AMOUNT_MESSAGE);
assert(Number.isInteger(scale), INVALID_SCALE_MESSAGE);
}
});
//#endregion
export { AED, AFN, ALL, AMD, AOA, ARS, AUD, AWG, AZN, BAM, BBD, BDT, BGN, BHD, BIF, BMD, BND, BOB, BOV, BRL, BSD, BTN, BWP, BYN, BZD, CAD, CDF, CHE, CHF, CHW, CLF, CLP, CNY, COP, COU, CRC, CUP, CVE, CZK, DJF, DKK, DOP, DZD, DineroComparisonOperator, EGP, ERN, ETB, EUR, FJD, FKP, GBP, GEL, GHS, GIP, GMD, GNF, GTQ, GYD, HKD, HNL, HTG, HUF, IDR, ILS, INR, IQD, IRR, ISK, JMD, JOD, JPY, KES, KGS, KHR, KMF, KPW, KRW, KWD, KYD, KZT, LAK, LBP, LKR, LRD, LSL, LYD, MAD, MDL, MGA, MKD, MMK, MNT, MOP, MRU, MUR, MVR, MWK, MXN, MXV, MYR, MZN, NAD, NGN, NIO, NOK, NPR, NZD, OMR, PAB, PEN, PGK, PHP, PKR, PLN, PYG, QAR, RON, RSD, RUB, RWF, SAR, SBD, SCR, SDG, SEK, SGD, SHP, SLE, SOS, SRD, SSP, STN, SVC, SYP, SZL, THB, TJS, TMT, TND, TOP, TRY, TTD, TWD, TZS, UAH, UGX, USD, USN, UYI, UYU, UYW, UZS, VED, VES, VND, VUV, WST, XAD, XAF, XCD, XCG, XOF, XPF, YER, ZAR, ZMW, ZWG, add, allocate, compare, convert, createDinero, dinero, down, equal, greaterThan, greaterThanOrEqual, halfAwayFromZero, halfDown, halfEven, halfOdd, halfTowardsZero, halfUp, hasSubUnits, haveSameAmount, haveSameCurrency, isNegative, isPositive, isZero, lessThan, lessThanOrEqual, maximum, minimum, multiply, normalizeScale, subtract, toDecimal, toSnapshot, toUnits, transformScale, trimScale, up };