@amboras-dev/money 0.1.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.
Files changed (80) hide show
  1. package/README.md +25 -10
  2. package/dist/ai.cjs +12 -13
  3. package/dist/ai.d.cts +5 -9
  4. package/dist/ai.d.ts +5 -9
  5. package/dist/ai.js +12 -13
  6. package/dist/{allocate-D7tm_t_o.cjs → allocate-AusholrC.cjs} +3 -4
  7. package/dist/{allocate-CdnhvAda.js → allocate-BBRfdaSC.js} +3 -4
  8. package/dist/{amount-DHtvZSSm.cjs → amount-CwFzcxUl.cjs} +29 -12
  9. package/dist/{amount-D7dj76nH.js → amount-DHFOK2Yd.js} +29 -12
  10. package/dist/{arithmetic-C-Q_aI49.js → arithmetic-C97-YafD.js} +4 -5
  11. package/dist/{arithmetic-Bq-8mSal.cjs → arithmetic-D8A6IeZ0.cjs} +4 -5
  12. package/dist/billing.cjs +5 -8
  13. package/dist/billing.d.cts +1 -9
  14. package/dist/billing.d.ts +1 -9
  15. package/dist/billing.js +5 -8
  16. package/dist/commerce.cjs +15 -23
  17. package/dist/commerce.d.cts +2 -16
  18. package/dist/commerce.d.ts +2 -16
  19. package/dist/commerce.js +15 -23
  20. package/dist/{format-BnA1aLJk.cjs → format-92fzvTXY.cjs} +21 -6
  21. package/dist/{format-BdB7LEIp.js → format-BJC513u4.js} +16 -7
  22. package/dist/fx.cjs +12 -18
  23. package/dist/fx.d.cts +5 -15
  24. package/dist/fx.d.ts +5 -15
  25. package/dist/fx.js +12 -18
  26. package/dist/index.cjs +13 -12
  27. package/dist/index.d.cts +28 -22
  28. package/dist/index.d.ts +28 -22
  29. package/dist/index.js +11 -13
  30. package/dist/input.cjs +7 -10
  31. package/dist/input.d.cts +9 -16
  32. package/dist/input.d.ts +9 -16
  33. package/dist/input.js +7 -10
  34. package/dist/{iso-minor--gQWI1f2.cjs → iso-minor-DyNjT9A1.cjs} +2 -3
  35. package/dist/{iso-minor-CtaiIifs.js → iso-minor-odkY-e6I.js} +2 -3
  36. package/dist/{medusa-OJ2TJOxt.cjs → medusa-CzVK0bth.cjs} +24 -4
  37. package/dist/{medusa-DuQ3-KoD.d.cts → medusa-DofdvIgQ.d.cts} +11 -4
  38. package/dist/{medusa-RwqxaDGq.d.ts → medusa-DrbYmD2Y.d.ts} +11 -4
  39. package/dist/{medusa-CmxCni-G.js → medusa-pKGlImn9.js} +19 -5
  40. package/dist/{money-CbhsT0fB.d.cts → money-BkMeYDEW.d.cts} +19 -9
  41. package/dist/{money-CbhsT0fB.d.ts → money-BkMeYDEW.d.ts} +19 -9
  42. package/dist/{money-CIgELekG.js → money-BxbAw7BP.js} +25 -21
  43. package/dist/{money-D5-vlv0h.cjs → money-DWBjuuEK.cjs} +42 -20
  44. package/dist/{number-text-C82oh6JB.js → number-text-Bj-gZXiF.js} +3 -4
  45. package/dist/{number-text-BpvN6NAo.cjs → number-text-CWuVwrlg.cjs} +3 -4
  46. package/dist/{own-oP9DXFWv.cjs → own-C5imDkyB.cjs} +1 -2
  47. package/dist/{own-D7544D3k.js → own-DHxqIYqL.js} +1 -2
  48. package/dist/{percent-CKVI_c-m.js → percent-CB3Ixjc_.js} +2 -3
  49. package/dist/{percent-Dt8vNIAW.cjs → percent-DABHiSBs.cjs} +2 -3
  50. package/dist/{rate-CmeTGNex.d.ts → rate-BvvZUdSu.d.ts} +1 -3
  51. package/dist/{rate-toyS3EMf.d.cts → rate-CEakW3ia.d.cts} +1 -3
  52. package/dist/{rate-DGPfB_jc.cjs → rate-CEjWTATc.cjs} +3 -4
  53. package/dist/{rate-lLPViBuM.js → rate-D6S2_wgZ.js} +3 -4
  54. package/dist/{reporting-5xby-Zas.d.ts → reporting-DFNyDBdi.d.cts} +2 -4
  55. package/dist/{reporting-DEM97DhQ.d.cts → reporting-jIBILvnr.d.ts} +2 -4
  56. package/dist/{retail-BwcFJcVN.d.ts → retail-B04CjW3b.d.ts} +1 -3
  57. package/dist/{retail-DTk2XAMM.cjs → retail-CYGPU4ea.cjs} +4 -5
  58. package/dist/{retail-Mqd-sPMF.d.cts → retail-CmEyJQOH.d.cts} +1 -3
  59. package/dist/{retail-BsvpNv1F.js → retail-DXgs11ov.js} +4 -5
  60. package/dist/{rounding-oZ832yTD.cjs → rounding-4QKTRbMQ.cjs} +2 -3
  61. package/dist/{rounding-CVAPEfq_.js → rounding-CA1PVP3b.js} +2 -3
  62. package/dist/sql.cjs +9 -15
  63. package/dist/sql.d.cts +2 -12
  64. package/dist/sql.d.ts +2 -12
  65. package/dist/sql.js +9 -15
  66. package/dist/testing.cjs +72675 -12
  67. package/dist/testing.d.cts +46 -11
  68. package/dist/testing.d.ts +46 -11
  69. package/dist/testing.js +72674 -13
  70. package/dist/{wire-CI3Sm1iC.js → wire-B4QU8O3W.js} +584 -114
  71. package/dist/wire-CVNicirK.d.ts +428 -0
  72. package/dist/wire-CtNJmWVP.d.cts +428 -0
  73. package/dist/{wire-DQZ6fA3c.cjs → wire-u2tmHY0Y.cjs} +649 -113
  74. package/dist/wire.cjs +12 -1
  75. package/dist/wire.d.cts +2 -2
  76. package/dist/wire.d.ts +2 -2
  77. package/dist/wire.js +1 -2
  78. package/package.json +4 -3
  79. package/dist/wire-Cd4Q1Jmm.d.ts +0 -269
  80. package/dist/wire-hWuixv3w.d.cts +0 -269
