@amboras-dev/money 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -8
- package/dist/ai.cjs +12 -13
- package/dist/ai.d.cts +5 -9
- package/dist/ai.d.ts +5 -9
- package/dist/ai.js +12 -13
- package/dist/{allocate-CZRg4TOP.cjs → allocate-AusholrC.cjs} +3 -4
- package/dist/{allocate-X7_jAtOj.js → allocate-BBRfdaSC.js} +3 -4
- package/dist/{amount-BV0O-aN8.cjs → amount-CwFzcxUl.cjs} +29 -12
- package/dist/{amount-BoYBMgK9.js → amount-DHFOK2Yd.js} +29 -12
- package/dist/{arithmetic-BhNwisjb.js → arithmetic-C97-YafD.js} +4 -5
- package/dist/{arithmetic-DjT4Kzgt.cjs → arithmetic-D8A6IeZ0.cjs} +4 -5
- package/dist/billing.cjs +5 -8
- package/dist/billing.d.cts +1 -9
- package/dist/billing.d.ts +1 -9
- package/dist/billing.js +5 -8
- package/dist/commerce.cjs +15 -23
- package/dist/commerce.d.cts +2 -16
- package/dist/commerce.d.ts +2 -16
- package/dist/commerce.js +15 -23
- package/dist/{format-DLhno7eX.cjs → format-92fzvTXY.cjs} +9 -9
- package/dist/{format-BdPnijvn.js → format-BJC513u4.js} +9 -9
- package/dist/fx.cjs +12 -18
- package/dist/fx.d.cts +5 -15
- package/dist/fx.d.ts +5 -15
- package/dist/fx.js +12 -18
- package/dist/index.cjs +10 -12
- package/dist/index.d.cts +17 -23
- package/dist/index.d.ts +17 -23
- package/dist/index.js +10 -12
- package/dist/input.cjs +7 -10
- package/dist/input.d.cts +9 -16
- package/dist/input.d.ts +9 -16
- package/dist/input.js +7 -10
- package/dist/{iso-minor-wSwJN57T.cjs → iso-minor-DyNjT9A1.cjs} +2 -3
- package/dist/{iso-minor-CqkWDxHS.js → iso-minor-odkY-e6I.js} +2 -3
- package/dist/{medusa-lRY9xlsf.cjs → medusa-CzVK0bth.cjs} +3 -4
- package/dist/{medusa-DBXJXXvF.d.ts → medusa-DofdvIgQ.d.cts} +1 -3
- package/dist/{medusa-4K8N1pUc.d.cts → medusa-DrbYmD2Y.d.ts} +1 -3
- package/dist/{medusa-DqJY1qpj.js → medusa-pKGlImn9.js} +3 -4
- package/dist/{money-B-3aFjNJ.d.cts → money-BkMeYDEW.d.cts} +0 -6
- package/dist/{money-B-3aFjNJ.d.ts → money-BkMeYDEW.d.ts} +0 -6
- package/dist/{money-WhnGiI00.js → money-BxbAw7BP.js} +7 -15
- package/dist/{money-B3wH_Z4S.cjs → money-DWBjuuEK.cjs} +7 -15
- package/dist/{number-text-DE-q4jO5.js → number-text-Bj-gZXiF.js} +3 -4
- package/dist/{number-text-BWu67jUq.cjs → number-text-CWuVwrlg.cjs} +3 -4
- package/dist/{own-oP9DXFWv.cjs → own-C5imDkyB.cjs} +1 -2
- package/dist/{own-D7544D3k.js → own-DHxqIYqL.js} +1 -2
- package/dist/{percent-D1VB9xXG.js → percent-CB3Ixjc_.js} +2 -3
- package/dist/{percent-C0InC2t2.cjs → percent-DABHiSBs.cjs} +2 -3
- package/dist/{rate-DBPiYgT1.d.ts → rate-BvvZUdSu.d.ts} +1 -3
- package/dist/{rate-tqK8ijG0.d.cts → rate-CEakW3ia.d.cts} +1 -3
- package/dist/{rate-CVeMii4a.cjs → rate-CEjWTATc.cjs} +3 -4
- package/dist/{rate-DicStBue.js → rate-D6S2_wgZ.js} +3 -4
- package/dist/{reporting-tpGJbqYp.d.ts → reporting-DFNyDBdi.d.cts} +2 -4
- package/dist/{reporting-CG-ai2sM.d.cts → reporting-jIBILvnr.d.ts} +2 -4
- package/dist/{retail-DRUTTQoJ.d.ts → retail-B04CjW3b.d.ts} +1 -3
- package/dist/{retail-Cml8YSKg.cjs → retail-CYGPU4ea.cjs} +4 -5
- package/dist/{retail-C_BPLvMj.d.cts → retail-CmEyJQOH.d.cts} +1 -3
- package/dist/{retail-1mu888J1.js → retail-DXgs11ov.js} +4 -5
- package/dist/{rounding-DHBtNCHG.cjs → rounding-4QKTRbMQ.cjs} +2 -3
- package/dist/{rounding-g9rvye0k.js → rounding-CA1PVP3b.js} +2 -3
- package/dist/sql.cjs +9 -15
- package/dist/sql.d.cts +2 -12
- package/dist/sql.d.ts +2 -12
- package/dist/sql.js +9 -15
- package/dist/testing.cjs +39198 -12
- package/dist/testing.d.cts +20 -13
- package/dist/testing.d.ts +20 -13
- package/dist/testing.js +39198 -13
- package/dist/{wire-sW0yzqth.js → wire-B4QU8O3W.js} +350 -93
- package/dist/{wire-CaUN9Vf_.d.ts → wire-CVNicirK.d.ts} +165 -46
- package/dist/{wire-xjYXv4go.d.cts → wire-CtNJmWVP.d.cts} +165 -46
- package/dist/{wire-Bhuut8cW.cjs → wire-u2tmHY0Y.cjs} +403 -92
- package/dist/wire.cjs +10 -1
- package/dist/wire.d.cts +2 -2
- package/dist/wire.d.ts +2 -2
- package/dist/wire.js +1 -2
- package/package.json +4 -3
package/dist/fx.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { R as DecimalText, i as Money, z as RoundingMode } from "./money-
|
|
2
|
-
import { n as priceRoundingParams, r as roundRetail, t as RetailRounding } from "./retail-
|
|
3
|
-
import { a as RateRow, c as rate, d as rateFromRow, f as rateToDecimal, i as RateFromDecimalOptions, l as rateEquals, n as RATE_REF, o as crossRate, p as rateToNumber, r as Rate, s as invertRate, t as RATE_BOUNDS, u as rateFromDecimal } from "./rate-
|
|
4
|
-
import { i as toReporting, n as ReportingTotal, r as storeFactors, t as FactorTable } from "./reporting-
|
|
5
|
-
import { n as MoneyByCurrency } from "./medusa-
|
|
6
|
-
//#region src/fx/convert.d.ts
|
|
1
|
+
import { R as DecimalText, i as Money, z as RoundingMode } from "./money-BkMeYDEW.js";
|
|
2
|
+
import { n as priceRoundingParams, r as roundRetail, t as RetailRounding } from "./retail-B04CjW3b.js";
|
|
3
|
+
import { a as RateRow, c as rate, d as rateFromRow, f as rateToDecimal, i as RateFromDecimalOptions, l as rateEquals, n as RATE_REF, o as crossRate, p as rateToNumber, r as Rate, s as invertRate, t as RATE_BOUNDS, u as rateFromDecimal } from "./rate-BvvZUdSu.js";
|
|
4
|
+
import { i as toReporting, n as ReportingTotal, r as storeFactors, t as FactorTable } from "./reporting-jIBILvnr.js";
|
|
5
|
+
import { n as MoneyByCurrency } from "./medusa-DrbYmD2Y.js";
|
|
7
6
|
/**
|
|
8
7
|
* The factor taking a stored `from` amount to a stored `to` amount for the major rate `r`
|
|
9
8
|
* (1 from = r to): `{ r.n x storageScale(to), r.d x storageScale(from) }`. Replaces Medusa
|
|
@@ -31,8 +30,6 @@ export declare function convert(m: Money, to: string, r: Rate, options?: Convert
|
|
|
31
30
|
* 150000 against USD 1000 gives 150). Both must be positive, else `rate_invalid`.
|
|
32
31
|
*/
|
|
33
32
|
export declare function impliedRate(a: Money, b: Money): Rate;
|
|
34
|
-
//#endregion
|
|
35
|
-
//#region src/fx/format-rate.d.ts
|
|
36
33
|
/**
|
|
37
34
|
* `'1 USD = 83.42 INR'`. `decimals: 'auto'` (default) shows 4 significant digits with at
|
|
38
35
|
* least 2 and at most 8 fraction digits; a number fixes them. Rounded half-up exactly, then
|
|
@@ -42,8 +39,6 @@ export declare function formatRate(r: Rate, from: string, to: string, options?:
|
|
|
42
39
|
decimals?: 'auto' | number;
|
|
43
40
|
locale?: string;
|
|
44
41
|
}): string;
|
|
45
|
-
//#endregion
|
|
46
|
-
//#region src/fx/plausibility.d.ts
|
|
47
42
|
/** Medusa PRICE_SEED_RATE_MAX_DEVIATION's default. */
|
|
48
43
|
export declare const DEFAULT_RATE_MAX_DEVIATION = 2;
|
|
49
44
|
/** chooseFactor's tolerance between the conventional factor and the observed median. */
|
|
@@ -106,8 +101,6 @@ export declare function rateConsensus(rates: readonly Rate[], options?: {
|
|
|
106
101
|
median: Rate | null;
|
|
107
102
|
accepted: boolean[];
|
|
108
103
|
};
|
|
109
|
-
//#endregion
|
|
110
|
-
//#region src/fx/settings.d.ts
|
|
111
104
|
export declare const RATE_MODES: readonly ["manual", "dynamic"];
|
|
112
105
|
export declare const PRICE_ROUNDINGS: readonly ["none", "nearest"];
|
|
113
106
|
/** `store_currency_rate.rate_mode` as readers coerce it: `'manual'` exactly, else `'dynamic'`. */
|
|
@@ -137,8 +130,6 @@ export declare function resolveMoneyByCurrency(setting: MoneyByCurrency, currenc
|
|
|
137
130
|
money: Money;
|
|
138
131
|
source: 'listed' | 'fallback';
|
|
139
132
|
} | null;
|
|
140
|
-
//#endregion
|
|
141
|
-
//#region src/fx/tables.d.ts
|
|
142
133
|
/** 1 USD = rate units of the currency, exact (see data/pegs.ts for the sources). Upper-case keys. */
|
|
143
134
|
export declare const USD_PEGS: Readonly<Record<string, Rate>>;
|
|
144
135
|
/** A feed's rate table with lower-case keys and only finite positive numbers kept (Medusa `lowerKeys`). Never throws. */
|
|
@@ -153,5 +144,4 @@ export declare function mergeRateTables(primary: Readonly<Record<string, number>
|
|
|
153
144
|
* gives 1/1; anything else null.
|
|
154
145
|
*/
|
|
155
146
|
export declare function pegFallback(from: string, to: string, ratesPerUsd: Readonly<Record<string, number>>, pegs?: Readonly<Record<string, Rate>>): Rate | null;
|
|
156
|
-
//#endregion
|
|
157
147
|
export { type ConvertOptions, type FactorTable, type MoneyByCurrencyFallback, RATE_BOUNDS, RATE_REF, type Rate, type RateClassification, type RateFromDecimalOptions, type RateReference, type RateRow, type ReportingTotal, type RetailRounding, crossRate, invertRate, priceRoundingParams, rate, rateEquals, rateFromDecimal, rateFromRow, rateToDecimal, rateToNumber, roundRetail, storeFactors, toReporting };
|
package/dist/fx.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { $ as describeValue, B as decimalOf, E as resolveCurrency, J as compareRatio, M as resolveLocale, Q as MoneyError, X as mulDiv, Y as gcd, Z as ratioToDecimal, it as formatDecimal, j as numberFormat, n as fromMajor, nt as decimalFromNumber, pt as toDecimalText, s as storedDecimal, t as boundedMoney, ut as pow10, y as findCurrency } from "./money-
|
|
2
|
-
import { t as mulDivToUnit } from "./rounding-
|
|
3
|
-
import { t as hasOwnKey } from "./own-
|
|
4
|
-
import { r as moneyFor } from "./medusa-
|
|
5
|
-
import { a as invertRate, c as rateFromDecimal, d as rateToNumber, i as crossRate, l as rateFromRow, n as RATE_REF, o as rate, r as checkRate, s as rateEquals, t as RATE_BOUNDS, u as rateToDecimal } from "./rate-
|
|
6
|
-
import { n as retailUnits, r as roundRetail, t as priceRoundingParams } from "./retail-
|
|
7
|
-
|
|
1
|
+
import { $ as describeValue, B as decimalOf, E as resolveCurrency, J as compareRatio, M as resolveLocale, Q as MoneyError, X as mulDiv, Y as gcd, Z as ratioToDecimal, it as formatDecimal, j as numberFormat, n as fromMajor, nt as decimalFromNumber, pt as toDecimalText, s as storedDecimal, t as boundedMoney, ut as pow10, y as findCurrency } from "./money-BxbAw7BP.js";
|
|
2
|
+
import { t as mulDivToUnit } from "./rounding-CA1PVP3b.js";
|
|
3
|
+
import { t as hasOwnKey } from "./own-DHxqIYqL.js";
|
|
4
|
+
import { r as moneyFor } from "./medusa-pKGlImn9.js";
|
|
5
|
+
import { a as invertRate, c as rateFromDecimal, d as rateToNumber, i as crossRate, l as rateFromRow, n as RATE_REF, o as rate, r as checkRate, s as rateEquals, t as RATE_BOUNDS, u as rateToDecimal } from "./rate-D6S2_wgZ.js";
|
|
6
|
+
import { n as retailUnits, r as roundRetail, t as priceRoundingParams } from "./retail-DXgs11ov.js";
|
|
7
|
+
// src/fx/convert.ts
|
|
8
8
|
const infoOf = (code) => resolveCurrency(code, { allowHistoric: true });
|
|
9
9
|
/**
|
|
10
10
|
* The factor taking a stored `from` amount to a stored `to` amount for the major rate `r`
|
|
@@ -46,8 +46,7 @@ function impliedRate(a, b) {
|
|
|
46
46
|
denominator: denominator / divisor
|
|
47
47
|
};
|
|
48
48
|
}
|
|
49
|
-
|
|
50
|
-
//#region src/fx/format-rate.ts
|
|
49
|
+
// src/fx/format-rate.ts
|
|
51
50
|
/** `floor(log10(n / d))` of a positive ratio, exactly. */
|
|
52
51
|
function exponentOf(n, d) {
|
|
53
52
|
let e = n.toString().length - d.toString().length;
|
|
@@ -76,8 +75,7 @@ function formatRate(r, from, to, options = {}) {
|
|
|
76
75
|
maximumFractionDigits: digits
|
|
77
76
|
}).format(asIntlValue(formatDecimal(value)))} ${toCode}`;
|
|
78
77
|
}
|
|
79
|
-
|
|
80
|
-
//#region src/fx/plausibility.ts
|
|
78
|
+
// src/fx/plausibility.ts
|
|
81
79
|
/** Medusa PRICE_SEED_RATE_MAX_DEVIATION's default. */
|
|
82
80
|
const DEFAULT_RATE_MAX_DEVIATION = 2;
|
|
83
81
|
/** chooseFactor's tolerance between the conventional factor and the observed median. */
|
|
@@ -205,8 +203,7 @@ function rateConsensus(rates, options = {}) {
|
|
|
205
203
|
})
|
|
206
204
|
};
|
|
207
205
|
}
|
|
208
|
-
|
|
209
|
-
//#region src/fx/reporting.ts
|
|
206
|
+
// src/fx/reporting.ts
|
|
210
207
|
const FACTOR_DIGITS = 20;
|
|
211
208
|
/**
|
|
212
209
|
* The reporting factors of a store whose locked rates say `1 default = n/d <code>`:
|
|
@@ -259,8 +256,7 @@ function toReporting(items, table) {
|
|
|
259
256
|
missing: [...missing].sort()
|
|
260
257
|
};
|
|
261
258
|
}
|
|
262
|
-
|
|
263
|
-
//#region src/fx/settings.ts
|
|
259
|
+
// src/fx/settings.ts
|
|
264
260
|
const RATE_MODES = ["manual", "dynamic"];
|
|
265
261
|
const PRICE_ROUNDINGS = ["none", "nearest"];
|
|
266
262
|
/** `store_currency_rate.rate_mode` as readers coerce it: `'manual'` exactly, else `'dynamic'`. */
|
|
@@ -298,8 +294,7 @@ function resolveMoneyByCurrency(setting, currency, options) {
|
|
|
298
294
|
}
|
|
299
295
|
return null;
|
|
300
296
|
}
|
|
301
|
-
|
|
302
|
-
//#region src/fx/tables.ts
|
|
297
|
+
// src/fx/tables.ts
|
|
303
298
|
/** 1 USD = rate units of the currency, exact (see data/pegs.ts for the sources). Upper-case keys. */
|
|
304
299
|
const USD_PEGS = Object.freeze(Object.fromEntries(Object.entries({
|
|
305
300
|
AED: [36725n, 10000n],
|
|
@@ -370,5 +365,4 @@ function pegFallback(from, to, ratesPerUsd, pegs = USD_PEGS) {
|
|
|
370
365
|
const fromPeg = own(pegs, f);
|
|
371
366
|
return fromPeg !== void 0 && t === "USD" ? invertRate(fromPeg) : null;
|
|
372
367
|
}
|
|
373
|
-
//#endregion
|
|
374
368
|
export { DEFAULT_RATE_MAX_DEVIATION, FACTOR_TOLERANCE, PRICE_ROUNDINGS, RATE_BOUNDS, RATE_MODES, RATE_REF, USD_PEGS, classifyRate, confirmStoredFactor, convert, convertFactor, crossRate, deviationFactor, formatRate, impliedRate, invertRate, mergeRateTables, parsePriceRounding, parseRateMode, pegFallback, priceRoundingParams, rate, rateConsensus, rateEquals, rateFromDecimal, rateFromRow, rateToDecimal, rateToNumber, resolveMoneyByCurrency, roundRetail, sanitizeRateTable, storeFactors, toReporting };
|
package/dist/index.cjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_money = require("./money-
|
|
3
|
-
const require_rounding = require("./rounding-
|
|
4
|
-
const require_allocate = require("./allocate-
|
|
5
|
-
const require_arithmetic = require("./arithmetic-
|
|
6
|
-
const require_own = require("./own-
|
|
7
|
-
const require_format = require("./format-
|
|
8
|
-
const require_iso_minor = require("./iso-minor-
|
|
9
|
-
const require_medusa = require("./medusa-
|
|
10
|
-
|
|
2
|
+
const require_money = require("./money-DWBjuuEK.cjs");
|
|
3
|
+
const require_rounding = require("./rounding-4QKTRbMQ.cjs");
|
|
4
|
+
const require_allocate = require("./allocate-AusholrC.cjs");
|
|
5
|
+
const require_arithmetic = require("./arithmetic-D8A6IeZ0.cjs");
|
|
6
|
+
const require_own = require("./own-C5imDkyB.cjs");
|
|
7
|
+
const require_format = require("./format-92fzvTXY.cjs");
|
|
8
|
+
const require_iso_minor = require("./iso-minor-DyNjT9A1.cjs");
|
|
9
|
+
const require_medusa = require("./medusa-CzVK0bth.cjs");
|
|
10
|
+
// src/data/countries.ts
|
|
11
11
|
const COUNTRY_CURRENCY = {
|
|
12
12
|
AC: "SHP",
|
|
13
13
|
AD: "EUR",
|
|
@@ -265,15 +265,13 @@ const COUNTRY_CURRENCY = {
|
|
|
265
265
|
ZM: "ZMW",
|
|
266
266
|
ZW: "ZWG"
|
|
267
267
|
};
|
|
268
|
-
|
|
269
|
-
//#region src/country.ts
|
|
268
|
+
// src/country.ts
|
|
270
269
|
/** The current legal tender of an ISO 3166 country (`'US'` or `'us'`), or null when unknown. Never guesses USD. */
|
|
271
270
|
function defaultCurrencyForCountry(country) {
|
|
272
271
|
if (typeof country !== "string") return null;
|
|
273
272
|
const key = country.toUpperCase();
|
|
274
273
|
return require_own.hasOwnKey(COUNTRY_CURRENCY, key) ? COUNTRY_CURRENCY[key] : null;
|
|
275
274
|
}
|
|
276
|
-
//#endregion
|
|
277
275
|
exports.CURRENCIES = require_money.CURRENCIES;
|
|
278
276
|
exports.MoneyError = require_money.MoneyError;
|
|
279
277
|
exports.add = require_arithmetic.add;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { A as isCurrencyCode, C as currencyInfo, D as currencySymbol, E as currencyOptions, F as sameCurrency, I as storageDigits, L as storageScale, M as medusaCurrencyCode, N as medusaEpsilon, O as displayDigits, P as parseCurrencyCode, R as DecimalText, S as currencyCode, T as currencyName, _ as CurrencyCodeOptions, a as ReadStoredOptions, b as FractionDigits, c as ToMajorDecimalOptions, d as money, f as readStored, g as CurrencyCode, h as CURRENCIES, i as Money, j as localeForCurrency, k as firstCurrency, l as fromMajor, m as toMajorNumber, n as FromMajorOptions, o as StoredAmount, p as toMajorDecimal, r as MajorDecimal, s as StoredAmountOptions, t as FractionalMoney, u as isStoredAmount, v as CurrencyInfo, w as currencyLabel, x as StorageScale, y as CurrencyStatus, z as RoundingMode } from "./money-
|
|
2
|
-
import { a as isPositiveAmount, c as readCalculatedPrice, d as readStoredLiteral, f as toMedusaAmountInput, i as ReadStoredDecimalOptions, l as readStoredDecimal, n as MoneyByCurrency, o as moneyByCurrency, p as toMedusaRaw, r as PriceLike, s as moneyFor, t as MedusaRaw, u as readStoredField } from "./medusa-
|
|
3
|
-
//#region src/allocate.d.ts
|
|
1
|
+
import { A as isCurrencyCode, C as currencyInfo, D as currencySymbol, E as currencyOptions, F as sameCurrency, I as storageDigits, L as storageScale, M as medusaCurrencyCode, N as medusaEpsilon, O as displayDigits, P as parseCurrencyCode, R as DecimalText, S as currencyCode, T as currencyName, _ as CurrencyCodeOptions, a as ReadStoredOptions, b as FractionDigits, c as ToMajorDecimalOptions, d as money, f as readStored, g as CurrencyCode, h as CURRENCIES, i as Money, j as localeForCurrency, k as firstCurrency, l as fromMajor, m as toMajorNumber, n as FromMajorOptions, o as StoredAmount, p as toMajorDecimal, r as MajorDecimal, s as StoredAmountOptions, t as FractionalMoney, u as isStoredAmount, v as CurrencyInfo, w as currencyLabel, x as StorageScale, y as CurrencyStatus, z as RoundingMode } from "./money-BkMeYDEW.cjs";
|
|
2
|
+
import { a as isPositiveAmount, c as readCalculatedPrice, d as readStoredLiteral, f as toMedusaAmountInput, i as ReadStoredDecimalOptions, l as readStoredDecimal, n as MoneyByCurrency, o as moneyByCurrency, p as toMedusaRaw, r as PriceLike, s as moneyFor, t as MedusaRaw, u as readStoredField } from "./medusa-DofdvIgQ.cjs";
|
|
4
3
|
/**
|
|
5
4
|
* Where the rounding remainder goes:
|
|
6
5
|
* - `'largest-remainder'` (default; promotion parity engine): floor every share, then +1 unit
|
|
@@ -67,8 +66,6 @@ interface UnitPricePart {
|
|
|
67
66
|
export declare function splitUnitPrice(net: Money, quantity: number, options?: {
|
|
68
67
|
unit?: 'storage' | 'currency';
|
|
69
68
|
}): UnitPricePart[];
|
|
70
|
-
//#endregion
|
|
71
|
-
//#region src/rounding.d.ts
|
|
72
69
|
/**
|
|
73
70
|
* - `'storage'`: one storage unit (USD 1 cent, JPY 1/100 yen).
|
|
74
71
|
* - `'currency'`: the smallest unit the currency stores, 10^-storageDigits major (JPY 1 yen
|
|
@@ -99,8 +96,6 @@ export declare function roundMajor(major: number | DecimalText, currency: string
|
|
|
99
96
|
digits?: 'display' | 'storage';
|
|
100
97
|
rounding?: RoundingMode;
|
|
101
98
|
}): number;
|
|
102
|
-
//#endregion
|
|
103
|
-
//#region src/arithmetic.d.ts
|
|
104
99
|
/** An exact ratio of integers (`{ numerator: 1, denominator: 3 }`). */
|
|
105
100
|
interface Ratio {
|
|
106
101
|
readonly numerator: number | bigint;
|
|
@@ -145,12 +140,8 @@ export declare function within(a: Money, b: Money, tolerance: Money, options?: {
|
|
|
145
140
|
}): boolean;
|
|
146
141
|
/** `d = a - b`; `d` below `tolerance` counts as rounding and gives 0, else `d` (Stripe `refundSyncDelta`). */
|
|
147
142
|
export declare function excessOver(a: Money, b: Money, tolerance: Money): Money;
|
|
148
|
-
//#endregion
|
|
149
|
-
//#region src/country.d.ts
|
|
150
143
|
/** The current legal tender of an ISO 3166 country (`'US'` or `'us'`), or null when unknown. Never guesses USD. */
|
|
151
144
|
export declare function defaultCurrencyForCountry(country: string): CurrencyCode | null;
|
|
152
|
-
//#endregion
|
|
153
|
-
//#region src/decimal-text.d.ts
|
|
154
145
|
/** Anything the family takes as a value. */
|
|
155
146
|
type DecimalInput = DecimalText | string | number | bigint;
|
|
156
147
|
/** Canonical DecimalText of `input` (`'4300.00'` gives `'4300'`, `0.1 + 0.2` gives `'0.30000000000000004'`). See `decimalOf` for what is refused. */
|
|
@@ -205,8 +196,6 @@ export declare function decimalClamp(a: DecimalText | string, bounds: {
|
|
|
205
196
|
export declare function decimalWithin(a: DecimalText | string, b: DecimalText | string, tolerance: DecimalText | string, options?: {
|
|
206
197
|
inclusive?: boolean;
|
|
207
198
|
}): boolean;
|
|
208
|
-
//#endregion
|
|
209
|
-
//#region src/errors.d.ts
|
|
210
199
|
/**
|
|
211
200
|
* Why a money operation refused its input:
|
|
212
201
|
* - `currency_invalid`: not a currency this package knows (or a retired one where only active codes are allowed)
|
|
@@ -231,8 +220,6 @@ export declare class MoneyError extends Error {
|
|
|
231
220
|
readonly field?: string;
|
|
232
221
|
constructor(code: MoneyErrorCode, message: string, options?: MoneyErrorOptions);
|
|
233
222
|
}
|
|
234
|
-
//#endregion
|
|
235
|
-
//#region src/format.d.ts
|
|
236
223
|
interface FormatMoneyOptions {
|
|
237
224
|
/** Default `'en-US'`; an unsupported or malformed tag falls back to it. */
|
|
238
225
|
locale?: string;
|
|
@@ -248,16 +235,26 @@ interface FormatMoneyOptions {
|
|
|
248
235
|
signDisplay?: 'auto' | 'always' | 'exceptZero';
|
|
249
236
|
/** Default `'-'`; `'−'` (U+2212) replaces the leading ASCII minus. */
|
|
250
237
|
minusSign?: '-' | '−';
|
|
238
|
+
/**
|
|
239
|
+
* How the amount is rounded to the digits shown: `'half-up'` (default) or `'down'` (toward
|
|
240
|
+
* zero), for an upper bound that must not read above itself: a refund cap of HUF 435050
|
|
241
|
+
* (4,350.50) shows `'HUF 4,350'` with `'down'`, never 4,351. `formatStored` rounds a fractional
|
|
242
|
+
* amount to a storage unit the same way first.
|
|
243
|
+
*/
|
|
244
|
+
rounding?: DisplayRounding;
|
|
251
245
|
}
|
|
246
|
+
/** The roundings `formatMoney` and `formatStored` take. */
|
|
247
|
+
type DisplayRounding = Extract<RoundingMode, 'half-up' | 'down'>;
|
|
252
248
|
/**
|
|
253
249
|
* Money for people: `'$1,234.50'`, `'¥1,200'`, `'KWD 1.005'`, `'-€5.00'`. Locale, currency
|
|
254
|
-
* display, digits
|
|
255
|
-
* pass. If Intl throws, `'<CODE> <decimal>'`.
|
|
250
|
+
* display, digits, sign and rounding (half-up by default, `'down'` for caps) are explicit
|
|
251
|
+
* options; the active app locale is the caller's to pass. If Intl throws, `'<CODE> <decimal>'`.
|
|
256
252
|
*/
|
|
257
253
|
export declare function formatMoney(m: Money, options?: FormatMoneyOptions): string;
|
|
258
254
|
/**
|
|
259
255
|
* A stored amount that may be fractional (a Medusa total, 107.8175; a percentage promotion) for
|
|
260
|
-
* people: rounded
|
|
256
|
+
* people: rounded to a whole storage unit by `options.rounding` (`roundToUnit`; half-up by default,
|
|
257
|
+
* `'down'` toward zero for a cap), then `formatMoney` with `options`.
|
|
261
258
|
* A number must be finite; text is plain decimal; an unknown currency throws `currency_invalid`.
|
|
262
259
|
*/
|
|
263
260
|
export declare function formatStored(amount: number | DecimalText, currency: string, options?: FormatMoneyOptions): string;
|
|
@@ -265,7 +262,7 @@ export declare function formatStored(amount: number | DecimalText, currency: str
|
|
|
265
262
|
* Like `formatMoney` below `threshold` major units (default 10000, by magnitude); at or above
|
|
266
263
|
* it, compact short notation with `maximumSignificantDigits` (default 3): `'$12.3K'`.
|
|
267
264
|
*/
|
|
268
|
-
export declare function formatMoneyCompact(m: Money, options?: FormatMoneyOptions & {
|
|
265
|
+
export declare function formatMoneyCompact(m: Money, options?: Omit<FormatMoneyOptions, 'rounding'> & {
|
|
269
266
|
threshold?: number;
|
|
270
267
|
maximumSignificantDigits?: number;
|
|
271
268
|
}): string;
|
|
@@ -278,8 +275,6 @@ export declare function formatMoneyRange(low: Money, high: Money | null, options
|
|
|
278
275
|
* same rounding as `formatMoneyCompact` (`1234567` gives `'$1.23M'`).
|
|
279
276
|
*/
|
|
280
277
|
export declare function moneyAxisFormatter(currency: string, options?: Pick<FormatMoneyOptions, 'locale' | 'currencyDisplay'>): (major: number) => string;
|
|
281
|
-
//#endregion
|
|
282
|
-
//#region src/iso-minor.d.ts
|
|
283
278
|
/**
|
|
284
279
|
* ISO minor units at the display digits: `round(major x 10^displayDigits)` with `rounding`
|
|
285
280
|
* (default half-up). JPY 150000 gives 1500, KWD 1005 gives 1005, IQD 10000 gives 10, HUF
|
|
@@ -296,5 +291,4 @@ export declare function toIsoMinor(m: Money, options?: {
|
|
|
296
291
|
export declare function fromIsoMinor(value: number | string, currency: string, options?: {
|
|
297
292
|
digits?: FractionDigits;
|
|
298
293
|
}): Money;
|
|
299
|
-
|
|
300
|
-
export { type AllocateOptions, type AllocationStrategy, type AllocationWeight, type AmountUnit, CURRENCIES, type CurrencyCode, type CurrencyCodeOptions, type CurrencyInfo, type CurrencyStatus, type DecimalInput, type DecimalText, type FormatMoneyOptions, type FractionDigits, type FractionalMoney, type FromMajorOptions, type MajorDecimal, type MedusaRaw, type Money, type MoneyByCurrency, type MoneyErrorCode, type MoneyErrorOptions, type PriceLike, type Ratio, type ReadStoredDecimalOptions, type ReadStoredOptions, type RoundToUnitOptions, type RoundingMode, type StorageScale, type StoredAmount, type StoredAmountOptions, type ToMajorDecimalOptions, type UnitPricePart, type WaterfallResult, currencyCode, currencyInfo, currencyLabel, currencyName, currencyOptions, currencySymbol, displayDigits, firstCurrency, fromMajor, isCurrencyCode, isPositiveAmount, isStoredAmount, localeForCurrency, medusaCurrencyCode, medusaEpsilon, money, moneyByCurrency, moneyFor, parseCurrencyCode, readCalculatedPrice, readStored, readStoredDecimal, readStoredField, readStoredLiteral, sameCurrency, storageDigits, storageScale, toMajorDecimal, toMajorNumber, toMedusaAmountInput, toMedusaRaw };
|
|
294
|
+
export { type AllocateOptions, type AllocationStrategy, type AllocationWeight, type AmountUnit, CURRENCIES, type CurrencyCode, type CurrencyCodeOptions, type CurrencyInfo, type CurrencyStatus, type DecimalInput, type DecimalText, type DisplayRounding, type FormatMoneyOptions, type FractionDigits, type FractionalMoney, type FromMajorOptions, type MajorDecimal, type MedusaRaw, type Money, type MoneyByCurrency, type MoneyErrorCode, type MoneyErrorOptions, type PriceLike, type Ratio, type ReadStoredDecimalOptions, type ReadStoredOptions, type RoundToUnitOptions, type RoundingMode, type StorageScale, type StoredAmount, type StoredAmountOptions, type ToMajorDecimalOptions, type UnitPricePart, type WaterfallResult, currencyCode, currencyInfo, currencyLabel, currencyName, currencyOptions, currencySymbol, displayDigits, firstCurrency, fromMajor, isCurrencyCode, isPositiveAmount, isStoredAmount, localeForCurrency, medusaCurrencyCode, medusaEpsilon, money, moneyByCurrency, moneyFor, parseCurrencyCode, readCalculatedPrice, readStored, readStoredDecimal, readStoredField, readStoredLiteral, sameCurrency, storageDigits, storageScale, toMajorDecimal, toMajorNumber, toMedusaAmountInput, toMedusaRaw };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { A as isCurrencyCode, C as currencyInfo, D as currencySymbol, E as currencyOptions, F as sameCurrency, I as storageDigits, L as storageScale, M as medusaCurrencyCode, N as medusaEpsilon, O as displayDigits, P as parseCurrencyCode, R as DecimalText, S as currencyCode, T as currencyName, _ as CurrencyCodeOptions, a as ReadStoredOptions, b as FractionDigits, c as ToMajorDecimalOptions, d as money, f as readStored, g as CurrencyCode, h as CURRENCIES, i as Money, j as localeForCurrency, k as firstCurrency, l as fromMajor, m as toMajorNumber, n as FromMajorOptions, o as StoredAmount, p as toMajorDecimal, r as MajorDecimal, s as StoredAmountOptions, t as FractionalMoney, u as isStoredAmount, v as CurrencyInfo, w as currencyLabel, x as StorageScale, y as CurrencyStatus, z as RoundingMode } from "./money-
|
|
2
|
-
import { a as isPositiveAmount, c as readCalculatedPrice, d as readStoredLiteral, f as toMedusaAmountInput, i as ReadStoredDecimalOptions, l as readStoredDecimal, n as MoneyByCurrency, o as moneyByCurrency, p as toMedusaRaw, r as PriceLike, s as moneyFor, t as MedusaRaw, u as readStoredField } from "./medusa-
|
|
3
|
-
//#region src/allocate.d.ts
|
|
1
|
+
import { A as isCurrencyCode, C as currencyInfo, D as currencySymbol, E as currencyOptions, F as sameCurrency, I as storageDigits, L as storageScale, M as medusaCurrencyCode, N as medusaEpsilon, O as displayDigits, P as parseCurrencyCode, R as DecimalText, S as currencyCode, T as currencyName, _ as CurrencyCodeOptions, a as ReadStoredOptions, b as FractionDigits, c as ToMajorDecimalOptions, d as money, f as readStored, g as CurrencyCode, h as CURRENCIES, i as Money, j as localeForCurrency, k as firstCurrency, l as fromMajor, m as toMajorNumber, n as FromMajorOptions, o as StoredAmount, p as toMajorDecimal, r as MajorDecimal, s as StoredAmountOptions, t as FractionalMoney, u as isStoredAmount, v as CurrencyInfo, w as currencyLabel, x as StorageScale, y as CurrencyStatus, z as RoundingMode } from "./money-BkMeYDEW.js";
|
|
2
|
+
import { a as isPositiveAmount, c as readCalculatedPrice, d as readStoredLiteral, f as toMedusaAmountInput, i as ReadStoredDecimalOptions, l as readStoredDecimal, n as MoneyByCurrency, o as moneyByCurrency, p as toMedusaRaw, r as PriceLike, s as moneyFor, t as MedusaRaw, u as readStoredField } from "./medusa-DrbYmD2Y.js";
|
|
4
3
|
/**
|
|
5
4
|
* Where the rounding remainder goes:
|
|
6
5
|
* - `'largest-remainder'` (default; promotion parity engine): floor every share, then +1 unit
|
|
@@ -67,8 +66,6 @@ interface UnitPricePart {
|
|
|
67
66
|
export declare function splitUnitPrice(net: Money, quantity: number, options?: {
|
|
68
67
|
unit?: 'storage' | 'currency';
|
|
69
68
|
}): UnitPricePart[];
|
|
70
|
-
//#endregion
|
|
71
|
-
//#region src/rounding.d.ts
|
|
72
69
|
/**
|
|
73
70
|
* - `'storage'`: one storage unit (USD 1 cent, JPY 1/100 yen).
|
|
74
71
|
* - `'currency'`: the smallest unit the currency stores, 10^-storageDigits major (JPY 1 yen
|
|
@@ -99,8 +96,6 @@ export declare function roundMajor(major: number | DecimalText, currency: string
|
|
|
99
96
|
digits?: 'display' | 'storage';
|
|
100
97
|
rounding?: RoundingMode;
|
|
101
98
|
}): number;
|
|
102
|
-
//#endregion
|
|
103
|
-
//#region src/arithmetic.d.ts
|
|
104
99
|
/** An exact ratio of integers (`{ numerator: 1, denominator: 3 }`). */
|
|
105
100
|
interface Ratio {
|
|
106
101
|
readonly numerator: number | bigint;
|
|
@@ -145,12 +140,8 @@ export declare function within(a: Money, b: Money, tolerance: Money, options?: {
|
|
|
145
140
|
}): boolean;
|
|
146
141
|
/** `d = a - b`; `d` below `tolerance` counts as rounding and gives 0, else `d` (Stripe `refundSyncDelta`). */
|
|
147
142
|
export declare function excessOver(a: Money, b: Money, tolerance: Money): Money;
|
|
148
|
-
//#endregion
|
|
149
|
-
//#region src/country.d.ts
|
|
150
143
|
/** The current legal tender of an ISO 3166 country (`'US'` or `'us'`), or null when unknown. Never guesses USD. */
|
|
151
144
|
export declare function defaultCurrencyForCountry(country: string): CurrencyCode | null;
|
|
152
|
-
//#endregion
|
|
153
|
-
//#region src/decimal-text.d.ts
|
|
154
145
|
/** Anything the family takes as a value. */
|
|
155
146
|
type DecimalInput = DecimalText | string | number | bigint;
|
|
156
147
|
/** Canonical DecimalText of `input` (`'4300.00'` gives `'4300'`, `0.1 + 0.2` gives `'0.30000000000000004'`). See `decimalOf` for what is refused. */
|
|
@@ -205,8 +196,6 @@ export declare function decimalClamp(a: DecimalText | string, bounds: {
|
|
|
205
196
|
export declare function decimalWithin(a: DecimalText | string, b: DecimalText | string, tolerance: DecimalText | string, options?: {
|
|
206
197
|
inclusive?: boolean;
|
|
207
198
|
}): boolean;
|
|
208
|
-
//#endregion
|
|
209
|
-
//#region src/errors.d.ts
|
|
210
199
|
/**
|
|
211
200
|
* Why a money operation refused its input:
|
|
212
201
|
* - `currency_invalid`: not a currency this package knows (or a retired one where only active codes are allowed)
|
|
@@ -231,8 +220,6 @@ export declare class MoneyError extends Error {
|
|
|
231
220
|
readonly field?: string;
|
|
232
221
|
constructor(code: MoneyErrorCode, message: string, options?: MoneyErrorOptions);
|
|
233
222
|
}
|
|
234
|
-
//#endregion
|
|
235
|
-
//#region src/format.d.ts
|
|
236
223
|
interface FormatMoneyOptions {
|
|
237
224
|
/** Default `'en-US'`; an unsupported or malformed tag falls back to it. */
|
|
238
225
|
locale?: string;
|
|
@@ -248,16 +235,26 @@ interface FormatMoneyOptions {
|
|
|
248
235
|
signDisplay?: 'auto' | 'always' | 'exceptZero';
|
|
249
236
|
/** Default `'-'`; `'−'` (U+2212) replaces the leading ASCII minus. */
|
|
250
237
|
minusSign?: '-' | '−';
|
|
238
|
+
/**
|
|
239
|
+
* How the amount is rounded to the digits shown: `'half-up'` (default) or `'down'` (toward
|
|
240
|
+
* zero), for an upper bound that must not read above itself: a refund cap of HUF 435050
|
|
241
|
+
* (4,350.50) shows `'HUF 4,350'` with `'down'`, never 4,351. `formatStored` rounds a fractional
|
|
242
|
+
* amount to a storage unit the same way first.
|
|
243
|
+
*/
|
|
244
|
+
rounding?: DisplayRounding;
|
|
251
245
|
}
|
|
246
|
+
/** The roundings `formatMoney` and `formatStored` take. */
|
|
247
|
+
type DisplayRounding = Extract<RoundingMode, 'half-up' | 'down'>;
|
|
252
248
|
/**
|
|
253
249
|
* Money for people: `'$1,234.50'`, `'¥1,200'`, `'KWD 1.005'`, `'-€5.00'`. Locale, currency
|
|
254
|
-
* display, digits
|
|
255
|
-
* pass. If Intl throws, `'<CODE> <decimal>'`.
|
|
250
|
+
* display, digits, sign and rounding (half-up by default, `'down'` for caps) are explicit
|
|
251
|
+
* options; the active app locale is the caller's to pass. If Intl throws, `'<CODE> <decimal>'`.
|
|
256
252
|
*/
|
|
257
253
|
export declare function formatMoney(m: Money, options?: FormatMoneyOptions): string;
|
|
258
254
|
/**
|
|
259
255
|
* A stored amount that may be fractional (a Medusa total, 107.8175; a percentage promotion) for
|
|
260
|
-
* people: rounded
|
|
256
|
+
* people: rounded to a whole storage unit by `options.rounding` (`roundToUnit`; half-up by default,
|
|
257
|
+
* `'down'` toward zero for a cap), then `formatMoney` with `options`.
|
|
261
258
|
* A number must be finite; text is plain decimal; an unknown currency throws `currency_invalid`.
|
|
262
259
|
*/
|
|
263
260
|
export declare function formatStored(amount: number | DecimalText, currency: string, options?: FormatMoneyOptions): string;
|
|
@@ -265,7 +262,7 @@ export declare function formatStored(amount: number | DecimalText, currency: str
|
|
|
265
262
|
* Like `formatMoney` below `threshold` major units (default 10000, by magnitude); at or above
|
|
266
263
|
* it, compact short notation with `maximumSignificantDigits` (default 3): `'$12.3K'`.
|
|
267
264
|
*/
|
|
268
|
-
export declare function formatMoneyCompact(m: Money, options?: FormatMoneyOptions & {
|
|
265
|
+
export declare function formatMoneyCompact(m: Money, options?: Omit<FormatMoneyOptions, 'rounding'> & {
|
|
269
266
|
threshold?: number;
|
|
270
267
|
maximumSignificantDigits?: number;
|
|
271
268
|
}): string;
|
|
@@ -278,8 +275,6 @@ export declare function formatMoneyRange(low: Money, high: Money | null, options
|
|
|
278
275
|
* same rounding as `formatMoneyCompact` (`1234567` gives `'$1.23M'`).
|
|
279
276
|
*/
|
|
280
277
|
export declare function moneyAxisFormatter(currency: string, options?: Pick<FormatMoneyOptions, 'locale' | 'currencyDisplay'>): (major: number) => string;
|
|
281
|
-
//#endregion
|
|
282
|
-
//#region src/iso-minor.d.ts
|
|
283
278
|
/**
|
|
284
279
|
* ISO minor units at the display digits: `round(major x 10^displayDigits)` with `rounding`
|
|
285
280
|
* (default half-up). JPY 150000 gives 1500, KWD 1005 gives 1005, IQD 10000 gives 10, HUF
|
|
@@ -296,5 +291,4 @@ export declare function toIsoMinor(m: Money, options?: {
|
|
|
296
291
|
export declare function fromIsoMinor(value: number | string, currency: string, options?: {
|
|
297
292
|
digits?: FractionDigits;
|
|
298
293
|
}): Money;
|
|
299
|
-
|
|
300
|
-
export { type AllocateOptions, type AllocationStrategy, type AllocationWeight, type AmountUnit, CURRENCIES, type CurrencyCode, type CurrencyCodeOptions, type CurrencyInfo, type CurrencyStatus, type DecimalInput, type DecimalText, type FormatMoneyOptions, type FractionDigits, type FractionalMoney, type FromMajorOptions, type MajorDecimal, type MedusaRaw, type Money, type MoneyByCurrency, type MoneyErrorCode, type MoneyErrorOptions, type PriceLike, type Ratio, type ReadStoredDecimalOptions, type ReadStoredOptions, type RoundToUnitOptions, type RoundingMode, type StorageScale, type StoredAmount, type StoredAmountOptions, type ToMajorDecimalOptions, type UnitPricePart, type WaterfallResult, currencyCode, currencyInfo, currencyLabel, currencyName, currencyOptions, currencySymbol, displayDigits, firstCurrency, fromMajor, isCurrencyCode, isPositiveAmount, isStoredAmount, localeForCurrency, medusaCurrencyCode, medusaEpsilon, money, moneyByCurrency, moneyFor, parseCurrencyCode, readCalculatedPrice, readStored, readStoredDecimal, readStoredField, readStoredLiteral, sameCurrency, storageDigits, storageScale, toMajorDecimal, toMajorNumber, toMedusaAmountInput, toMedusaRaw };
|
|
294
|
+
export { type AllocateOptions, type AllocationStrategy, type AllocationWeight, type AmountUnit, CURRENCIES, type CurrencyCode, type CurrencyCodeOptions, type CurrencyInfo, type CurrencyStatus, type DecimalInput, type DecimalText, type DisplayRounding, type FormatMoneyOptions, type FractionDigits, type FractionalMoney, type FromMajorOptions, type MajorDecimal, type MedusaRaw, type Money, type MoneyByCurrency, type MoneyErrorCode, type MoneyErrorOptions, type PriceLike, type Ratio, type ReadStoredDecimalOptions, type ReadStoredOptions, type RoundToUnitOptions, type RoundingMode, type StorageScale, type StoredAmount, type StoredAmountOptions, type ToMajorDecimalOptions, type UnitPricePart, type WaterfallResult, currencyCode, currencyInfo, currencyLabel, currencyName, currencyOptions, currencySymbol, displayDigits, firstCurrency, fromMajor, isCurrencyCode, isPositiveAmount, isStoredAmount, localeForCurrency, medusaCurrencyCode, medusaEpsilon, money, moneyByCurrency, moneyFor, parseCurrencyCode, readCalculatedPrice, readStored, readStoredDecimal, readStoredField, readStoredLiteral, sameCurrency, storageDigits, storageScale, toMajorDecimal, toMajorNumber, toMedusaAmountInput, toMedusaRaw };
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { A as storageScale, C as medusaCurrencyCode, D as sameCurrency, F as decimalClamp, G as isDecimalLiteral, H as decimalSubtract, I as decimalCompare, K as parseDecimalText, L as decimalDivide, O as storageDigits, P as assertDecimalLiteral, Q as MoneyError, R as decimalEquals, S as localeForCurrency, T as parseCurrencyCode, U as decimalSum, V as decimalRound, W as decimalWithin, _ as currencySymbol, a as money, b as firstCurrency, c as toMajorDecimal, d as currencyCode, f as currencyInfo, g as currencyOptions, h as currencyName, l as toMajorNumber, n as fromMajor, o as readStored, p as currencyLabel, q as trimDecimalZeros, r as isStoredAmount, u as CURRENCIES, v as displayDigits, w as medusaEpsilon, x as isCurrencyCode, z as decimalMultiply } from "./money-
|
|
2
|
-
import { i as roundToUnit, n as roundMajor } from "./rounding-
|
|
3
|
-
import { i as splitUnitPrice, r as allocateWaterfall, t as allocate } from "./allocate-
|
|
4
|
-
import { _ as within, a as equals, c as isPositive, d as min, f as multiply, g as sum, h as subtract, i as divide, l as isZero, m as remaining, n as clamp, o as excessOver, p as percentOf, r as compare, s as isNegative, t as add, u as max } from "./arithmetic-
|
|
5
|
-
import { t as hasOwnKey } from "./own-
|
|
6
|
-
import { a as moneyAxisFormatter, i as formatStored, n as formatMoneyCompact, r as formatMoneyRange, t as formatMoney } from "./format-
|
|
7
|
-
import { r as toIsoMinor, t as fromIsoMinor } from "./iso-minor-
|
|
8
|
-
import { a as readStoredDecimal, i as readCalculatedPrice, l as toMedusaAmountInput, n as moneyByCurrency, o as readStoredField, r as moneyFor, s as readStoredLiteral, t as isPositiveAmount, u as toMedusaRaw } from "./medusa-
|
|
9
|
-
|
|
1
|
+
import { A as storageScale, C as medusaCurrencyCode, D as sameCurrency, F as decimalClamp, G as isDecimalLiteral, H as decimalSubtract, I as decimalCompare, K as parseDecimalText, L as decimalDivide, O as storageDigits, P as assertDecimalLiteral, Q as MoneyError, R as decimalEquals, S as localeForCurrency, T as parseCurrencyCode, U as decimalSum, V as decimalRound, W as decimalWithin, _ as currencySymbol, a as money, b as firstCurrency, c as toMajorDecimal, d as currencyCode, f as currencyInfo, g as currencyOptions, h as currencyName, l as toMajorNumber, n as fromMajor, o as readStored, p as currencyLabel, q as trimDecimalZeros, r as isStoredAmount, u as CURRENCIES, v as displayDigits, w as medusaEpsilon, x as isCurrencyCode, z as decimalMultiply } from "./money-BxbAw7BP.js";
|
|
2
|
+
import { i as roundToUnit, n as roundMajor } from "./rounding-CA1PVP3b.js";
|
|
3
|
+
import { i as splitUnitPrice, r as allocateWaterfall, t as allocate } from "./allocate-BBRfdaSC.js";
|
|
4
|
+
import { _ as within, a as equals, c as isPositive, d as min, f as multiply, g as sum, h as subtract, i as divide, l as isZero, m as remaining, n as clamp, o as excessOver, p as percentOf, r as compare, s as isNegative, t as add, u as max } from "./arithmetic-C97-YafD.js";
|
|
5
|
+
import { t as hasOwnKey } from "./own-DHxqIYqL.js";
|
|
6
|
+
import { a as moneyAxisFormatter, i as formatStored, n as formatMoneyCompact, r as formatMoneyRange, t as formatMoney } from "./format-BJC513u4.js";
|
|
7
|
+
import { r as toIsoMinor, t as fromIsoMinor } from "./iso-minor-odkY-e6I.js";
|
|
8
|
+
import { a as readStoredDecimal, i as readCalculatedPrice, l as toMedusaAmountInput, n as moneyByCurrency, o as readStoredField, r as moneyFor, s as readStoredLiteral, t as isPositiveAmount, u as toMedusaRaw } from "./medusa-pKGlImn9.js";
|
|
9
|
+
// src/data/countries.ts
|
|
10
10
|
const COUNTRY_CURRENCY = {
|
|
11
11
|
AC: "SHP",
|
|
12
12
|
AD: "EUR",
|
|
@@ -264,13 +264,11 @@ const COUNTRY_CURRENCY = {
|
|
|
264
264
|
ZM: "ZMW",
|
|
265
265
|
ZW: "ZWG"
|
|
266
266
|
};
|
|
267
|
-
|
|
268
|
-
//#region src/country.ts
|
|
267
|
+
// src/country.ts
|
|
269
268
|
/** The current legal tender of an ISO 3166 country (`'US'` or `'us'`), or null when unknown. Never guesses USD. */
|
|
270
269
|
function defaultCurrencyForCountry(country) {
|
|
271
270
|
if (typeof country !== "string") return null;
|
|
272
271
|
const key = country.toUpperCase();
|
|
273
272
|
return hasOwnKey(COUNTRY_CURRENCY, key) ? COUNTRY_CURRENCY[key] : null;
|
|
274
273
|
}
|
|
275
|
-
//#endregion
|
|
276
274
|
export { CURRENCIES, MoneyError, add, allocate, allocateWaterfall, assertDecimalLiteral, clamp, compare, currencyCode, currencyInfo, currencyLabel, currencyName, currencyOptions, currencySymbol, decimalClamp, decimalCompare, decimalDivide, decimalEquals, decimalMultiply, decimalRound, decimalSubtract, decimalSum, decimalWithin, defaultCurrencyForCountry, displayDigits, divide, equals, excessOver, firstCurrency, formatMoney, formatMoneyCompact, formatMoneyRange, formatStored, fromIsoMinor, fromMajor, isCurrencyCode, isDecimalLiteral, isNegative, isPositive, isPositiveAmount, isStoredAmount, isZero, localeForCurrency, max, medusaCurrencyCode, medusaEpsilon, min, money, moneyAxisFormatter, moneyByCurrency, moneyFor, multiply, parseCurrencyCode, parseDecimalText, percentOf, readCalculatedPrice, readStored, readStoredDecimal, readStoredField, readStoredLiteral, remaining, roundMajor, roundToUnit, sameCurrency, splitUnitPrice, storageDigits, storageScale, subtract, sum, toIsoMinor, toMajorDecimal, toMajorNumber, toMedusaAmountInput, toMedusaRaw, trimDecimalZeros, within };
|
package/dist/input.cjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_money = require("./money-
|
|
3
|
-
const require_number_text = require("./number-text-
|
|
4
|
-
const require_rate = require("./rate-
|
|
5
|
-
const require_amount = require("./amount-
|
|
6
|
-
|
|
2
|
+
const require_money = require("./money-DWBjuuEK.cjs");
|
|
3
|
+
const require_number_text = require("./number-text-CWuVwrlg.cjs");
|
|
4
|
+
const require_rate = require("./rate-CEjWTATc.cjs");
|
|
5
|
+
const require_amount = require("./amount-CwFzcxUl.cjs");
|
|
6
|
+
// src/input/import.ts
|
|
7
7
|
/**
|
|
8
8
|
* Amount text from a file or a third party to canonical DecimalText (major units, exactly as
|
|
9
9
|
* written: `'1.299,00'` gives `'1299'`), or null when it is not an amount (empty, exponent,
|
|
@@ -53,8 +53,7 @@ function parseDecimalInput(text, options) {
|
|
|
53
53
|
value: require_money.toDecimalText(value)
|
|
54
54
|
};
|
|
55
55
|
}
|
|
56
|
-
|
|
57
|
-
//#region src/input/percent-rate.ts
|
|
56
|
+
// src/input/percent-rate.ts
|
|
58
57
|
/**
|
|
59
58
|
* A typed percent (`'20'`, `'12.5'`, `'12,5 %'` in de-DE) as DecimalText. A `%` before or after
|
|
60
59
|
* the number is allowed. Default range 0..100 with 2 decimals; below 0 (with a non-negative
|
|
@@ -103,8 +102,7 @@ function parseRateInput(text, options = {}) {
|
|
|
103
102
|
throw error;
|
|
104
103
|
}
|
|
105
104
|
}
|
|
106
|
-
|
|
107
|
-
//#region src/input/template.ts
|
|
105
|
+
// src/input/template.ts
|
|
108
106
|
const DEFAULT_TEMPLATE = Object.freeze({
|
|
109
107
|
prefix: "",
|
|
110
108
|
suffix: "",
|
|
@@ -150,7 +148,6 @@ function formatWithTemplate(m, template) {
|
|
|
150
148
|
const tail = fraction === void 0 ? "" : `${template.decimalSeparator}${fraction}`;
|
|
151
149
|
return `${template.prefix}${negative ? "-" : ""}${grouped}${tail}${template.suffix}`;
|
|
152
150
|
}
|
|
153
|
-
//#endregion
|
|
154
151
|
exports.formatAmountInput = require_amount.formatAmountInput;
|
|
155
152
|
exports.formatWithTemplate = formatWithTemplate;
|
|
156
153
|
exports.inputPlaceholder = require_amount.inputPlaceholder;
|
package/dist/input.d.cts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { R as DecimalText, b as FractionDigits, i as Money } from "./money-
|
|
2
|
-
import { r as Rate } from "./rate-
|
|
3
|
-
//#region src/input/amount.d.ts
|
|
1
|
+
import { R as DecimalText, b as FractionDigits, i as Money } from "./money-BkMeYDEW.cjs";
|
|
2
|
+
import { r as Rate } from "./rate-CEakW3ia.cjs";
|
|
4
3
|
/** Why typed text is not an acceptable amount. */
|
|
5
4
|
type ParseFailureReason = 'empty' | 'unparseable' | 'too_many_decimals' | 'negative' | 'zero' | 'below_min' | 'above_max';
|
|
6
5
|
interface ParseAmountInputOptions {
|
|
@@ -58,17 +57,18 @@ type ParseAmountResult = {
|
|
|
58
57
|
* against `,` (see `parseImportAmount`): `'29,99'` EUR is 29.99, `'1.299,00'` and `'1,299'`
|
|
59
58
|
* are 1299, KWD `'1,5'` is 1.5; a currency storing 0 digits rounds a fraction half-up to a
|
|
60
59
|
* whole unit (`'1200.5'` JPY is 1201).
|
|
61
|
-
* - With `locale`: its decimal separator is the decimal and its group separator is valid
|
|
62
|
-
* 3-digit (or Indian lakh) groups
|
|
63
|
-
* before exactly three digits
|
|
64
|
-
*
|
|
65
|
-
*
|
|
60
|
+
* - With `locale`: its decimal separator is always the decimal and its group separator is valid
|
|
61
|
+
* only in 3-digit (or Indian lakh) groups. In a currency that stores no fraction (JPY, VND) the
|
|
62
|
+
* decimal separator before exactly three digits is ambiguous (en-US `'1.234'` JPY could be
|
|
63
|
+
* 1,234 or 1.234) and is `'too_many_decimals'`, never read as grouping; grouping takes the
|
|
64
|
+
* locale's group separator (`'1,234'` en-US, `'1.234'` de-DE). en-US `'29,99'` USD is
|
|
65
|
+
* `'unparseable'`; de-DE `'29,99'` EUR is 29.99; en-US `'1200.5'` JPY is `'too_many_decimals'`.
|
|
66
66
|
* - With `decimalSeparator: '.'` (every `<input type="number">`): `.` is the decimal, nothing
|
|
67
67
|
* groups (`'1,299'` is `'unparseable'`), TND and IQD `'1.500'` are 1.5, and a currency storing
|
|
68
68
|
* 0 digits rounds a fraction half-up to a whole unit (`'1.5'` JPY is 2).
|
|
69
69
|
* Otherwise more fraction digits than the currency stores is `'too_many_decimals'`, never rounded
|
|
70
70
|
* (`'1,2345'` USD). Text equal to `original` returns it unchanged (JPY 120050 shown as
|
|
71
|
-
* `'1200.50'`). An unknown currency, or an `original` in another currency, throws.
|
|
71
|
+
* `'1200.50'`), except the ambiguous zero-digit text above. An unknown currency, or an `original` in another currency, throws.
|
|
72
72
|
*/
|
|
73
73
|
export declare function parseAmountInput(text: string, currency: string, options?: ParseAmountInputOptions): ParseAmountResult;
|
|
74
74
|
/**
|
|
@@ -99,8 +99,6 @@ export declare function formatAmountInput(m: Money, options?: {
|
|
|
99
99
|
export declare function inputStep(currency: string): '1' | '0.01' | '0.001';
|
|
100
100
|
/** The placeholder of a money input: `'0'`, `'0.00'` or `'0.000'`, from the storage digits. */
|
|
101
101
|
export declare function inputPlaceholder(currency: string): '0' | '0.00' | '0.000';
|
|
102
|
-
//#endregion
|
|
103
|
-
//#region src/input/import.d.ts
|
|
104
102
|
interface ImportAmountOptions {
|
|
105
103
|
/**
|
|
106
104
|
* `'auto'` (default): spaces, NBSP, thin spaces and apostrophes are grouping, and the
|
|
@@ -142,8 +140,6 @@ export declare function parseDecimalInput(text: string, options: DecimalInputOpt
|
|
|
142
140
|
ok: false;
|
|
143
141
|
reason: ParseFailureReason;
|
|
144
142
|
};
|
|
145
|
-
//#endregion
|
|
146
|
-
//#region src/input/percent-rate.d.ts
|
|
147
143
|
interface PercentInputOptions {
|
|
148
144
|
/** Inclusive, default 0. */
|
|
149
145
|
min?: number;
|
|
@@ -174,8 +170,6 @@ export declare function parsePercentInput(text: string, options?: PercentInputOp
|
|
|
174
170
|
export declare function parseRateInput(text: string, options?: {
|
|
175
171
|
locale?: string;
|
|
176
172
|
}): Rate | null;
|
|
177
|
-
//#endregion
|
|
178
|
-
//#region src/input/template.d.ts
|
|
179
173
|
interface MoneyTemplate {
|
|
180
174
|
/** Text before the number (`'Rp '`, `'€'`), the sign goes after it. */
|
|
181
175
|
readonly prefix: string;
|
|
@@ -199,5 +193,4 @@ export declare function moneyTemplateOf(sample: string): MoneyTemplate;
|
|
|
199
193
|
* (`moneyTemplateOf('Rp 199.000')` prints IDR 2500050 as `'Rp 25.001'`).
|
|
200
194
|
*/
|
|
201
195
|
export declare function formatWithTemplate(m: Money, template: MoneyTemplate): string;
|
|
202
|
-
//#endregion
|
|
203
196
|
export type { DecimalInputOptions, ImportAmountOptions, MoneyTemplate, ParseAmountInputOptions, ParseAmountResult, ParseFailureReason, PercentInputOptions };
|
package/dist/input.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { R as DecimalText, b as FractionDigits, i as Money } from "./money-
|
|
2
|
-
import { r as Rate } from "./rate-
|
|
3
|
-
//#region src/input/amount.d.ts
|
|
1
|
+
import { R as DecimalText, b as FractionDigits, i as Money } from "./money-BkMeYDEW.js";
|
|
2
|
+
import { r as Rate } from "./rate-BvvZUdSu.js";
|
|
4
3
|
/** Why typed text is not an acceptable amount. */
|
|
5
4
|
type ParseFailureReason = 'empty' | 'unparseable' | 'too_many_decimals' | 'negative' | 'zero' | 'below_min' | 'above_max';
|
|
6
5
|
interface ParseAmountInputOptions {
|
|
@@ -58,17 +57,18 @@ type ParseAmountResult = {
|
|
|
58
57
|
* against `,` (see `parseImportAmount`): `'29,99'` EUR is 29.99, `'1.299,00'` and `'1,299'`
|
|
59
58
|
* are 1299, KWD `'1,5'` is 1.5; a currency storing 0 digits rounds a fraction half-up to a
|
|
60
59
|
* whole unit (`'1200.5'` JPY is 1201).
|
|
61
|
-
* - With `locale`: its decimal separator is the decimal and its group separator is valid
|
|
62
|
-
* 3-digit (or Indian lakh) groups
|
|
63
|
-
* before exactly three digits
|
|
64
|
-
*
|
|
65
|
-
*
|
|
60
|
+
* - With `locale`: its decimal separator is always the decimal and its group separator is valid
|
|
61
|
+
* only in 3-digit (or Indian lakh) groups. In a currency that stores no fraction (JPY, VND) the
|
|
62
|
+
* decimal separator before exactly three digits is ambiguous (en-US `'1.234'` JPY could be
|
|
63
|
+
* 1,234 or 1.234) and is `'too_many_decimals'`, never read as grouping; grouping takes the
|
|
64
|
+
* locale's group separator (`'1,234'` en-US, `'1.234'` de-DE). en-US `'29,99'` USD is
|
|
65
|
+
* `'unparseable'`; de-DE `'29,99'` EUR is 29.99; en-US `'1200.5'` JPY is `'too_many_decimals'`.
|
|
66
66
|
* - With `decimalSeparator: '.'` (every `<input type="number">`): `.` is the decimal, nothing
|
|
67
67
|
* groups (`'1,299'` is `'unparseable'`), TND and IQD `'1.500'` are 1.5, and a currency storing
|
|
68
68
|
* 0 digits rounds a fraction half-up to a whole unit (`'1.5'` JPY is 2).
|
|
69
69
|
* Otherwise more fraction digits than the currency stores is `'too_many_decimals'`, never rounded
|
|
70
70
|
* (`'1,2345'` USD). Text equal to `original` returns it unchanged (JPY 120050 shown as
|
|
71
|
-
* `'1200.50'`). An unknown currency, or an `original` in another currency, throws.
|
|
71
|
+
* `'1200.50'`), except the ambiguous zero-digit text above. An unknown currency, or an `original` in another currency, throws.
|
|
72
72
|
*/
|
|
73
73
|
export declare function parseAmountInput(text: string, currency: string, options?: ParseAmountInputOptions): ParseAmountResult;
|
|
74
74
|
/**
|
|
@@ -99,8 +99,6 @@ export declare function formatAmountInput(m: Money, options?: {
|
|
|
99
99
|
export declare function inputStep(currency: string): '1' | '0.01' | '0.001';
|
|
100
100
|
/** The placeholder of a money input: `'0'`, `'0.00'` or `'0.000'`, from the storage digits. */
|
|
101
101
|
export declare function inputPlaceholder(currency: string): '0' | '0.00' | '0.000';
|
|
102
|
-
//#endregion
|
|
103
|
-
//#region src/input/import.d.ts
|
|
104
102
|
interface ImportAmountOptions {
|
|
105
103
|
/**
|
|
106
104
|
* `'auto'` (default): spaces, NBSP, thin spaces and apostrophes are grouping, and the
|
|
@@ -142,8 +140,6 @@ export declare function parseDecimalInput(text: string, options: DecimalInputOpt
|
|
|
142
140
|
ok: false;
|
|
143
141
|
reason: ParseFailureReason;
|
|
144
142
|
};
|
|
145
|
-
//#endregion
|
|
146
|
-
//#region src/input/percent-rate.d.ts
|
|
147
143
|
interface PercentInputOptions {
|
|
148
144
|
/** Inclusive, default 0. */
|
|
149
145
|
min?: number;
|
|
@@ -174,8 +170,6 @@ export declare function parsePercentInput(text: string, options?: PercentInputOp
|
|
|
174
170
|
export declare function parseRateInput(text: string, options?: {
|
|
175
171
|
locale?: string;
|
|
176
172
|
}): Rate | null;
|
|
177
|
-
//#endregion
|
|
178
|
-
//#region src/input/template.d.ts
|
|
179
173
|
interface MoneyTemplate {
|
|
180
174
|
/** Text before the number (`'Rp '`, `'€'`), the sign goes after it. */
|
|
181
175
|
readonly prefix: string;
|
|
@@ -199,5 +193,4 @@ export declare function moneyTemplateOf(sample: string): MoneyTemplate;
|
|
|
199
193
|
* (`moneyTemplateOf('Rp 199.000')` prints IDR 2500050 as `'Rp 25.001'`).
|
|
200
194
|
*/
|
|
201
195
|
export declare function formatWithTemplate(m: Money, template: MoneyTemplate): string;
|
|
202
|
-
//#endregion
|
|
203
196
|
export type { DecimalInputOptions, ImportAmountOptions, MoneyTemplate, ParseAmountInputOptions, ParseAmountResult, ParseFailureReason, PercentInputOptions };
|