@amboras-dev/money 0.1.0 → 0.2.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 +14 -6
- package/dist/ai.cjs +4 -4
- package/dist/ai.d.cts +1 -1
- package/dist/ai.d.ts +1 -1
- package/dist/ai.js +4 -4
- package/dist/{allocate-D7tm_t_o.cjs → allocate-CZRg4TOP.cjs} +2 -2
- package/dist/{allocate-CdnhvAda.js → allocate-X7_jAtOj.js} +2 -2
- package/dist/{amount-DHtvZSSm.cjs → amount-BV0O-aN8.cjs} +3 -3
- package/dist/{amount-D7dj76nH.js → amount-BoYBMgK9.js} +3 -3
- package/dist/{arithmetic-C-Q_aI49.js → arithmetic-BhNwisjb.js} +3 -3
- package/dist/{arithmetic-Bq-8mSal.cjs → arithmetic-DjT4Kzgt.cjs} +3 -3
- package/dist/billing.cjs +2 -2
- package/dist/billing.d.cts +1 -1
- package/dist/billing.d.ts +1 -1
- package/dist/billing.js +2 -2
- package/dist/commerce.cjs +7 -7
- package/dist/commerce.d.cts +2 -2
- package/dist/commerce.d.ts +2 -2
- package/dist/commerce.js +7 -7
- package/dist/{format-BdB7LEIp.js → format-BdPnijvn.js} +11 -2
- package/dist/{format-BnA1aLJk.cjs → format-DLhno7eX.cjs} +16 -1
- package/dist/fx.cjs +5 -5
- package/dist/fx.d.cts +5 -5
- package/dist/fx.d.ts +5 -5
- package/dist/fx.js +5 -5
- package/dist/index.cjs +10 -7
- package/dist/index.d.cts +15 -3
- package/dist/index.d.ts +15 -3
- package/dist/index.js +8 -8
- package/dist/input.cjs +4 -4
- package/dist/input.d.cts +2 -2
- package/dist/input.d.ts +2 -2
- package/dist/input.js +4 -4
- package/dist/{iso-minor-CtaiIifs.js → iso-minor-CqkWDxHS.js} +1 -1
- package/dist/{iso-minor--gQWI1f2.cjs → iso-minor-wSwJN57T.cjs} +1 -1
- package/dist/{medusa-DuQ3-KoD.d.cts → medusa-4K8N1pUc.d.cts} +11 -2
- package/dist/{medusa-RwqxaDGq.d.ts → medusa-DBXJXXvF.d.ts} +11 -2
- package/dist/{medusa-CmxCni-G.js → medusa-DqJY1qpj.js} +17 -2
- package/dist/{medusa-OJ2TJOxt.cjs → medusa-lRY9xlsf.cjs} +22 -1
- package/dist/{money-CbhsT0fB.d.cts → money-B-3aFjNJ.d.cts} +19 -3
- package/dist/{money-CbhsT0fB.d.ts → money-B-3aFjNJ.d.ts} +19 -3
- package/dist/{money-D5-vlv0h.cjs → money-B3wH_Z4S.cjs} +35 -5
- package/dist/{money-CIgELekG.js → money-WhnGiI00.js} +18 -6
- package/dist/{number-text-BpvN6NAo.cjs → number-text-BWu67jUq.cjs} +1 -1
- package/dist/{number-text-C82oh6JB.js → number-text-DE-q4jO5.js} +1 -1
- package/dist/{percent-Dt8vNIAW.cjs → percent-C0InC2t2.cjs} +1 -1
- package/dist/{percent-CKVI_c-m.js → percent-D1VB9xXG.js} +1 -1
- package/dist/{rate-DGPfB_jc.cjs → rate-CVeMii4a.cjs} +1 -1
- package/dist/{rate-CmeTGNex.d.ts → rate-DBPiYgT1.d.ts} +1 -1
- package/dist/{rate-lLPViBuM.js → rate-DicStBue.js} +1 -1
- package/dist/{rate-toyS3EMf.d.cts → rate-tqK8ijG0.d.cts} +1 -1
- package/dist/{reporting-DEM97DhQ.d.cts → reporting-CG-ai2sM.d.cts} +2 -2
- package/dist/{reporting-5xby-Zas.d.ts → reporting-tpGJbqYp.d.ts} +2 -2
- package/dist/{retail-BsvpNv1F.js → retail-1mu888J1.js} +3 -3
- package/dist/{retail-Mqd-sPMF.d.cts → retail-C_BPLvMj.d.cts} +1 -1
- package/dist/{retail-DTk2XAMM.cjs → retail-Cml8YSKg.cjs} +3 -3
- package/dist/{retail-BwcFJcVN.d.ts → retail-DRUTTQoJ.d.ts} +1 -1
- package/dist/{rounding-oZ832yTD.cjs → rounding-DHBtNCHG.cjs} +1 -1
- package/dist/{rounding-CVAPEfq_.js → rounding-g9rvye0k.js} +1 -1
- package/dist/sql.cjs +3 -3
- package/dist/sql.d.cts +2 -2
- package/dist/sql.d.ts +2 -2
- package/dist/sql.js +3 -3
- package/dist/testing.cjs +33481 -4
- package/dist/testing.d.cts +31 -3
- package/dist/testing.d.ts +31 -3
- package/dist/testing.js +33481 -5
- package/dist/{wire-DQZ6fA3c.cjs → wire-Bhuut8cW.cjs} +259 -34
- package/dist/{wire-Cd4Q1Jmm.d.ts → wire-CaUN9Vf_.d.ts} +61 -21
- package/dist/{wire-CI3Sm1iC.js → wire-sW0yzqth.js} +248 -35
- package/dist/{wire-hWuixv3w.d.cts → wire-xjYXv4go.d.cts} +61 -21
- package/dist/wire.cjs +3 -1
- package/dist/wire.d.cts +2 -2
- package/dist/wire.d.ts +2 -2
- package/dist/wire.js +2 -2
- package/package.json +1 -1
package/dist/input.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { r as Rate } from "./rate-
|
|
1
|
+
import { R as DecimalText, b as FractionDigits, i as Money } from "./money-B-3aFjNJ.js";
|
|
2
|
+
import { r as Rate } from "./rate-DBPiYgT1.js";
|
|
3
3
|
//#region src/input/amount.d.ts
|
|
4
4
|
/** Why typed text is not an acceptable amount. */
|
|
5
5
|
type ParseFailureReason = 'empty' | 'unparseable' | 'too_many_decimals' | 'negative' | 'zero' | 'below_min' | 'above_max';
|
package/dist/input.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as readNumberText } from "./number-text-
|
|
3
|
-
import { c as rateFromDecimal, o as rate } from "./rate-
|
|
4
|
-
import { a as inputStep, i as inputPlaceholder, n as formatAmountInput, o as localeSeparators, r as groupDigits, s as parseAmountInput, t as decimalOfText } from "./amount-
|
|
1
|
+
import { B as decimalOf, Q as MoneyError, at as fractionDigitsOf, dt as roundToScale, it as formatDecimal, pt as toDecimalText, s as storedDecimal, tt as compareDecimal } from "./money-WhnGiI00.js";
|
|
2
|
+
import { n as readNumberText } from "./number-text-DE-q4jO5.js";
|
|
3
|
+
import { c as rateFromDecimal, o as rate } from "./rate-DicStBue.js";
|
|
4
|
+
import { a as inputStep, i as inputPlaceholder, n as formatAmountInput, o as localeSeparators, r as groupDigits, s as parseAmountInput, t as decimalOfText } from "./amount-BoYBMgK9.js";
|
|
5
5
|
//#region src/input/import.ts
|
|
6
6
|
/**
|
|
7
7
|
* Amount text from a file or a third party to canonical DecimalText (major units, exactly as
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { $ as describeValue, E as resolveCurrency, Q as MoneyError, X as mulDiv, k as storageExponent, lt as parseDecimal, s as storedDecimal, t as boundedMoney, ut as pow10 } from "./money-WhnGiI00.js";
|
|
2
2
|
//#region src/iso-minor.ts
|
|
3
3
|
/**
|
|
4
4
|
* Internal: stored units per ISO minor unit at `digits`, `storageScale / 10^digits` (100 for
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { R as DecimalText, a as ReadStoredOptions, i as Money, o as StoredAmount } from "./money-B-3aFjNJ.cjs";
|
|
2
2
|
//#region src/medusa.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* `row['raw_' + key]` when it is not null/undefined (a failure to read it is final: no
|
|
@@ -31,6 +31,15 @@ declare function readStoredDecimal(raw: unknown, options?: ReadStoredDecimalOpti
|
|
|
31
31
|
mode?: 'strict';
|
|
32
32
|
}): DecimalText;
|
|
33
33
|
declare function readStoredDecimal(raw: unknown, options?: ReadStoredDecimalOptions): DecimalText | null;
|
|
34
|
+
/**
|
|
35
|
+
* A Medusa amount's literal, verbatim (`'4300.00'` stays `'4300.00'`), for SQL and ledger columns:
|
|
36
|
+
* `.value ?? .numeric ?? raw` when it is an unsigned decimal literal without leading zeros
|
|
37
|
+
* (`isDecimalLiteral(text, { leadingZeros: false })`), else null. A number counts only while all
|
|
38
|
+
* its digits are there (finite; a safe integer when whole) and is spelled `String(n)`. Unlike
|
|
39
|
+
* `readStoredDecimal` it neither canonicalizes nor reads `.raw.value`, a bigint or a BigNumber's
|
|
40
|
+
* `valueOf`: the literal is passed on as Medusa holds it.
|
|
41
|
+
*/
|
|
42
|
+
declare function readStoredLiteral(raw: unknown): string | null;
|
|
34
43
|
/**
|
|
35
44
|
* A variant's `calculated_price` (a number, or an object read through
|
|
36
45
|
* `raw_calculated_amount` / `calculated_amount`) as Money in
|
|
@@ -75,4 +84,4 @@ declare function moneyFor(source: MoneyByCurrency | readonly PriceLike[], curren
|
|
|
75
84
|
/** Whether unknown Medusa input holds an amount above zero. `''`, null and garbage are false, never a throw. */
|
|
76
85
|
declare function isPositiveAmount(raw: unknown): boolean;
|
|
77
86
|
//#endregion
|
|
78
|
-
export { isPositiveAmount as a, readCalculatedPrice as c,
|
|
87
|
+
export { isPositiveAmount as a, readCalculatedPrice as c, readStoredLiteral as d, toMedusaAmountInput as f, ReadStoredDecimalOptions as i, readStoredDecimal as l, MoneyByCurrency as n, moneyByCurrency as o, toMedusaRaw as p, PriceLike as r, moneyFor as s, MedusaRaw as t, readStoredField as u };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { R as DecimalText, a as ReadStoredOptions, i as Money, o as StoredAmount } from "./money-B-3aFjNJ.js";
|
|
2
2
|
//#region src/medusa.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* `row['raw_' + key]` when it is not null/undefined (a failure to read it is final: no
|
|
@@ -31,6 +31,15 @@ declare function readStoredDecimal(raw: unknown, options?: ReadStoredDecimalOpti
|
|
|
31
31
|
mode?: 'strict';
|
|
32
32
|
}): DecimalText;
|
|
33
33
|
declare function readStoredDecimal(raw: unknown, options?: ReadStoredDecimalOptions): DecimalText | null;
|
|
34
|
+
/**
|
|
35
|
+
* A Medusa amount's literal, verbatim (`'4300.00'` stays `'4300.00'`), for SQL and ledger columns:
|
|
36
|
+
* `.value ?? .numeric ?? raw` when it is an unsigned decimal literal without leading zeros
|
|
37
|
+
* (`isDecimalLiteral(text, { leadingZeros: false })`), else null. A number counts only while all
|
|
38
|
+
* its digits are there (finite; a safe integer when whole) and is spelled `String(n)`. Unlike
|
|
39
|
+
* `readStoredDecimal` it neither canonicalizes nor reads `.raw.value`, a bigint or a BigNumber's
|
|
40
|
+
* `valueOf`: the literal is passed on as Medusa holds it.
|
|
41
|
+
*/
|
|
42
|
+
declare function readStoredLiteral(raw: unknown): string | null;
|
|
34
43
|
/**
|
|
35
44
|
* A variant's `calculated_price` (a number, or an object read through
|
|
36
45
|
* `raw_calculated_amount` / `calculated_amount`) as Money in
|
|
@@ -75,4 +84,4 @@ declare function moneyFor(source: MoneyByCurrency | readonly PriceLike[], curren
|
|
|
75
84
|
/** Whether unknown Medusa input holds an amount above zero. `''`, null and garbage are false, never a throw. */
|
|
76
85
|
declare function isPositiveAmount(raw: unknown): boolean;
|
|
77
86
|
//#endregion
|
|
78
|
-
export { isPositiveAmount as a, readCalculatedPrice as c,
|
|
87
|
+
export { isPositiveAmount as a, readCalculatedPrice as c, readStoredLiteral as d, toMedusaAmountInput as f, ReadStoredDecimalOptions as i, readStoredDecimal as l, MoneyByCurrency as n, moneyByCurrency as o, toMedusaRaw as p, PriceLike as r, moneyFor as s, MedusaRaw as t, readStoredField as u };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { D as sameCurrency, E as resolveCurrency,
|
|
1
|
+
import { $ as describeValue, B as decimalOf, D as sameCurrency, E as resolveCurrency, G as isDecimalLiteral, Q as MoneyError, a as money, b as firstCurrency, d as currencyCode, ft as strictNumberDecimal, i as medusaAmountDecimal, o as readStored, ot as isPositiveDecimal, pt as toDecimalText, r as isStoredAmount, s as storedDecimal } from "./money-WhnGiI00.js";
|
|
2
2
|
import { t as hasOwnKey } from "./own-D7544D3k.js";
|
|
3
3
|
//#region src/medusa.ts
|
|
4
4
|
const isObject = (value) => typeof value === "object" && value !== null;
|
|
@@ -21,6 +21,21 @@ function readStoredDecimal(raw, options = {}) {
|
|
|
21
21
|
throw new MoneyError("amount_invalid", `Invalid stored amount: ${describeValue(raw)}`, { field: options.field });
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
24
|
+
* A Medusa amount's literal, verbatim (`'4300.00'` stays `'4300.00'`), for SQL and ledger columns:
|
|
25
|
+
* `.value ?? .numeric ?? raw` when it is an unsigned decimal literal without leading zeros
|
|
26
|
+
* (`isDecimalLiteral(text, { leadingZeros: false })`), else null. A number counts only while all
|
|
27
|
+
* its digits are there (finite; a safe integer when whole) and is spelled `String(n)`. Unlike
|
|
28
|
+
* `readStoredDecimal` it neither canonicalizes nor reads `.raw.value`, a bigint or a BigNumber's
|
|
29
|
+
* `valueOf`: the literal is passed on as Medusa holds it.
|
|
30
|
+
*/
|
|
31
|
+
function readStoredLiteral(raw) {
|
|
32
|
+
const picked = isObject(raw) ? raw.value ?? raw.numeric ?? raw : raw;
|
|
33
|
+
let literal = null;
|
|
34
|
+
if (typeof picked === "string") literal = picked;
|
|
35
|
+
else if (typeof picked === "number" && strictNumberDecimal(picked) !== null) literal = String(picked);
|
|
36
|
+
return literal !== null && isDecimalLiteral(literal, { leadingZeros: false }) ? literal : null;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
24
39
|
* A variant's `calculated_price` (a number, or an object read through
|
|
25
40
|
* `raw_calculated_amount` / `calculated_amount`) as Money in
|
|
26
41
|
* `firstCurrency(calculated_price.currency_code, fallbackCurrency)`. Null on anything
|
|
@@ -98,4 +113,4 @@ function isPositiveAmount(raw) {
|
|
|
98
113
|
return value !== null && isPositiveDecimal(value);
|
|
99
114
|
}
|
|
100
115
|
//#endregion
|
|
101
|
-
export { readStoredDecimal as a,
|
|
116
|
+
export { readStoredDecimal as a, storedFieldValue as c, readCalculatedPrice as i, toMedusaAmountInput as l, moneyByCurrency as n, readStoredField as o, moneyFor as r, readStoredLiteral as s, isPositiveAmount as t, toMedusaRaw as u };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_money = require("./money-
|
|
1
|
+
const require_money = require("./money-B3wH_Z4S.cjs");
|
|
2
2
|
const require_own = require("./own-oP9DXFWv.cjs");
|
|
3
3
|
//#region src/medusa.ts
|
|
4
4
|
const isObject = (value) => typeof value === "object" && value !== null;
|
|
@@ -21,6 +21,21 @@ function readStoredDecimal(raw, options = {}) {
|
|
|
21
21
|
throw new require_money.MoneyError("amount_invalid", `Invalid stored amount: ${require_money.describeValue(raw)}`, { field: options.field });
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
24
|
+
* A Medusa amount's literal, verbatim (`'4300.00'` stays `'4300.00'`), for SQL and ledger columns:
|
|
25
|
+
* `.value ?? .numeric ?? raw` when it is an unsigned decimal literal without leading zeros
|
|
26
|
+
* (`isDecimalLiteral(text, { leadingZeros: false })`), else null. A number counts only while all
|
|
27
|
+
* its digits are there (finite; a safe integer when whole) and is spelled `String(n)`. Unlike
|
|
28
|
+
* `readStoredDecimal` it neither canonicalizes nor reads `.raw.value`, a bigint or a BigNumber's
|
|
29
|
+
* `valueOf`: the literal is passed on as Medusa holds it.
|
|
30
|
+
*/
|
|
31
|
+
function readStoredLiteral(raw) {
|
|
32
|
+
const picked = isObject(raw) ? raw.value ?? raw.numeric ?? raw : raw;
|
|
33
|
+
let literal = null;
|
|
34
|
+
if (typeof picked === "string") literal = picked;
|
|
35
|
+
else if (typeof picked === "number" && require_money.strictNumberDecimal(picked) !== null) literal = String(picked);
|
|
36
|
+
return literal !== null && require_money.isDecimalLiteral(literal, { leadingZeros: false }) ? literal : null;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
24
39
|
* A variant's `calculated_price` (a number, or an object read through
|
|
25
40
|
* `raw_calculated_amount` / `calculated_amount`) as Money in
|
|
26
41
|
* `firstCurrency(calculated_price.currency_code, fallbackCurrency)`. Null on anything
|
|
@@ -134,6 +149,12 @@ Object.defineProperty(exports, "readStoredField", {
|
|
|
134
149
|
return readStoredField;
|
|
135
150
|
}
|
|
136
151
|
});
|
|
152
|
+
Object.defineProperty(exports, "readStoredLiteral", {
|
|
153
|
+
enumerable: true,
|
|
154
|
+
get: function() {
|
|
155
|
+
return readStoredLiteral;
|
|
156
|
+
}
|
|
157
|
+
});
|
|
137
158
|
Object.defineProperty(exports, "storedFieldValue", {
|
|
138
159
|
enumerable: true,
|
|
139
160
|
get: function() {
|
|
@@ -145,6 +145,16 @@ interface Money {
|
|
|
145
145
|
readonly amount: StoredAmount;
|
|
146
146
|
readonly currency: CurrencyCode;
|
|
147
147
|
}
|
|
148
|
+
/**
|
|
149
|
+
* A stored amount that may hold a fraction of a storage unit, as Medusa keeps unrounded totals (a
|
|
150
|
+
* tax line can leave 107.8175): a finite number (a safe integer when whole) or plain decimal text
|
|
151
|
+
* (`readStoredDecimal`'s result). `Money` is always whole; the PSP codecs and comparators take
|
|
152
|
+
* either, and `formatStored` formats one.
|
|
153
|
+
*/
|
|
154
|
+
interface FractionalMoney {
|
|
155
|
+
readonly amount: number | DecimalText;
|
|
156
|
+
readonly currency: string;
|
|
157
|
+
}
|
|
148
158
|
interface FromMajorOptions {
|
|
149
159
|
/**
|
|
150
160
|
* More fraction digits than the currency stores: `'reject'` (default) throws
|
|
@@ -176,6 +186,11 @@ interface ToMajorDecimalOptions {
|
|
|
176
186
|
interface ReadStoredOptions {
|
|
177
187
|
/** `'strict'` (default) throws `amount_invalid` on a bad amount; `'lenient'` returns null. Never 0. */
|
|
178
188
|
mode?: 'strict' | 'lenient';
|
|
189
|
+
/**
|
|
190
|
+
* A fractional stored amount (Medusa's unrounded totals, 107.8175): `'reject'` (default) reads it
|
|
191
|
+
* as invalid; `'round'` rounds it half-up, exactly, to a whole storage unit (107.8175 gives 108).
|
|
192
|
+
*/
|
|
193
|
+
precision?: 'reject' | 'round';
|
|
179
194
|
/** Names the input field in errors. */
|
|
180
195
|
field?: string;
|
|
181
196
|
}
|
|
@@ -217,8 +232,9 @@ declare function toMajorNumber(m: Money, options?: ToMajorDecimalOptions): numbe
|
|
|
217
232
|
* A stored amount as Medusa hands it over (a number, a numeric string, a raw
|
|
218
233
|
* `{ value: '4300', precision: 20 }`, a live BigNumber) as Money. Precedence
|
|
219
234
|
* `.value ?? .raw.value ?? .raw_.value`, then `.numeric ?? .numeric_`, then the
|
|
220
|
-
* primitive. `'4300.00'` is accepted; a fractional
|
|
221
|
-
*
|
|
235
|
+
* primitive. `'4300.00'` is accepted; a fractional amount is rounded half-up to a whole
|
|
236
|
+
* storage unit with `precision: 'round'`; otherwise a fractional, non-finite, unsafe or
|
|
237
|
+
* unreadable amount throws `amount_invalid`, or gives null with `mode: 'lenient'` (never 0).
|
|
222
238
|
* An unknown currency always throws.
|
|
223
239
|
*/
|
|
224
240
|
declare function readStored(raw: unknown, currency: string, options: ReadStoredOptions & {
|
|
@@ -229,4 +245,4 @@ declare function readStored(raw: unknown, currency: string, options?: ReadStored
|
|
|
229
245
|
}): Money;
|
|
230
246
|
declare function readStored(raw: unknown, currency: string, options?: ReadStoredOptions): Money | null;
|
|
231
247
|
//#endregion
|
|
232
|
-
export {
|
|
248
|
+
export { isCurrencyCode as A, currencyInfo as C, currencySymbol as D, currencyOptions as E, sameCurrency as F, storageDigits as I, storageScale as L, medusaCurrencyCode as M, medusaEpsilon as N, displayDigits as O, parseCurrencyCode as P, DecimalText as R, currencyCode as S, currencyName as T, CurrencyCodeOptions as _, ReadStoredOptions as a, FractionDigits as b, ToMajorDecimalOptions as c, money as d, readStored as f, CurrencyCode as g, CURRENCIES as h, Money as i, localeForCurrency as j, firstCurrency as k, fromMajor as l, toMajorNumber as m, FromMajorOptions as n, StoredAmount as o, toMajorDecimal as p, MajorDecimal as r, StoredAmountOptions as s, FractionalMoney as t, isStoredAmount as u, CurrencyInfo as v, currencyLabel as w, StorageScale as x, CurrencyStatus as y, RoundingMode as z };
|
|
@@ -145,6 +145,16 @@ interface Money {
|
|
|
145
145
|
readonly amount: StoredAmount;
|
|
146
146
|
readonly currency: CurrencyCode;
|
|
147
147
|
}
|
|
148
|
+
/**
|
|
149
|
+
* A stored amount that may hold a fraction of a storage unit, as Medusa keeps unrounded totals (a
|
|
150
|
+
* tax line can leave 107.8175): a finite number (a safe integer when whole) or plain decimal text
|
|
151
|
+
* (`readStoredDecimal`'s result). `Money` is always whole; the PSP codecs and comparators take
|
|
152
|
+
* either, and `formatStored` formats one.
|
|
153
|
+
*/
|
|
154
|
+
interface FractionalMoney {
|
|
155
|
+
readonly amount: number | DecimalText;
|
|
156
|
+
readonly currency: string;
|
|
157
|
+
}
|
|
148
158
|
interface FromMajorOptions {
|
|
149
159
|
/**
|
|
150
160
|
* More fraction digits than the currency stores: `'reject'` (default) throws
|
|
@@ -176,6 +186,11 @@ interface ToMajorDecimalOptions {
|
|
|
176
186
|
interface ReadStoredOptions {
|
|
177
187
|
/** `'strict'` (default) throws `amount_invalid` on a bad amount; `'lenient'` returns null. Never 0. */
|
|
178
188
|
mode?: 'strict' | 'lenient';
|
|
189
|
+
/**
|
|
190
|
+
* A fractional stored amount (Medusa's unrounded totals, 107.8175): `'reject'` (default) reads it
|
|
191
|
+
* as invalid; `'round'` rounds it half-up, exactly, to a whole storage unit (107.8175 gives 108).
|
|
192
|
+
*/
|
|
193
|
+
precision?: 'reject' | 'round';
|
|
179
194
|
/** Names the input field in errors. */
|
|
180
195
|
field?: string;
|
|
181
196
|
}
|
|
@@ -217,8 +232,9 @@ declare function toMajorNumber(m: Money, options?: ToMajorDecimalOptions): numbe
|
|
|
217
232
|
* A stored amount as Medusa hands it over (a number, a numeric string, a raw
|
|
218
233
|
* `{ value: '4300', precision: 20 }`, a live BigNumber) as Money. Precedence
|
|
219
234
|
* `.value ?? .raw.value ?? .raw_.value`, then `.numeric ?? .numeric_`, then the
|
|
220
|
-
* primitive. `'4300.00'` is accepted; a fractional
|
|
221
|
-
*
|
|
235
|
+
* primitive. `'4300.00'` is accepted; a fractional amount is rounded half-up to a whole
|
|
236
|
+
* storage unit with `precision: 'round'`; otherwise a fractional, non-finite, unsafe or
|
|
237
|
+
* unreadable amount throws `amount_invalid`, or gives null with `mode: 'lenient'` (never 0).
|
|
222
238
|
* An unknown currency always throws.
|
|
223
239
|
*/
|
|
224
240
|
declare function readStored(raw: unknown, currency: string, options: ReadStoredOptions & {
|
|
@@ -229,4 +245,4 @@ declare function readStored(raw: unknown, currency: string, options?: ReadStored
|
|
|
229
245
|
}): Money;
|
|
230
246
|
declare function readStored(raw: unknown, currency: string, options?: ReadStoredOptions): Money | null;
|
|
231
247
|
//#endregion
|
|
232
|
-
export {
|
|
248
|
+
export { isCurrencyCode as A, currencyInfo as C, currencySymbol as D, currencyOptions as E, sameCurrency as F, storageDigits as I, storageScale as L, medusaCurrencyCode as M, medusaEpsilon as N, displayDigits as O, parseCurrencyCode as P, DecimalText as R, currencyCode as S, currencyName as T, CurrencyCodeOptions as _, ReadStoredOptions as a, FractionDigits as b, ToMajorDecimalOptions as c, money as d, readStored as f, CurrencyCode as g, CURRENCIES as h, Money as i, localeForCurrency as j, firstCurrency as k, fromMajor as l, toMajorNumber as m, FromMajorOptions as n, StoredAmount as o, toMajorDecimal as p, MajorDecimal as r, StoredAmountOptions as s, FractionalMoney as t, isStoredAmount as u, CurrencyInfo as v, currencyLabel as w, StorageScale as x, CurrencyStatus as y, RoundingMode as z };
|
|
@@ -276,6 +276,18 @@ function decimalRound(a, options) {
|
|
|
276
276
|
function decimalCompare(a, b) {
|
|
277
277
|
return compareDecimal(decimalOf(a), decimalOf(b));
|
|
278
278
|
}
|
|
279
|
+
/**
|
|
280
|
+
* Whether `a` and `b` are the same decimal, exactly (`'43.0'` equals `'43.00'` and `43`). Takes what
|
|
281
|
+
* `decimalCompare` takes, but never throws: anything that is not plain decimal text, a finite number
|
|
282
|
+
* or a bigint is never equal, not even to itself.
|
|
283
|
+
*/
|
|
284
|
+
function decimalEquals(a, b) {
|
|
285
|
+
try {
|
|
286
|
+
return compareDecimal(decimalOf(a), decimalOf(b)) === 0;
|
|
287
|
+
} catch {
|
|
288
|
+
return false;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
279
291
|
/** `a` limited to `[min, max]` (either bound optional). `min` above `max` throws `amount_invalid`. */
|
|
280
292
|
function decimalClamp(a, bounds) {
|
|
281
293
|
const value = decimalOf(a);
|
|
@@ -3553,16 +3565,16 @@ function medusaAmountDecimal(raw) {
|
|
|
3553
3565
|
return typeof primitive === "string" ? parseDecimal(primitive) : null;
|
|
3554
3566
|
}
|
|
3555
3567
|
const SAFE_LIMIT = BigInt(Number.MAX_SAFE_INTEGER);
|
|
3556
|
-
/** A stored integer from Medusa's shapes, or null when it is fractional, unsafe or unreadable. */
|
|
3557
|
-
function unwrapStored(raw) {
|
|
3568
|
+
/** A stored integer from Medusa's shapes (a fraction rounded half-up with `round`), or null when it is fractional, unsafe or unreadable. */
|
|
3569
|
+
function unwrapStored(raw, round) {
|
|
3558
3570
|
const parsed = medusaAmountDecimal(raw);
|
|
3559
|
-
if (!parsed || fractionDigitsOf(parsed) !== 0) return null;
|
|
3560
|
-
const whole = roundToScale(parsed, 0, "
|
|
3571
|
+
if (!parsed || !round && fractionDigitsOf(parsed) !== 0) return null;
|
|
3572
|
+
const whole = roundToScale(parsed, 0, "half-up");
|
|
3561
3573
|
return unitsWithin(whole, SAFE_LIMIT) ? Number(whole.units) : null;
|
|
3562
3574
|
}
|
|
3563
3575
|
function readStored(raw, currency, options = {}) {
|
|
3564
3576
|
const info = anyKnownCurrency(currency, options.field);
|
|
3565
|
-
const amount = unwrapStored(raw);
|
|
3577
|
+
const amount = unwrapStored(raw, options.precision === "round");
|
|
3566
3578
|
if (amount !== null) return storedFrom(amount, info);
|
|
3567
3579
|
if (options.mode === "lenient") return null;
|
|
3568
3580
|
throw new MoneyError("amount_invalid", `Invalid stored amount: ${describeValue(raw)}`, { field: options.field });
|
|
@@ -3670,6 +3682,12 @@ Object.defineProperty(exports, "decimalDivide", {
|
|
|
3670
3682
|
return decimalDivide;
|
|
3671
3683
|
}
|
|
3672
3684
|
});
|
|
3685
|
+
Object.defineProperty(exports, "decimalEquals", {
|
|
3686
|
+
enumerable: true,
|
|
3687
|
+
get: function() {
|
|
3688
|
+
return decimalEquals;
|
|
3689
|
+
}
|
|
3690
|
+
});
|
|
3673
3691
|
Object.defineProperty(exports, "decimalFromNumber", {
|
|
3674
3692
|
enumerable: true,
|
|
3675
3693
|
get: function() {
|
|
@@ -3832,6 +3850,12 @@ Object.defineProperty(exports, "multiplyDecimal", {
|
|
|
3832
3850
|
return multiplyDecimal;
|
|
3833
3851
|
}
|
|
3834
3852
|
});
|
|
3853
|
+
Object.defineProperty(exports, "normalizeDecimal", {
|
|
3854
|
+
enumerable: true,
|
|
3855
|
+
get: function() {
|
|
3856
|
+
return normalizeDecimal;
|
|
3857
|
+
}
|
|
3858
|
+
});
|
|
3835
3859
|
Object.defineProperty(exports, "numberFormat", {
|
|
3836
3860
|
enumerable: true,
|
|
3837
3861
|
get: function() {
|
|
@@ -3958,3 +3982,9 @@ Object.defineProperty(exports, "trimDecimalZeros", {
|
|
|
3958
3982
|
return trimDecimalZeros;
|
|
3959
3983
|
}
|
|
3960
3984
|
});
|
|
3985
|
+
Object.defineProperty(exports, "unitsWithin", {
|
|
3986
|
+
enumerable: true,
|
|
3987
|
+
get: function() {
|
|
3988
|
+
return unitsWithin;
|
|
3989
|
+
}
|
|
3990
|
+
});
|
|
@@ -276,6 +276,18 @@ function decimalRound(a, options) {
|
|
|
276
276
|
function decimalCompare(a, b) {
|
|
277
277
|
return compareDecimal(decimalOf(a), decimalOf(b));
|
|
278
278
|
}
|
|
279
|
+
/**
|
|
280
|
+
* Whether `a` and `b` are the same decimal, exactly (`'43.0'` equals `'43.00'` and `43`). Takes what
|
|
281
|
+
* `decimalCompare` takes, but never throws: anything that is not plain decimal text, a finite number
|
|
282
|
+
* or a bigint is never equal, not even to itself.
|
|
283
|
+
*/
|
|
284
|
+
function decimalEquals(a, b) {
|
|
285
|
+
try {
|
|
286
|
+
return compareDecimal(decimalOf(a), decimalOf(b)) === 0;
|
|
287
|
+
} catch {
|
|
288
|
+
return false;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
279
291
|
/** `a` limited to `[min, max]` (either bound optional). `min` above `max` throws `amount_invalid`. */
|
|
280
292
|
function decimalClamp(a, bounds) {
|
|
281
293
|
const value = decimalOf(a);
|
|
@@ -3553,19 +3565,19 @@ function medusaAmountDecimal(raw) {
|
|
|
3553
3565
|
return typeof primitive === "string" ? parseDecimal(primitive) : null;
|
|
3554
3566
|
}
|
|
3555
3567
|
const SAFE_LIMIT = BigInt(Number.MAX_SAFE_INTEGER);
|
|
3556
|
-
/** A stored integer from Medusa's shapes, or null when it is fractional, unsafe or unreadable. */
|
|
3557
|
-
function unwrapStored(raw) {
|
|
3568
|
+
/** A stored integer from Medusa's shapes (a fraction rounded half-up with `round`), or null when it is fractional, unsafe or unreadable. */
|
|
3569
|
+
function unwrapStored(raw, round) {
|
|
3558
3570
|
const parsed = medusaAmountDecimal(raw);
|
|
3559
|
-
if (!parsed || fractionDigitsOf(parsed) !== 0) return null;
|
|
3560
|
-
const whole = roundToScale(parsed, 0, "
|
|
3571
|
+
if (!parsed || !round && fractionDigitsOf(parsed) !== 0) return null;
|
|
3572
|
+
const whole = roundToScale(parsed, 0, "half-up");
|
|
3561
3573
|
return unitsWithin(whole, SAFE_LIMIT) ? Number(whole.units) : null;
|
|
3562
3574
|
}
|
|
3563
3575
|
function readStored(raw, currency, options = {}) {
|
|
3564
3576
|
const info = anyKnownCurrency(currency, options.field);
|
|
3565
|
-
const amount = unwrapStored(raw);
|
|
3577
|
+
const amount = unwrapStored(raw, options.precision === "round");
|
|
3566
3578
|
if (amount !== null) return storedFrom(amount, info);
|
|
3567
3579
|
if (options.mode === "lenient") return null;
|
|
3568
3580
|
throw new MoneyError("amount_invalid", `Invalid stored amount: ${describeValue(raw)}`, { field: options.field });
|
|
3569
3581
|
}
|
|
3570
3582
|
//#endregion
|
|
3571
|
-
export {
|
|
3583
|
+
export { describeValue as $, storageScale as A, decimalOf as B, medusaCurrencyCode as C, sameCurrency as D, resolveCurrency as E, decimalClamp as F, isDecimalLiteral as G, decimalSubtract as H, decimalCompare as I, compareRatio as J, parseDecimalText as K, decimalDivide as L, resolveLocale as M, separatorsOf as N, storageDigits as O, assertDecimalLiteral as P, MoneyError as Q, decimalEquals as R, localeForCurrency as S, parseCurrencyCode as T, decimalSum as U, decimalRound as V, decimalWithin as W, mulDiv as X, gcd as Y, ratioToDecimal as Z, currencySymbol as _, money as a, fractionDigitsOf as at, firstCurrency as b, toMajorDecimal as c, normalizeDecimal as ct, currencyCode as d, roundToScale as dt, addDecimal as et, currencyInfo as f, strictNumberDecimal as ft, currencyOptions as g, currencyName as h, medusaAmountDecimal as i, formatDecimal as it, numberFormat as j, storageExponent as k, toMajorNumber as l, parseDecimal as lt, currencyMarks as m, unitsWithin as mt, fromMajor as n, decimalFromNumber as nt, readStored as o, isPositiveDecimal as ot, currencyLabel as p, toDecimalText as pt, trimDecimalZeros as q, isStoredAmount as r, divRound as rt, storedDecimal as s, multiplyDecimal as st, boundedMoney as t, compareDecimal as tt, CURRENCIES as u, pow10 as ut, displayDigits as v, medusaEpsilon as w, isCurrencyCode as x, findCurrency as y, decimalMultiply as z };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { $ as describeValue, E as resolveCurrency, dt as roundToScale, m as currencyMarks } from "./money-WhnGiI00.js";
|
|
2
2
|
//#region src/internal/number-text.ts
|
|
3
3
|
const MINUS = /^[-−]/;
|
|
4
4
|
const escapeRegExp = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_money = require("./money-
|
|
1
|
+
const require_money = require("./money-B3wH_Z4S.cjs");
|
|
2
2
|
//#region src/internal/percent.ts
|
|
3
3
|
/** 100% for a percent written with `scale` fraction digits: the denominator of its units. */
|
|
4
4
|
function hundredPercent(scale) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { X as
|
|
1
|
+
import { X as mulDiv, Z as ratioToDecimal, ut as pow10 } from "./money-WhnGiI00.js";
|
|
2
2
|
//#region src/internal/percent.ts
|
|
3
3
|
/** 100% for a percent written with `scale` fraction digits: the denominator of its units. */
|
|
4
4
|
function hundredPercent(scale) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_money = require("./money-
|
|
1
|
+
const require_money = require("./money-B3wH_Z4S.cjs");
|
|
2
2
|
const require_own = require("./own-oP9DXFWv.cjs");
|
|
3
3
|
//#region src/fx/rate.ts
|
|
4
4
|
/** Denominator of every locked rate (`store_currency_rate.rate_denominator` default): 7 decimals. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { $ as describeValue, B as decimalOf, J as compareRatio, Q as MoneyError, Z as ratioToDecimal, dt as roundToScale, lt as parseDecimal, pt as toDecimalText, ut as pow10 } from "./money-WhnGiI00.js";
|
|
2
2
|
import { t as hasOwnKey } from "./own-D7544D3k.js";
|
|
3
3
|
//#region src/fx/rate.ts
|
|
4
4
|
/** Denominator of every locked rate (`store_currency_rate.rate_denominator` default): 7 decimals. */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as RateRow } from "./rate-
|
|
1
|
+
import { R as DecimalText, g as CurrencyCode, i as Money } from "./money-B-3aFjNJ.cjs";
|
|
2
|
+
import { a as RateRow } from "./rate-tqK8ijG0.cjs";
|
|
3
3
|
//#region src/fx/reporting.d.ts
|
|
4
4
|
/** `factors[lower code]` takes a stored amount in that currency to a stored amount in `base`. */
|
|
5
5
|
interface FactorTable {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as RateRow } from "./rate-
|
|
1
|
+
import { R as DecimalText, g as CurrencyCode, i as Money } from "./money-B-3aFjNJ.js";
|
|
2
|
+
import { a as RateRow } from "./rate-DBPiYgT1.js";
|
|
3
3
|
//#region src/fx/reporting.d.ts
|
|
4
4
|
/** `factors[lower code]` takes a stored amount in that currency to a stored amount in `base`. */
|
|
5
5
|
interface FactorTable {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as unitSize, t as mulDivToUnit } from "./rounding-
|
|
3
|
-
import { r as percentOfUnits } from "./percent-
|
|
1
|
+
import { $ as describeValue, E as resolveCurrency, Q as MoneyError, rt as divRound, s as storedDecimal, t as boundedMoney } from "./money-WhnGiI00.js";
|
|
2
|
+
import { a as unitSize, t as mulDivToUnit } from "./rounding-g9rvye0k.js";
|
|
3
|
+
import { r as percentOfUnits } from "./percent-D1VB9xXG.js";
|
|
4
4
|
//#region src/fx/retail.ts
|
|
5
5
|
const RETAIL_ROUNDINGS = [
|
|
6
6
|
"none",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
const require_money = require("./money-
|
|
2
|
-
const require_rounding = require("./rounding-
|
|
3
|
-
const require_percent = require("./percent-
|
|
1
|
+
const require_money = require("./money-B3wH_Z4S.cjs");
|
|
2
|
+
const require_rounding = require("./rounding-DHBtNCHG.cjs");
|
|
3
|
+
const require_percent = require("./percent-C0InC2t2.cjs");
|
|
4
4
|
//#region src/fx/retail.ts
|
|
5
5
|
const RETAIL_ROUNDINGS = [
|
|
6
6
|
"none",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { B as decimalOf, E as resolveCurrency, Q as MoneyError, X as mulDiv, dt as roundToScale, it as formatDecimal, s as storedDecimal, t as boundedMoney, ut as pow10 } from "./money-WhnGiI00.js";
|
|
2
2
|
//#region src/rounding.ts
|
|
3
3
|
/** Internal: the size of `unit` in storage units. */
|
|
4
4
|
function unitSize(info, unit) {
|
package/dist/sql.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_money = require("./money-
|
|
3
|
-
const require_rate = require("./rate-
|
|
4
|
-
const require_retail = require("./retail-
|
|
2
|
+
const require_money = require("./money-B3wH_Z4S.cjs");
|
|
3
|
+
const require_rate = require("./rate-CVeMii4a.cjs");
|
|
4
|
+
const require_retail = require("./retail-Cml8YSKg.cjs");
|
|
5
5
|
//#region src/sql/guard.ts
|
|
6
6
|
const STATEMENT_BREAKERS = /;|--|\/\*|\*\/|\0/;
|
|
7
7
|
const refuse = (name, value) => new require_money.MoneyError("parse", `${name} must be a SQL expression written in code, got ${require_money.describeValue(value)}`);
|
package/dist/sql.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { r as Rate } from "./rate-
|
|
2
|
-
import { t as FactorTable } from "./reporting-
|
|
1
|
+
import { r as Rate } from "./rate-tqK8ijG0.cjs";
|
|
2
|
+
import { t as FactorTable } from "./reporting-CG-ai2sM.cjs";
|
|
3
3
|
//#region src/sql/guard.d.ts
|
|
4
4
|
type SqlBinding = string | number;
|
|
5
5
|
/** Text with knex `?` placeholders and the values they bind, in order: `knex.raw(f.sql, f.bindings)`. */
|
package/dist/sql.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { r as Rate } from "./rate-
|
|
2
|
-
import { t as FactorTable } from "./reporting-
|
|
1
|
+
import { r as Rate } from "./rate-DBPiYgT1.js";
|
|
2
|
+
import { t as FactorTable } from "./reporting-tpGJbqYp.js";
|
|
3
3
|
//#region src/sql/guard.d.ts
|
|
4
4
|
type SqlBinding = string | number;
|
|
5
5
|
/** Text with knex `?` placeholders and the values they bind, in order: `knex.raw(f.sql, f.bindings)`. */
|
package/dist/sql.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { A as storageScale, E as resolveCurrency, Q as
|
|
2
|
-
import { r as checkRate } from "./rate-
|
|
3
|
-
import { t as priceRoundingParams } from "./retail-
|
|
1
|
+
import { $ as describeValue, A as storageScale, E as resolveCurrency, Q as MoneyError, u as CURRENCIES } from "./money-WhnGiI00.js";
|
|
2
|
+
import { r as checkRate } from "./rate-DicStBue.js";
|
|
3
|
+
import { t as priceRoundingParams } from "./retail-1mu888J1.js";
|
|
4
4
|
//#region src/sql/guard.ts
|
|
5
5
|
const STATEMENT_BREAKERS = /;|--|\/\*|\*\/|\0/;
|
|
6
6
|
const refuse = (name, value) => new MoneyError("parse", `${name} must be a SQL expression written in code, got ${describeValue(value)}`);
|