package/dist/fx.d.cts CHANGED
@@ -1,9 +1,8 @@
1
- import { L as DecimalText, R as RoundingMode, r as Money } from "./money-CbhsT0fB.cjs";
2
- import { n as priceRoundingParams, r as roundRetail, t as RetailRounding } from "./retail-Mqd-sPMF.cjs";
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-toyS3EMf.cjs";
4
- import { i as toReporting, n as ReportingTotal, r as storeFactors, t as FactorTable } from "./reporting-DEM97DhQ.cjs";
5
- import { n as MoneyByCurrency } from "./medusa-DuQ3-KoD.cjs";
6
- //#region src/fx/convert.d.ts
1
+ import { R as DecimalText, i as Money, z as RoundingMode } from "./money-BkMeYDEW.cjs";
2
+ import { n as priceRoundingParams, r as roundRetail, t as RetailRounding } from "./retail-CmEyJQOH.cjs";
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-CEakW3ia.cjs";
4
+ import { i as toReporting, n as ReportingTotal, r as storeFactors, t as FactorTable } from "./reporting-DFNyDBdi.cjs";
5
+ import { n as MoneyByCurrency } from "./medusa-DofdvIgQ.cjs";
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.d.ts CHANGED
@@ -1,9 +1,8 @@
1
- import { L as DecimalText, R as RoundingMode, r as Money } from "./money-CbhsT0fB.js";
2
- import { n as priceRoundingParams, r as roundRetail, t as RetailRounding } from "./retail-BwcFJcVN.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-CmeTGNex.js";
4
- import { i as toReporting, n as ReportingTotal, r as storeFactors, t as FactorTable } from "./reporting-5xby-Zas.js";
5
- import { n as MoneyByCurrency } from "./medusa-RwqxaDGq.js";
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 { E as resolveCurrency, J as gcd, M as resolveLocale, Q as describeValue, X as ratioToDecimal, Y as mulDiv, Z as MoneyError, ct as pow10, dt as toDecimalText, j as numberFormat, n as fromMajor, q as compareRatio, rt as formatDecimal, s as storedDecimal, t as boundedMoney, tt as decimalFromNumber, y as findCurrency, z as decimalOf } from "./money-CIgELekG.js";
2
- import { t as mulDivToUnit } from "./rounding-CVAPEfq_.js";
3
- import { t as hasOwnKey } from "./own-D7544D3k.js";
4
- import { r as moneyFor } from "./medusa-CmxCni-G.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-lLPViBuM.js";
6
- import { n as retailUnits, r as roundRetail, t as priceRoundingParams } from "./retail-BsvpNv1F.js";
7
- //#region src/fx/convert.ts
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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-D5-vlv0h.cjs");
3
- const require_rounding = require("./rounding-oZ832yTD.cjs");
4
- const require_allocate = require("./allocate-D7tm_t_o.cjs");
5
- const require_arithmetic = require("./arithmetic-Bq-8mSal.cjs");
6
- const require_own = require("./own-oP9DXFWv.cjs");
7
- const require_format = require("./format-BnA1aLJk.cjs");
8
- const require_iso_minor = require("./iso-minor--gQWI1f2.cjs");
9
- const require_medusa = require("./medusa-OJ2TJOxt.cjs");
10
- //#region src/data/countries.ts
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
- //#endregion
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;
@@ -291,6 +289,7 @@ exports.currencySymbol = require_money.currencySymbol;
291
289
  exports.decimalClamp = require_money.decimalClamp;
