@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.
- package/README.md +25 -10
- 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-D7tm_t_o.cjs → allocate-AusholrC.cjs} +3 -4
- package/dist/{allocate-CdnhvAda.js → allocate-BBRfdaSC.js} +3 -4
- package/dist/{amount-DHtvZSSm.cjs → amount-CwFzcxUl.cjs} +29 -12
- package/dist/{amount-D7dj76nH.js → amount-DHFOK2Yd.js} +29 -12
- package/dist/{arithmetic-C-Q_aI49.js → arithmetic-C97-YafD.js} +4 -5
- package/dist/{arithmetic-Bq-8mSal.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-BnA1aLJk.cjs → format-92fzvTXY.cjs} +21 -6
- package/dist/{format-BdB7LEIp.js → format-BJC513u4.js} +16 -7
- 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 +13 -12
- package/dist/index.d.cts +28 -22
- package/dist/index.d.ts +28 -22
- package/dist/index.js +11 -13
- 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--gQWI1f2.cjs → iso-minor-DyNjT9A1.cjs} +2 -3
- package/dist/{iso-minor-CtaiIifs.js → iso-minor-odkY-e6I.js} +2 -3
- package/dist/{medusa-OJ2TJOxt.cjs → medusa-CzVK0bth.cjs} +24 -4
- package/dist/{medusa-DuQ3-KoD.d.cts → medusa-DofdvIgQ.d.cts} +11 -4
- package/dist/{medusa-RwqxaDGq.d.ts → medusa-DrbYmD2Y.d.ts} +11 -4
- package/dist/{medusa-CmxCni-G.js → medusa-pKGlImn9.js} +19 -5
- package/dist/{money-CbhsT0fB.d.cts → money-BkMeYDEW.d.cts} +19 -9
- package/dist/{money-CbhsT0fB.d.ts → money-BkMeYDEW.d.ts} +19 -9
- package/dist/{money-CIgELekG.js → money-BxbAw7BP.js} +25 -21
- package/dist/{money-D5-vlv0h.cjs → money-DWBjuuEK.cjs} +42 -20
- package/dist/{number-text-C82oh6JB.js → number-text-Bj-gZXiF.js} +3 -4
- package/dist/{number-text-BpvN6NAo.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-CKVI_c-m.js → percent-CB3Ixjc_.js} +2 -3
- package/dist/{percent-Dt8vNIAW.cjs → percent-DABHiSBs.cjs} +2 -3
- package/dist/{rate-CmeTGNex.d.ts → rate-BvvZUdSu.d.ts} +1 -3
- package/dist/{rate-toyS3EMf.d.cts → rate-CEakW3ia.d.cts} +1 -3
- package/dist/{rate-DGPfB_jc.cjs → rate-CEjWTATc.cjs} +3 -4
- package/dist/{rate-lLPViBuM.js → rate-D6S2_wgZ.js} +3 -4
- package/dist/{reporting-5xby-Zas.d.ts → reporting-DFNyDBdi.d.cts} +2 -4
- package/dist/{reporting-DEM97DhQ.d.cts → reporting-jIBILvnr.d.ts} +2 -4
- package/dist/{retail-BwcFJcVN.d.ts → retail-B04CjW3b.d.ts} +1 -3
- package/dist/{retail-DTk2XAMM.cjs → retail-CYGPU4ea.cjs} +4 -5
- package/dist/{retail-Mqd-sPMF.d.cts → retail-CmEyJQOH.d.cts} +1 -3
- package/dist/{retail-BsvpNv1F.js → retail-DXgs11ov.js} +4 -5
- package/dist/{rounding-oZ832yTD.cjs → rounding-4QKTRbMQ.cjs} +2 -3
- package/dist/{rounding-CVAPEfq_.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 +72675 -12
- package/dist/testing.d.cts +46 -11
- package/dist/testing.d.ts +46 -11
- package/dist/testing.js +72674 -13
- package/dist/{wire-CI3Sm1iC.js → wire-B4QU8O3W.js} +584 -114
- package/dist/wire-CVNicirK.d.ts +428 -0
- package/dist/wire-CtNJmWVP.d.cts +428 -0
- package/dist/{wire-DQZ6fA3c.cjs → wire-u2tmHY0Y.cjs} +649 -113
- package/dist/wire.cjs +12 -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/wire-Cd4Q1Jmm.d.ts +0 -269
- package/dist/wire-hWuixv3w.d.cts +0 -269
package/dist/input.d.cts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
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 {
|
|
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 };
|
package/dist/input.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
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-
|
|
5
|
-
|
|
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-BxbAw7BP.js";
|
|
2
|
+
import { n as readNumberText } from "./number-text-Bj-gZXiF.js";
|
|
3
|
+
import { c as rateFromDecimal, o as rate } from "./rate-D6S2_wgZ.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-DHFOK2Yd.js";
|
|
5
|
+
// src/input/import.ts
|
|
6
6
|
/**
|
|
7
7
|
* Amount text from a file or a third party to canonical DecimalText (major units, exactly as
|
|
8
8
|
* written: `'1.299,00'` gives `'1299'`), or null when it is not an amount (empty, exponent,
|
|
@@ -52,8 +52,7 @@ function parseDecimalInput(text, options) {
|
|
|
52
52
|
value: toDecimalText(value)
|
|
53
53
|
};
|
|
54
54
|
}
|
|
55
|
-
|
|
56
|
-
//#region src/input/percent-rate.ts
|
|
55
|
+
// src/input/percent-rate.ts
|
|
57
56
|
/**
|
|
58
57
|
* A typed percent (`'20'`, `'12.5'`, `'12,5 %'` in de-DE) as DecimalText. A `%` before or after
|
|
59
58
|
* the number is allowed. Default range 0..100 with 2 decimals; below 0 (with a non-negative
|
|
@@ -102,8 +101,7 @@ function parseRateInput(text, options = {}) {
|
|
|
102
101
|
throw error;
|
|
103
102
|
}
|
|
104
103
|
}
|
|
105
|
-
|
|
106
|
-
//#region src/input/template.ts
|
|
104
|
+
// src/input/template.ts
|
|
107
105
|
const DEFAULT_TEMPLATE = Object.freeze({
|
|
108
106
|
prefix: "",
|
|
109
107
|
suffix: "",
|
|
@@ -149,5 +147,4 @@ function formatWithTemplate(m, template) {
|
|
|
149
147
|
const tail = fraction === void 0 ? "" : `${template.decimalSeparator}${fraction}`;
|
|
150
148
|
return `${template.prefix}${negative ? "-" : ""}${grouped}${tail}${template.suffix}`;
|
|
151
149
|
}
|
|
152
|
-
//#endregion
|
|
153
150
|
export { formatAmountInput, formatWithTemplate, inputPlaceholder, inputStep, moneyTemplateOf, parseAmountInput, parseDecimalInput, parseImportAmount, parsePercentInput, parseRateInput };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const require_money = require("./money-
|
|
2
|
-
|
|
1
|
+
const require_money = require("./money-DWBjuuEK.cjs");
|
|
2
|
+
// src/iso-minor.ts
|
|
3
3
|
/**
|
|
4
4
|
* Internal: stored units per ISO minor unit at `digits`, `storageScale / 10^digits` (100 for
|
|
5
5
|
* a zero-digit count on a x100 currency, 1 when the digits match the storage exponent).
|
|
@@ -44,7 +44,6 @@ function fromIsoMinor(value, currency, options = {}) {
|
|
|
44
44
|
if (BigInt(integer) % excess !== 0n) throw new require_money.MoneyError("precision", `${integer} at ${digits} digits is not a whole ${info.code} storage unit`);
|
|
45
45
|
return require_money.boundedMoney(BigInt(integer) / excess, info);
|
|
46
46
|
}
|
|
47
|
-
//#endregion
|
|
48
47
|
Object.defineProperty(exports, "fromIsoMinor", {
|
|
49
48
|
enumerable: true,
|
|
50
49
|
get: function() {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
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-BxbAw7BP.js";
|
|
2
|
+
// src/iso-minor.ts
|
|
3
3
|
/**
|
|
4
4
|
* Internal: stored units per ISO minor unit at `digits`, `storageScale / 10^digits` (100 for
|
|
5
5
|
* a zero-digit count on a x100 currency, 1 when the digits match the storage exponent).
|
|
@@ -44,5 +44,4 @@ function fromIsoMinor(value, currency, options = {}) {
|
|
|
44
44
|
if (BigInt(integer) % excess !== 0n) throw new MoneyError("precision", `${integer} at ${digits} digits is not a whole ${info.code} storage unit`);
|
|
45
45
|
return boundedMoney(BigInt(integer) / excess, info);
|
|
46
46
|
}
|
|
47
|
-
//#endregion
|
|
48
47
|
export { isoMinorFactor as n, toIsoMinor as r, fromIsoMinor as t };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
const require_money = require("./money-
|
|
2
|
-
const require_own = require("./own-
|
|
3
|
-
|
|
1
|
+
const require_money = require("./money-DWBjuuEK.cjs");
|
|
2
|
+
const require_own = require("./own-C5imDkyB.cjs");
|
|
3
|
+
// src/medusa.ts
|
|
4
4
|
const isObject = (value) => typeof value === "object" && value !== null;
|
|
5
5
|
/** Internal: `row['raw_' + key]` when it is not null/undefined, else `row[key]` (undefined for a non-object row). */
|
|
6
6
|
function storedFieldValue(row, key) {
|
|
@@ -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
|
|
@@ -97,7 +112,6 @@ function isPositiveAmount(raw) {
|
|
|
97
112
|
const value = require_money.medusaAmountDecimal(raw);
|
|
98
113
|
return value !== null && require_money.isPositiveDecimal(value);
|
|
99
114
|
}
|
|
100
|
-
//#endregion
|
|
101
115
|
Object.defineProperty(exports, "isPositiveAmount", {
|
|
102
116
|
enumerable: true,
|
|
103
117
|
get: function() {
|
|
@@ -134,6 +148,12 @@ Object.defineProperty(exports, "readStoredField", {
|
|
|
134
148
|
return readStoredField;
|
|
135
149
|
}
|
|
136
150
|
});
|
|
151
|
+
Object.defineProperty(exports, "readStoredLiteral", {
|
|
152
|
+
enumerable: true,
|
|
153
|
+
get: function() {
|
|
154
|
+
return readStoredLiteral;
|
|
155
|
+
}
|
|
156
|
+
});
|
|
137
157
|
Object.defineProperty(exports, "storedFieldValue", {
|
|
138
158
|
enumerable: true,
|
|
139
159
|
get: function() {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
//#region src/medusa.d.ts
|
|
1
|
+
import { R as DecimalText, a as ReadStoredOptions, i as Money, o as StoredAmount } from "./money-BkMeYDEW.cjs";
|
|
3
2
|
/**
|
|
4
3
|
* `row['raw_' + key]` when it is not null/undefined (a failure to read it is final: no
|
|
5
4
|
* fallback to the lossy plain key), else `row[key]`, read like `readStored`.
|
|
@@ -31,6 +30,15 @@ declare function readStoredDecimal(raw: unknown, options?: ReadStoredDecimalOpti
|
|
|
31
30
|
mode?: 'strict';
|
|
32
31
|
}): DecimalText;
|
|
33
32
|
declare function readStoredDecimal(raw: unknown, options?: ReadStoredDecimalOptions): DecimalText | null;
|
|
33
|
+
/**
|
|
34
|
+
* A Medusa amount's literal, verbatim (`'4300.00'` stays `'4300.00'`), for SQL and ledger columns:
|
|
35
|
+
* `.value ?? .numeric ?? raw` when it is an unsigned decimal literal without leading zeros
|
|
36
|
+
* (`isDecimalLiteral(text, { leadingZeros: false })`), else null. A number counts only while all
|
|
37
|
+
* its digits are there (finite; a safe integer when whole) and is spelled `String(n)`. Unlike
|
|
38
|
+
* `readStoredDecimal` it neither canonicalizes nor reads `.raw.value`, a bigint or a BigNumber's
|
|
39
|
+
* `valueOf`: the literal is passed on as Medusa holds it.
|
|
40
|
+
*/
|
|
41
|
+
declare function readStoredLiteral(raw: unknown): string | null;
|
|
34
42
|
/**
|
|
35
43
|
* A variant's `calculated_price` (a number, or an object read through
|
|
36
44
|
* `raw_calculated_amount` / `calculated_amount`) as Money in
|
|
@@ -74,5 +82,4 @@ interface PriceLike {
|
|
|
74
82
|
declare function moneyFor(source: MoneyByCurrency | readonly PriceLike[], currency: string): Money | null;
|
|
75
83
|
/** Whether unknown Medusa input holds an amount above zero. `''`, null and garbage are false, never a throw. */
|
|
76
84
|
declare function isPositiveAmount(raw: unknown): boolean;
|
|
77
|
-
|
|
78
|
-
export { isPositiveAmount as a, readCalculatedPrice as c, toMedusaAmountInput as d, toMedusaRaw as f, ReadStoredDecimalOptions as i, readStoredDecimal as l, MoneyByCurrency as n, moneyByCurrency as o, PriceLike as r, moneyFor as s, MedusaRaw as t, readStoredField as u };
|
|
85
|
+
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,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
//#region src/medusa.d.ts
|
|
1
|
+
import { R as DecimalText, a as ReadStoredOptions, i as Money, o as StoredAmount } from "./money-BkMeYDEW.js";
|
|
3
2
|
/**
|
|
4
3
|
* `row['raw_' + key]` when it is not null/undefined (a failure to read it is final: no
|
|
5
4
|
* fallback to the lossy plain key), else `row[key]`, read like `readStored`.
|
|
@@ -31,6 +30,15 @@ declare function readStoredDecimal(raw: unknown, options?: ReadStoredDecimalOpti
|
|
|
31
30
|
mode?: 'strict';
|
|
32
31
|
}): DecimalText;
|
|
33
32
|
declare function readStoredDecimal(raw: unknown, options?: ReadStoredDecimalOptions): DecimalText | null;
|
|
33
|
+
/**
|
|
34
|
+
* A Medusa amount's literal, verbatim (`'4300.00'` stays `'4300.00'`), for SQL and ledger columns:
|
|
35
|
+
* `.value ?? .numeric ?? raw` when it is an unsigned decimal literal without leading zeros
|
|
36
|
+
* (`isDecimalLiteral(text, { leadingZeros: false })`), else null. A number counts only while all
|
|
37
|
+
* its digits are there (finite; a safe integer when whole) and is spelled `String(n)`. Unlike
|
|
38
|
+
* `readStoredDecimal` it neither canonicalizes nor reads `.raw.value`, a bigint or a BigNumber's
|
|
39
|
+
* `valueOf`: the literal is passed on as Medusa holds it.
|
|
40
|
+
*/
|
|
41
|
+
declare function readStoredLiteral(raw: unknown): string | null;
|
|
34
42
|
/**
|
|
35
43
|
* A variant's `calculated_price` (a number, or an object read through
|
|
36
44
|
* `raw_calculated_amount` / `calculated_amount`) as Money in
|
|
@@ -74,5 +82,4 @@ interface PriceLike {
|
|
|
74
82
|
declare function moneyFor(source: MoneyByCurrency | readonly PriceLike[], currency: string): Money | null;
|
|
75
83
|
/** Whether unknown Medusa input holds an amount above zero. `''`, null and garbage are false, never a throw. */
|
|
76
84
|
declare function isPositiveAmount(raw: unknown): boolean;
|
|
77
|
-
|
|
78
|
-
export { isPositiveAmount as a, readCalculatedPrice as c, toMedusaAmountInput as d, toMedusaRaw as f, ReadStoredDecimalOptions as i, readStoredDecimal as l, MoneyByCurrency as n, moneyByCurrency as o, PriceLike as r, moneyFor as s, MedusaRaw as t, readStoredField as u };
|
|
85
|
+
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,6 +1,6 @@
|
|
|
1
|
-
import { D as sameCurrency, E as resolveCurrency,
|
|
2
|
-
import { t as hasOwnKey } from "./own-
|
|
3
|
-
|
|
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-BxbAw7BP.js";
|
|
2
|
+
import { t as hasOwnKey } from "./own-DHxqIYqL.js";
|
|
3
|
+
// src/medusa.ts
|
|
4
4
|
const isObject = (value) => typeof value === "object" && value !== null;
|
|
5
5
|
/** Internal: `row['raw_' + key]` when it is not null/undefined, else `row[key]` (undefined for a non-object row). */
|
|
6
6
|
function storedFieldValue(row, key) {
|
|
@@ -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
|
|
@@ -97,5 +112,4 @@ function isPositiveAmount(raw) {
|
|
|
97
112
|
const value = medusaAmountDecimal(raw);
|
|
98
113
|
return value !== null && isPositiveDecimal(value);
|
|
99
114
|
}
|
|
100
|
-
|
|
101
|
-
export { readStoredDecimal as a, toMedusaAmountInput as c, readCalculatedPrice as i, toMedusaRaw as l, moneyByCurrency as n, readStoredField as o, moneyFor as r, storedFieldValue as s, isPositiveAmount as t };
|
|
115
|
+
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,3 @@
|
|
|
1
|
-
//#region src/decimal.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* How a value between two representable amounts is resolved. `half-up` rounds a tie away from zero.
|
|
4
3
|
* `floor-after-tenth` is Shopify's discount truncation: round to a tenth of the unit (half-up), then
|
|
@@ -10,8 +9,6 @@ declare const DECIMAL_TEXT_BRAND: unique symbol;
|
|
|
10
9
|
type DecimalText = string & {
|
|
11
10
|
readonly [DECIMAL_TEXT_BRAND]: true;
|
|
12
11
|
};
|
|
13
|
-
//#endregion
|
|
14
|
-
//#region src/registry.d.ts
|
|
15
12
|
declare const CURRENCY_CODE: unique symbol;
|
|
16
13
|
/** An upper-case code this package knows. Obtain one from `currencyCode` or `isCurrencyCode`. */
|
|
17
14
|
type CurrencyCode = string & {
|
|
@@ -128,8 +125,6 @@ declare function localeForCurrency(code: string): string;
|
|
|
128
125
|
* numbers, as Medusa does, so these sites agree with Medusa's own `payment_status`.
|
|
129
126
|
*/
|
|
130
127
|
declare function medusaEpsilon(code: string): DecimalText;
|
|
131
|
-
//#endregion
|
|
132
|
-
//#region src/money.d.ts
|
|
133
128
|
declare const STORED_AMOUNT: unique symbol;
|
|
134
129
|
declare const MAJOR_DECIMAL: unique symbol;
|
|
135
130
|
/** An amount in Amboras storage units (major x storageScale): a safe integer. */
|
|
@@ -145,6 +140,16 @@ interface Money {
|
|
|
145
140
|
readonly amount: StoredAmount;
|
|
146
141
|
readonly currency: CurrencyCode;
|
|
147
142
|
}
|
|
143
|
+
/**
|
|
144
|
+
* A stored amount that may hold a fraction of a storage unit, as Medusa keeps unrounded totals (a
|
|
145
|
+
* tax line can leave 107.8175): a finite number (a safe integer when whole) or plain decimal text
|
|
146
|
+
* (`readStoredDecimal`'s result). `Money` is always whole; the PSP codecs and comparators take
|
|
147
|
+
* either, and `formatStored` formats one.
|
|
148
|
+
*/
|
|
149
|
+
interface FractionalMoney {
|
|
150
|
+
readonly amount: number | DecimalText;
|
|
151
|
+
readonly currency: string;
|
|
152
|
+
}
|
|
148
153
|
interface FromMajorOptions {
|
|
149
154
|
/**
|
|
150
155
|
* More fraction digits than the currency stores: `'reject'` (default) throws
|
|
@@ -176,6 +181,11 @@ interface ToMajorDecimalOptions {
|
|
|
176
181
|
interface ReadStoredOptions {
|
|
177
182
|
/** `'strict'` (default) throws `amount_invalid` on a bad amount; `'lenient'` returns null. Never 0. */
|
|
178
183
|
mode?: 'strict' | 'lenient';
|
|
184
|
+
/**
|
|
185
|
+
* A fractional stored amount (Medusa's unrounded totals, 107.8175): `'reject'` (default) reads it
|
|
186
|
+
* as invalid; `'round'` rounds it half-up, exactly, to a whole storage unit (107.8175 gives 108).
|
|
187
|
+
*/
|
|
188
|
+
precision?: 'reject' | 'round';
|
|
179
189
|
/** Names the input field in errors. */
|
|
180
190
|
field?: string;
|
|
181
191
|
}
|
|
@@ -217,8 +227,9 @@ declare function toMajorNumber(m: Money, options?: ToMajorDecimalOptions): numbe
|
|
|
217
227
|
* A stored amount as Medusa hands it over (a number, a numeric string, a raw
|
|
218
228
|
* `{ value: '4300', precision: 20 }`, a live BigNumber) as Money. Precedence
|
|
219
229
|
* `.value ?? .raw.value ?? .raw_.value`, then `.numeric ?? .numeric_`, then the
|
|
220
|
-
* primitive. `'4300.00'` is accepted; a fractional
|
|
221
|
-
*
|
|
230
|
+
* primitive. `'4300.00'` is accepted; a fractional amount is rounded half-up to a whole
|
|
231
|
+
* storage unit with `precision: 'round'`; otherwise a fractional, non-finite, unsafe or
|
|
232
|
+
* unreadable amount throws `amount_invalid`, or gives null with `mode: 'lenient'` (never 0).
|
|
222
233
|
* An unknown currency always throws.
|
|
223
234
|
*/
|
|
224
235
|
declare function readStored(raw: unknown, currency: string, options: ReadStoredOptions & {
|
|
@@ -228,5 +239,4 @@ declare function readStored(raw: unknown, currency: string, options?: ReadStored
|
|
|
228
239
|
mode?: 'strict';
|
|
229
240
|
}): Money;
|
|
230
241
|
declare function readStored(raw: unknown, currency: string, options?: ReadStoredOptions): Money | null;
|
|
231
|
-
|
|
232
|
-
export { localeForCurrency as A, currencyLabel as C, displayDigits as D, currencySymbol as E, storageDigits as F, storageScale as I, DecimalText as L, medusaEpsilon as M, parseCurrencyCode as N, firstCurrency as O, sameCurrency as P, RoundingMode as R, currencyInfo as S, currencyOptions as T, CurrencyInfo as _, StoredAmount as a, StorageScale as b, fromMajor as c, readStored as d, toMajorDecimal as f, CurrencyCodeOptions as g, CurrencyCode as h, ReadStoredOptions as i, medusaCurrencyCode as j, isCurrencyCode as k, isStoredAmount as l, CURRENCIES as m, MajorDecimal as n, StoredAmountOptions as o, toMajorNumber as p, Money as r, ToMajorDecimalOptions as s, FromMajorOptions as t, money as u, CurrencyStatus as v, currencyName as w, currencyCode as x, FractionDigits as y };
|
|
242
|
+
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 };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/decimal.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* How a value between two representable amounts is resolved. `half-up` rounds a tie away from zero.
|
|
4
3
|
* `floor-after-tenth` is Shopify's discount truncation: round to a tenth of the unit (half-up), then
|
|
@@ -10,8 +9,6 @@ declare const DECIMAL_TEXT_BRAND: unique symbol;
|
|
|
10
9
|
type DecimalText = string & {
|
|
11
10
|
readonly [DECIMAL_TEXT_BRAND]: true;
|
|
12
11
|
};
|
|
13
|
-
//#endregion
|
|
14
|
-
//#region src/registry.d.ts
|
|
15
12
|
declare const CURRENCY_CODE: unique symbol;
|
|
16
13
|
/** An upper-case code this package knows. Obtain one from `currencyCode` or `isCurrencyCode`. */
|
|
17
14
|
type CurrencyCode = string & {
|
|
@@ -128,8 +125,6 @@ declare function localeForCurrency(code: string): string;
|
|
|
128
125
|
* numbers, as Medusa does, so these sites agree with Medusa's own `payment_status`.
|
|
129
126
|
*/
|
|
130
127
|
declare function medusaEpsilon(code: string): DecimalText;
|
|
131
|
-
//#endregion
|
|
132
|
-
//#region src/money.d.ts
|
|
133
128
|
declare const STORED_AMOUNT: unique symbol;
|
|
134
129
|
declare const MAJOR_DECIMAL: unique symbol;
|
|
135
130
|
/** An amount in Amboras storage units (major x storageScale): a safe integer. */
|
|
@@ -145,6 +140,16 @@ interface Money {
|
|
|
145
140
|
readonly amount: StoredAmount;
|
|
146
141
|
readonly currency: CurrencyCode;
|
|
147
142
|
}
|
|
143
|
+
/**
|
|
144
|
+
* A stored amount that may hold a fraction of a storage unit, as Medusa keeps unrounded totals (a
|
|
145
|
+
* tax line can leave 107.8175): a finite number (a safe integer when whole) or plain decimal text
|
|
146
|
+
* (`readStoredDecimal`'s result). `Money` is always whole; the PSP codecs and comparators take
|
|
147
|
+
* either, and `formatStored` formats one.
|
|
148
|
+
*/
|
|
149
|
+
interface FractionalMoney {
|
|
150
|
+
readonly amount: number | DecimalText;
|
|
151
|
+
readonly currency: string;
|
|
152
|
+
}
|
|
148
153
|
interface FromMajorOptions {
|
|
149
154
|
/**
|
|
150
155
|
* More fraction digits than the currency stores: `'reject'` (default) throws
|
|
@@ -176,6 +181,11 @@ interface ToMajorDecimalOptions {
|
|
|
176
181
|
interface ReadStoredOptions {
|
|
177
182
|
/** `'strict'` (default) throws `amount_invalid` on a bad amount; `'lenient'` returns null. Never 0. */
|
|
178
183
|
mode?: 'strict' | 'lenient';
|
|
184
|
+
/**
|
|
185
|
+
* A fractional stored amount (Medusa's unrounded totals, 107.8175): `'reject'` (default) reads it
|
|
186
|
+
* as invalid; `'round'` rounds it half-up, exactly, to a whole storage unit (107.8175 gives 108).
|
|
187
|
+
*/
|
|
188
|
+
precision?: 'reject' | 'round';
|
|
179
189
|
/** Names the input field in errors. */
|
|
180
190
|
field?: string;
|
|
181
191
|
}
|
|
@@ -217,8 +227,9 @@ declare function toMajorNumber(m: Money, options?: ToMajorDecimalOptions): numbe
|
|
|
217
227
|
* A stored amount as Medusa hands it over (a number, a numeric string, a raw
|
|
218
228
|
* `{ value: '4300', precision: 20 }`, a live BigNumber) as Money. Precedence
|
|
219
229
|
* `.value ?? .raw.value ?? .raw_.value`, then `.numeric ?? .numeric_`, then the
|
|
220
|
-
* primitive. `'4300.00'` is accepted; a fractional
|
|
221
|
-
*
|
|
230
|
+
* primitive. `'4300.00'` is accepted; a fractional amount is rounded half-up to a whole
|
|
231
|
+
* storage unit with `precision: 'round'`; otherwise a fractional, non-finite, unsafe or
|
|
232
|
+
* unreadable amount throws `amount_invalid`, or gives null with `mode: 'lenient'` (never 0).
|
|
222
233
|
* An unknown currency always throws.
|
|
223
234
|
*/
|
|
224
235
|
declare function readStored(raw: unknown, currency: string, options: ReadStoredOptions & {
|
|
@@ -228,5 +239,4 @@ declare function readStored(raw: unknown, currency: string, options?: ReadStored
|
|
|
228
239
|
mode?: 'strict';
|
|
229
240
|
}): Money;
|
|
230
241
|
declare function readStored(raw: unknown, currency: string, options?: ReadStoredOptions): Money | null;
|
|
231
|
-
|
|
232
|
-
export { localeForCurrency as A, currencyLabel as C, displayDigits as D, currencySymbol as E, storageDigits as F, storageScale as I, DecimalText as L, medusaEpsilon as M, parseCurrencyCode as N, firstCurrency as O, sameCurrency as P, RoundingMode as R, currencyInfo as S, currencyOptions as T, CurrencyInfo as _, StoredAmount as a, StorageScale as b, fromMajor as c, readStored as d, toMajorDecimal as f, CurrencyCodeOptions as g, CurrencyCode as h, ReadStoredOptions as i, medusaCurrencyCode as j, isCurrencyCode as k, isStoredAmount as l, CURRENCIES as m, MajorDecimal as n, StoredAmountOptions as o, toMajorNumber as p, Money as r, ToMajorDecimalOptions as s, FromMajorOptions as t, money as u, CurrencyStatus as v, currencyName as w, currencyCode as x, FractionDigits as y };
|
|
242
|
+
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 };
|
|
@@ -137,8 +137,7 @@ function withinFloatNoise(major, digits) {
|
|
|
137
137
|
function unitsWithin(d, limit) {
|
|
138
138
|
return (d.units < 0n ? -d.units : d.units) <= limit;
|
|
139
139
|
}
|
|
140
|
-
|
|
141
|
-
//#region src/errors.ts
|
|
140
|
+
// src/errors.ts
|
|
142
141
|
/** The one error this package throws for bad money input. Check `code`, not the message. */
|
|
143
142
|
var MoneyError = class extends Error {
|
|
144
143
|
constructor(code, message, options = {}) {
|
|
@@ -157,8 +156,7 @@ function describeValue(value) {
|
|
|
157
156
|
return Object.prototype.toString.call(value);
|
|
158
157
|
}
|
|
159
158
|
}
|
|
160
|
-
|
|
161
|
-
//#region src/internal/rational.ts
|
|
159
|
+
// src/internal/rational.ts
|
|
162
160
|
/** `a x b / c` rounded by `mode`. `c` must not be zero; its sign is folded into the numerator. */
|
|
163
161
|
function mulDiv(a, b, c, mode) {
|
|
164
162
|
if (c === 0n) throw new RangeError("mulDiv: division by zero");
|
|
@@ -185,8 +183,7 @@ function gcd(a, b) {
|
|
|
185
183
|
while (y !== 0n) [x, y] = [y, x % y];
|
|
186
184
|
return x;
|
|
187
185
|
}
|
|
188
|
-
|
|
189
|
-
//#region src/decimal-text.ts
|
|
186
|
+
// src/decimal-text.ts
|
|
190
187
|
/**
|
|
191
188
|
* Internal: `input` as an exact Decimal. Text must be plain decimal (`'-12.50'`, `'7'`):
|
|
192
189
|
* no blank, whitespace, exponent, hex, `'.5'` or `'1.'` (`parse`). Numbers are taken by
|
|
@@ -276,6 +273,18 @@ function decimalRound(a, options) {
|
|
|
276
273
|
function decimalCompare(a, b) {
|
|
277
274
|
return compareDecimal(decimalOf(a), decimalOf(b));
|
|
278
275
|
}
|
|
276
|
+
/**
|
|
277
|
+
* Whether `a` and `b` are the same decimal, exactly (`'43.0'` equals `'43.00'` and `43`). Takes what
|
|
278
|
+
* `decimalCompare` takes, but never throws: anything that is not plain decimal text, a finite number
|
|
279
|
+
* or a bigint is never equal, not even to itself.
|
|
280
|
+
*/
|
|
281
|
+
function decimalEquals(a, b) {
|
|
282
|
+
try {
|
|
283
|
+
return compareDecimal(decimalOf(a), decimalOf(b)) === 0;
|
|
284
|
+
} catch {
|
|
285
|
+
return false;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
279
288
|
/** `a` limited to `[min, max]` (either bound optional). `min` above `max` throws `amount_invalid`. */
|
|
280
289
|
function decimalClamp(a, bounds) {
|
|
281
290
|
const value = decimalOf(a);
|
|
@@ -296,8 +305,7 @@ function decimalWithin(a, b, tolerance, options = {}) {
|
|
|
296
305
|
}, limit);
|
|
297
306
|
return options.inclusive === false ? gap < 0 : gap <= 0;
|
|
298
307
|
}
|
|
299
|
-
|
|
300
|
-
//#region src/data/currencies.ts
|
|
308
|
+
// src/data/currencies.ts
|
|
301
309
|
const CURRENCY_ROWS = [
|
|
302
310
|
{
|
|
303
311
|
code: "AED",
|
|
@@ -3215,8 +3223,7 @@ const CURRENCY_ROWS = [
|
|
|
3215
3223
|
commaDecimal: false
|
|
3216
3224
|
}
|
|
3217
3225
|
];
|
|
3218
|
-
|
|
3219
|
-
//#region src/internal/intl.ts
|
|
3226
|
+
// src/internal/intl.ts
|
|
3220
3227
|
const DEFAULT_LOCALE = "en-US";
|
|
3221
3228
|
/**
|
|
3222
3229
|
* `locale` when the runtime supports it, else `'en-US'`. Blank, malformed or unsupported
|
|
@@ -3253,8 +3260,7 @@ function separatorsOf(locale) {
|
|
|
3253
3260
|
group: parts.find((p) => p.type === "group")?.value ?? (decimal === "." ? "," : ".")
|
|
3254
3261
|
};
|
|
3255
3262
|
}
|
|
3256
|
-
|
|
3257
|
-
//#region src/registry.ts
|
|
3263
|
+
// src/registry.ts
|
|
3258
3264
|
/** Every currency this package knows, active and historic, sorted by code. */
|
|
3259
3265
|
const CURRENCIES = Object.freeze(CURRENCY_ROWS.map((row) => Object.freeze({
|
|
3260
3266
|
...row,
|
|
@@ -3413,8 +3419,7 @@ function medusaEpsilon(code) {
|
|
|
3413
3419
|
scale: currencyInfo(code).medusaDigits
|
|
3414
3420
|
});
|
|
3415
3421
|
}
|
|
3416
|
-
|
|
3417
|
-
//#region src/money.ts
|
|
3422
|
+
// src/money.ts
|
|
3418
3423
|
const MAX_UNITS = 2n ** 46n;
|
|
3419
3424
|
const anyKnownCurrency = (currency, field) => resolveCurrency(currency, {
|
|
3420
3425
|
allowHistoric: true,
|
|
@@ -3553,19 +3558,18 @@ function medusaAmountDecimal(raw) {
|
|
|
3553
3558
|
return typeof primitive === "string" ? parseDecimal(primitive) : null;
|
|
3554
3559
|
}
|
|
3555
3560
|
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) {
|
|
3561
|
+
/** A stored integer from Medusa's shapes (a fraction rounded half-up with `round`), or null when it is fractional, unsafe or unreadable. */
|
|
3562
|
+
function unwrapStored(raw, round) {
|
|
3558
3563
|
const parsed = medusaAmountDecimal(raw);
|
|
3559
|
-
if (!parsed || fractionDigitsOf(parsed) !== 0) return null;
|
|
3560
|
-
const whole = roundToScale(parsed, 0, "
|
|
3564
|
+
if (!parsed || !round && fractionDigitsOf(parsed) !== 0) return null;
|
|
3565
|
+
const whole = roundToScale(parsed, 0, "half-up");
|
|
3561
3566
|
return unitsWithin(whole, SAFE_LIMIT) ? Number(whole.units) : null;
|
|
3562
3567
|
}
|
|
3563
3568
|
function readStored(raw, currency, options = {}) {
|
|
3564
3569
|
const info = anyKnownCurrency(currency, options.field);
|
|
3565
|
-
const amount = unwrapStored(raw);
|
|
3570
|
+
const amount = unwrapStored(raw, options.precision === "round");
|
|
3566
3571
|
if (amount !== null) return storedFrom(amount, info);
|
|
3567
3572
|
if (options.mode === "lenient") return null;
|
|
3568
3573
|
throw new MoneyError("amount_invalid", `Invalid stored amount: ${describeValue(raw)}`, { field: options.field });
|
|
3569
3574
|
}
|
|
3570
|
-
|
|
3571
|
-
export { addDecimal as $, storageScale as A, decimalRound as B, medusaCurrencyCode as C, sameCurrency as D, resolveCurrency as E, decimalClamp as F, parseDecimalText as G, decimalSum as H, decimalCompare as I, gcd as J, trimDecimalZeros as K, decimalDivide as L, resolveLocale as M, separatorsOf as N, storageDigits as O, assertDecimalLiteral as P, describeValue as Q, decimalMultiply as R, localeForCurrency as S, parseCurrencyCode as T, decimalWithin as U, decimalSubtract as V, isDecimalLiteral as W, ratioToDecimal as X, mulDiv as Y, MoneyError as Z, currencySymbol as _, money as a, isPositiveDecimal as at, firstCurrency as b, toMajorDecimal as c, pow10 as ct, currencyCode as d, toDecimalText as dt, compareDecimal as et, currencyInfo as f, currencyOptions as g, currencyName as h, medusaAmountDecimal as i, fractionDigitsOf as it, numberFormat as j, storageExponent as k, toMajorNumber as l, roundToScale as lt, currencyMarks as m, fromMajor as n, divRound as nt, readStored as o, multiplyDecimal as ot, currencyLabel as p, compareRatio as q, isStoredAmount as r, formatDecimal as rt, storedDecimal as s, parseDecimal as st, boundedMoney as t, decimalFromNumber as tt, CURRENCIES as u, strictNumberDecimal as ut, displayDigits as v, medusaEpsilon as w, isCurrencyCode as x, findCurrency as y, decimalOf as z };
|
|
3575
|
+
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 };
|