292
290
  exports.decimalCompare = require_money.decimalCompare;
293
291
  exports.decimalDivide = require_money.decimalDivide;
292
+ exports.decimalEquals = require_money.decimalEquals;
294
293
  exports.decimalMultiply = require_money.decimalMultiply;
295
294
  exports.decimalRound = require_money.decimalRound;
296
295
  exports.decimalSubtract = require_money.decimalSubtract;
@@ -305,6 +304,7 @@ exports.firstCurrency = require_money.firstCurrency;
305
304
  exports.formatMoney = require_format.formatMoney;
306
305
  exports.formatMoneyCompact = require_format.formatMoneyCompact;
307
306
  exports.formatMoneyRange = require_format.formatMoneyRange;
307
+ exports.formatStored = require_format.formatStored;
308
308
  exports.fromIsoMinor = require_iso_minor.fromIsoMinor;
309
309
  exports.fromMajor = require_money.fromMajor;
310
310
  exports.isCurrencyCode = require_money.isCurrencyCode;
@@ -331,6 +331,7 @@ exports.readCalculatedPrice = require_medusa.readCalculatedPrice;
331
331
  exports.readStored = require_money.readStored;
332
332
  exports.readStoredDecimal = require_medusa.readStoredDecimal;
333
333
  exports.readStoredField = require_medusa.readStoredField;
334
+ exports.readStoredLiteral = require_medusa.readStoredLiteral;
334
335
  exports.remaining = require_arithmetic.remaining;
335
336
  exports.roundMajor = require_rounding.roundMajor;
336
337
  exports.roundToUnit = require_rounding.roundToUnit;
package/dist/index.d.cts CHANGED
@@ -1,6 +1,5 @@
1
- import { A as localeForCurrency, C as currencyLabel, D as displayDigits, E as currencySymbol, F as storageDigits, I as storageScale, L as DecimalText, M as medusaEpsilon, N as parseCurrencyCode, O as firstCurrency, P as sameCurrency, R as RoundingMode, S as currencyInfo, T as currencyOptions, _ as CurrencyInfo, a as StoredAmount, b as StorageScale, c as fromMajor, d as readStored, f as toMajorDecimal, g as CurrencyCodeOptions, h as CurrencyCode, i as ReadStoredOptions, j as medusaCurrencyCode, k as isCurrencyCode, l as isStoredAmount, m as CURRENCIES, n as MajorDecimal, o as StoredAmountOptions, p as toMajorNumber, r as Money, s as ToMajorDecimalOptions, t as FromMajorOptions, u as money, v as CurrencyStatus, w as currencyName, x as currencyCode, y as FractionDigits } from "./money-CbhsT0fB.cjs";
2
- import { a as isPositiveAmount, c as readCalculatedPrice, d as toMedusaAmountInput, f as toMedusaRaw, i as ReadStoredDecimalOptions, l as readStoredDecimal, n as MoneyByCurrency, o as moneyByCurrency, r as PriceLike, s as moneyFor, t as MedusaRaw, u as readStoredField } from "./medusa-DuQ3-KoD.cjs";
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. */
@@ -190,6 +181,12 @@ export declare function decimalRound(a: DecimalText | string | number, options:
190
181
  }): DecimalText;
191
182
  /** `-1`, `0` or `1` as `a` is below, equal to or above `b`. */
192
183
  export declare function decimalCompare(a: DecimalText | string, b: DecimalText | string): -1 | 0 | 1;
184
+ /**
185
+ * Whether `a` and `b` are the same decimal, exactly (`'43.0'` equals `'43.00'` and `43`). Takes what
186
+ * `decimalCompare` takes, but never throws: anything that is not plain decimal text, a finite number
187
+ * or a bigint is never equal, not even to itself.
188
+ */
189
+ export declare function decimalEquals(a: unknown, b: unknown): boolean;
193
190
  /** `a` limited to `[min, max]` (either bound optional). `min` above `max` throws `amount_invalid`. */
194
191
  export declare function decimalClamp(a: DecimalText | string, bounds: {
195
192
  min?: DecimalText | string;
@@ -199,8 +196,6 @@ export declare function decimalClamp(a: DecimalText | string, bounds: {
199
196
  export declare function decimalWithin(a: DecimalText | string, b: DecimalText | string, tolerance: DecimalText | string, options?: {
200
197
  inclusive?: boolean;
201
198
  }): boolean;
202
- //#endregion
203
- //#region src/errors.d.ts
204
199
  /**
205
200
  * Why a money operation refused its input:
206
201
  * - `currency_invalid`: not a currency this package knows (or a retired one where only active codes are allowed)
@@ -225,8 +220,6 @@ export declare class MoneyError extends Error {
225
220
  readonly field?: string;
226
221
  constructor(code: MoneyErrorCode, message: string, options?: MoneyErrorOptions);
227
222
  }
228
- //#endregion
229
- //#region src/format.d.ts
230
223
  interface FormatMoneyOptions {
231
224
  /** Default `'en-US'`; an unsupported or malformed tag falls back to it. */
232
225
  locale?: string;
@@ -242,18 +235,34 @@ interface FormatMoneyOptions {
242
235
  signDisplay?: 'auto' | 'always' | 'exceptZero';
243
236
  /** Default `'-'`; `'−'` (U+2212) replaces the leading ASCII minus. */
244
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;
245
245
  }
246
+ /** The roundings `formatMoney` and `formatStored` take. */
247
+ type DisplayRounding = Extract<RoundingMode, 'half-up' | 'down'>;
246
248
  /**
247
249
  * Money for people: `'$1,234.50'`, `'¥1,200'`, `'KWD 1.005'`, `'-€5.00'`. Locale, currency
248
- * display, digits and sign are explicit options; the active app locale is the caller's to
249
- * 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>'`.
250
252
  */
251
253
  export declare function formatMoney(m: Money, options?: FormatMoneyOptions): string;
254
+ /**
255
+ * A stored amount that may be fractional (a Medusa total, 107.8175; a percentage promotion) for
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`.
258
+ * A number must be finite; text is plain decimal; an unknown currency throws `currency_invalid`.
259
+ */
260
+ export declare function formatStored(amount: number | DecimalText, currency: string, options?: FormatMoneyOptions): string;
252
261
  /**
253
262
  * Like `formatMoney` below `threshold` major units (default 10000, by magnitude); at or above
254
263
  * it, compact short notation with `maximumSignificantDigits` (default 3): `'$12.3K'`.
255
264
  */
256
- export declare function formatMoneyCompact(m: Money, options?: FormatMoneyOptions & {
265
+ export declare function formatMoneyCompact(m: Money, options?: Omit<FormatMoneyOptions, 'rounding'> & {
257
266
  threshold?: number;
258
267
  maximumSignificantDigits?: number;
259
268
  }): string;
@@ -266,8 +275,6 @@ export declare function formatMoneyRange(low: Money, high: Money | null, options
266
275
  * same rounding as `formatMoneyCompact` (`1234567` gives `'$1.23M'`).
267
276
  */
268
277
  export declare function moneyAxisFormatter(currency: string, options?: Pick<FormatMoneyOptions, 'locale' | 'currencyDisplay'>): (major: number) => string;
269
- //#endregion
270
- //#region src/iso-minor.d.ts
271
278
  /**
272
279
  * ISO minor units at the display digits: `round(major x 10^displayDigits)` with `rounding`
273
280
  * (default half-up). JPY 150000 gives 1500, KWD 1005 gives 1005, IQD 10000 gives 10, HUF
@@ -284,5 +291,4 @@ export declare function toIsoMinor(m: Money, options?: {
284
291
  export declare function fromIsoMinor(value: number | string, currency: string, options?: {
285
292
  digits?: FractionDigits;
286
293
  }): Money;
287
- //#endregion
288
- 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 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, 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 localeForCurrency, C as currencyLabel, D as displayDigits, E as currencySymbol, F as storageDigits, I as storageScale, L as DecimalText, M as medusaEpsilon, N as parseCurrencyCode, O as firstCurrency, P as sameCurrency, R as RoundingMode, S as currencyInfo, T as currencyOptions, _ as CurrencyInfo, a as StoredAmount, b as StorageScale, c as fromMajor, d as readStored, f as toMajorDecimal, g as CurrencyCodeOptions, h as CurrencyCode, i as ReadStoredOptions, j as medusaCurrencyCode, k as isCurrencyCode, l as isStoredAmount, m as CURRENCIES, n as MajorDecimal, o as StoredAmountOptions, p as toMajorNumber, r as Money, s as ToMajorDecimalOptions, t as FromMajorOptions, u as money, v as CurrencyStatus, w as currencyName, x as currencyCode, y as FractionDigits } from "./money-CbhsT0fB.js";
2
- import { a as isPositiveAmount, c as readCalculatedPrice, d as toMedusaAmountInput, f as toMedusaRaw, i as ReadStoredDecimalOptions, l as readStoredDecimal, n as MoneyByCurrency, o as moneyByCurrency, r as PriceLike, s as moneyFor, t as MedusaRaw, u as readStoredField } from "./medusa-RwqxaDGq.js";
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. */
@@ -190,6 +181,12 @@ export declare function decimalRound(a: DecimalText | string | number, options:
190
181
  }): DecimalText;
191
182
  /** `-1`, `0` or `1` as `a` is below, equal to or above `b`. */
192
183
  export declare function decimalCompare(a: DecimalText | string, b: DecimalText | string): -1 | 0 | 1;
184
+ /**
185
+ * Whether `a` and `b` are the same decimal, exactly (`'43.0'` equals `'43.00'` and `43`). Takes what
186
+ * `decimalCompare` takes, but never throws: anything that is not plain decimal text, a finite number
187
+ * or a bigint is never equal, not even to itself.
188
+ */
189
+ export declare function decimalEquals(a: unknown, b: unknown): boolean;
193
190
  /** `a` limited to `[min, max]` (either bound optional). `min` above `max` throws `amount_invalid`. */
194
191
  export declare function decimalClamp(a: DecimalText | string, bounds: {
195
192
  min?: DecimalText | string;
@@ -199,8 +196,6 @@ export declare function decimalClamp(a: DecimalText | string, bounds: {
199
196
  export declare function decimalWithin(a: DecimalText | string, b: DecimalText | string, tolerance: DecimalText | string, options?: {
200
197
  inclusive?: boolean;
201
198
  }): boolean;
202
- //#endregion
203
- //#region src/errors.d.ts
204
199
  /**
205
200
  * Why a money operation refused its input:
206
201
  * - `currency_invalid`: not a currency this package knows (or a retired one where only active codes are allowed)
@@ -225,8 +220,6 @@ export declare class MoneyError extends Error {
225
220
  readonly field?: string;
226
221
  constructor(code: MoneyErrorCode, message: string, options?: MoneyErrorOptions);
227
222
  }
228
- //#endregion
229
- //#region src/format.d.ts
230
223
  interface FormatMoneyOptions {
231
224
  /** Default `'en-US'`; an unsupported or malformed tag falls back to it. */
232
225
  locale?: string;
@@ -242,18 +235,34 @@ interface FormatMoneyOptions {
242
235
  signDisplay?: 'auto' | 'always' | 'exceptZero';
243
236
  /** Default `'-'`; `'−'` (U+2212) replaces the leading ASCII minus. */
244
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;
245
245
  }
246
+ /** The roundings `formatMoney` and `formatStored` take. */
247
+ type DisplayRounding = Extract<RoundingMode, 'half-up' | 'down'>;
246
248
  /**
247
249
  * Money for people: `'$1,234.50'`, `'¥1,200'`, `'KWD 1.005'`, `'-€5.00'`. Locale, currency
248
- * display, digits and sign are explicit options; the active app locale is the caller's to
249
- * 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>'`.
250
252
  */
251
253
  export declare function formatMoney(m: Money, options?: FormatMoneyOptions): string;
254
+ /**
255
+ * A stored amount that may be fractional (a Medusa total, 107.8175; a percentage promotion) for
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`.
258
+ * A number must be finite; text is plain decimal; an unknown currency throws `currency_invalid`.
259
+ */
260
+ export declare function formatStored(amount: number | DecimalText, currency: string, options?: FormatMoneyOptions): string;
252
261
  /**
253
262
  * Like `formatMoney` below `threshold` major units (default 10000, by magnitude); at or above
254
263
  * it, compact short notation with `maximumSignificantDigits` (default 3): `'$12.3K'`.
255
264
  */
256
- export declare function formatMoneyCompact(m: Money, options?: FormatMoneyOptions & {
265
+ export declare function formatMoneyCompact(m: Money, options?: Omit<FormatMoneyOptions, 'rounding'> & {
257
266
  threshold?: number;
258
267
  maximumSignificantDigits?: number;
259
268
  }): string;
@@ -266,8 +275,6 @@ export declare function formatMoneyRange(low: Money, high: Money | null, options
266
275
  * same rounding as `formatMoneyCompact` (`1234567` gives `'$1.23M'`).
267
276
  */
268
277
  export declare function moneyAxisFormatter(currency: string, options?: Pick<FormatMoneyOptions, 'locale' | 'currencyDisplay'>): (major: number) => string;
269
- //#endregion
270
- //#region src/iso-minor.d.ts
271
278
  /**
272
279
  * ISO minor units at the display digits: `round(major x 10^displayDigits)` with `rounding`
273
280
  * (default half-up). JPY 150000 gives 1500, KWD 1005 gives 1005, IQD 10000 gives 10, HUF
@@ -284,5 +291,4 @@ export declare function toIsoMinor(m: Money, options?: {
284
291
  export declare function fromIsoMinor(value: number | string, currency: string, options?: {
285
292
  digits?: FractionDigits;
286
293
  }): Money;
287
- //#endregion
288
- 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 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, 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, B as decimalRound, C as medusaCurrencyCode, D as sameCurrency, F as decimalClamp, G as parseDecimalText, H as decimalSum, I as decimalCompare, K as trimDecimalZeros, L as decimalDivide, O as storageDigits, P as assertDecimalLiteral, R as decimalMultiply, S as localeForCurrency, T as parseCurrencyCode, U as decimalWithin, V as decimalSubtract, W as isDecimalLiteral, Z as MoneyError, _ 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, r as isStoredAmount, u as CURRENCIES, v as displayDigits, w as medusaEpsilon, x as isCurrencyCode } from "./money-CIgELekG.js";
2
- import { i as roundToUnit, n as roundMajor } from "./rounding-CVAPEfq_.js";
3
- import { i as splitUnitPrice, r as allocateWaterfall, t as allocate } from "./allocate-CdnhvAda.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-C-Q_aI49.js";
5
- import { t as hasOwnKey } from "./own-D7544D3k.js";
6
- import { i as moneyAxisFormatter, n as formatMoneyCompact, r as formatMoneyRange, t as formatMoney } from "./format-BdB7LEIp.js";
7
- import { r as toIsoMinor, t as fromIsoMinor } from "./iso-minor-CtaiIifs.js";
8
- import { a as readStoredDecimal, c as toMedusaAmountInput, i as readCalculatedPrice, l as toMedusaRaw, n as moneyByCurrency, o as readStoredField, r as moneyFor, t as isPositiveAmount } from "./medusa-CmxCni-G.js";
9
- //#region src/data/countries.ts
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
- //#endregion
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
- export { CURRENCIES, MoneyError, add, allocate, allocateWaterfall, assertDecimalLiteral, clamp, compare, currencyCode, currencyInfo, currencyLabel, currencyName, currencyOptions, currencySymbol, decimalClamp, decimalCompare, decimalDivide, decimalMultiply, decimalRound, decimalSubtract, decimalSum, decimalWithin, defaultCurrencyForCountry, displayDigits, divide, equals, excessOver, firstCurrency, formatMoney, formatMoneyCompact, formatMoneyRange, 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, remaining, roundMajor, roundToUnit, sameCurrency, splitUnitPrice, storageDigits, storageScale, subtract, sum, toIsoMinor, toMajorDecimal, toMajorNumber, toMedusaAmountInput, toMedusaRaw, trimDecimalZeros, within };
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-D5-vlv0h.cjs");
3
- const require_number_text = require("./number-text-BpvN6NAo.cjs");
4
- const require_rate = require("./rate-DGPfB_jc.cjs");
5
- const require_amount = require("./amount-DHtvZSSm.cjs");
6
- //#region src/input/import.ts
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
- //#endregion
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
- //#endregion
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;