@vectoriox/iox-ui 5.92.0 → 5.93.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/commerce-core/index.d.ts +88 -0
- package/commerce-core/package.json +3 -0
- package/fesm2022/vectoriox-iox-ui-commerce-core.mjs +342 -0
- package/fesm2022/vectoriox-iox-ui-commerce-core.mjs.map +1 -0
- package/package.json +5 -1
- package/src/commerce-core/currency.ts +99 -0
- package/src/commerce-core/decimal.ts +78 -0
- package/src/commerce-core/money-error.ts +18 -0
- package/src/commerce-core/money.ts +159 -0
- package/src/commerce-core/public-api.ts +12 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
declare enum MoneyErrorCode {
|
|
2
|
+
UnknownCurrency = "unknown-currency",
|
|
3
|
+
NotMoney = "not-money",
|
|
4
|
+
NotInteger = "not-integer",
|
|
5
|
+
NotANumber = "not-a-number",
|
|
6
|
+
TooManyDecimals = "too-many-decimals",
|
|
7
|
+
CurrencyMismatch = "currency-mismatch",
|
|
8
|
+
NotWhole = "not-whole",
|
|
9
|
+
Negative = "negative",
|
|
10
|
+
Overflow = "overflow"
|
|
11
|
+
}
|
|
12
|
+
declare class MoneyError extends Error {
|
|
13
|
+
readonly code: MoneyErrorCode;
|
|
14
|
+
constructor(code: MoneyErrorCode, message: string);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
declare enum CurrencyCode {
|
|
18
|
+
ILS = "ILS",
|
|
19
|
+
USD = "USD",
|
|
20
|
+
EUR = "EUR",
|
|
21
|
+
GBP = "GBP",
|
|
22
|
+
CHF = "CHF",
|
|
23
|
+
CAD = "CAD",
|
|
24
|
+
AUD = "AUD",
|
|
25
|
+
NZD = "NZD",
|
|
26
|
+
SEK = "SEK",
|
|
27
|
+
NOK = "NOK",
|
|
28
|
+
DKK = "DKK",
|
|
29
|
+
PLN = "PLN",
|
|
30
|
+
CZK = "CZK",
|
|
31
|
+
HUF = "HUF",
|
|
32
|
+
RON = "RON",
|
|
33
|
+
TRY = "TRY",
|
|
34
|
+
AED = "AED",
|
|
35
|
+
SAR = "SAR",
|
|
36
|
+
QAR = "QAR",
|
|
37
|
+
EGP = "EGP",
|
|
38
|
+
MAD = "MAD",
|
|
39
|
+
ZAR = "ZAR",
|
|
40
|
+
INR = "INR",
|
|
41
|
+
CNY = "CNY",
|
|
42
|
+
HKD = "HKD",
|
|
43
|
+
SGD = "SGD",
|
|
44
|
+
THB = "THB",
|
|
45
|
+
MXN = "MXN",
|
|
46
|
+
BRL = "BRL",
|
|
47
|
+
JPY = "JPY",
|
|
48
|
+
KRW = "KRW",
|
|
49
|
+
VND = "VND",
|
|
50
|
+
CLP = "CLP",
|
|
51
|
+
ISK = "ISK",
|
|
52
|
+
BHD = "BHD",
|
|
53
|
+
KWD = "KWD",
|
|
54
|
+
JOD = "JOD",
|
|
55
|
+
OMR = "OMR",
|
|
56
|
+
TND = "TND"
|
|
57
|
+
}
|
|
58
|
+
/** ISO-4217 minor units — our own table, never Intl's CLDR digits (they differ for some codes). */
|
|
59
|
+
declare const CURRENCY_EXPONENTS: Readonly<Record<CurrencyCode, number>>;
|
|
60
|
+
declare const CURRENCY_CODES: readonly CurrencyCode[];
|
|
61
|
+
declare function isCurrencyCode(value: unknown): value is CurrencyCode;
|
|
62
|
+
declare function currencyExponent(currency: CurrencyCode): number;
|
|
63
|
+
|
|
64
|
+
interface Money {
|
|
65
|
+
/** Integer minor units (agorot, cents, fils…). */
|
|
66
|
+
amount: number;
|
|
67
|
+
currency: CurrencyCode;
|
|
68
|
+
}
|
|
69
|
+
declare function isMoney(value: unknown): value is Money;
|
|
70
|
+
declare function money(amount: number, currency: CurrencyCode): Money;
|
|
71
|
+
/** Exact: `19.99` → 1999 by reading the digits, never `x * 100`; refuses digits the currency lacks. */
|
|
72
|
+
declare function majorToMinor(major: number | string, currency: CurrencyCode): number;
|
|
73
|
+
declare function minorToMajor(minor: number, currency: CurrencyCode): number;
|
|
74
|
+
declare function addMoney(a: Money, b: Money): Money;
|
|
75
|
+
declare function subtractMoney(a: Money, b: Money): Money;
|
|
76
|
+
declare function timesMoney(value: Money, quantity: number): Money;
|
|
77
|
+
/** `percent` of an amount, rounded ONCE to a minor unit, half-to-even (banker's). */
|
|
78
|
+
declare function percentOf(value: Money, percent: number): Money;
|
|
79
|
+
declare function formatMoney(value: Money, locale: string): string;
|
|
80
|
+
/**
|
|
81
|
+
* For the one boot migration of stored major-unit prices. A stored float may carry arithmetic noise
|
|
82
|
+
* (19.990000000000002), so extra digits round half-to-even instead of refusing. No usable price
|
|
83
|
+
* (null, '', NaN, text, a negative) → null; it never applies twice by itself — the caller marks rows.
|
|
84
|
+
*/
|
|
85
|
+
declare function migrateMajorPrice(value: unknown, currency: CurrencyCode): number | null;
|
|
86
|
+
|
|
87
|
+
export { CURRENCY_CODES, CURRENCY_EXPONENTS, CurrencyCode, MoneyError, MoneyErrorCode, addMoney, currencyExponent, formatMoney, isCurrencyCode, isMoney, majorToMinor, migrateMajorPrice, minorToMajor, money, percentOf, subtractMoney, timesMoney };
|
|
88
|
+
export type { Money };
|
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
var MoneyErrorCode;
|
|
2
|
+
(function (MoneyErrorCode) {
|
|
3
|
+
MoneyErrorCode["UnknownCurrency"] = "unknown-currency";
|
|
4
|
+
MoneyErrorCode["NotMoney"] = "not-money";
|
|
5
|
+
MoneyErrorCode["NotInteger"] = "not-integer";
|
|
6
|
+
MoneyErrorCode["NotANumber"] = "not-a-number";
|
|
7
|
+
MoneyErrorCode["TooManyDecimals"] = "too-many-decimals";
|
|
8
|
+
MoneyErrorCode["CurrencyMismatch"] = "currency-mismatch";
|
|
9
|
+
MoneyErrorCode["NotWhole"] = "not-whole";
|
|
10
|
+
MoneyErrorCode["Negative"] = "negative";
|
|
11
|
+
MoneyErrorCode["Overflow"] = "overflow";
|
|
12
|
+
})(MoneyErrorCode || (MoneyErrorCode = {}));
|
|
13
|
+
class MoneyError extends Error {
|
|
14
|
+
constructor(code, message) {
|
|
15
|
+
super(message);
|
|
16
|
+
this.code = code;
|
|
17
|
+
this.name = 'MoneyError';
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
var CurrencyCode;
|
|
22
|
+
(function (CurrencyCode) {
|
|
23
|
+
CurrencyCode["ILS"] = "ILS";
|
|
24
|
+
CurrencyCode["USD"] = "USD";
|
|
25
|
+
CurrencyCode["EUR"] = "EUR";
|
|
26
|
+
CurrencyCode["GBP"] = "GBP";
|
|
27
|
+
CurrencyCode["CHF"] = "CHF";
|
|
28
|
+
CurrencyCode["CAD"] = "CAD";
|
|
29
|
+
CurrencyCode["AUD"] = "AUD";
|
|
30
|
+
CurrencyCode["NZD"] = "NZD";
|
|
31
|
+
CurrencyCode["SEK"] = "SEK";
|
|
32
|
+
CurrencyCode["NOK"] = "NOK";
|
|
33
|
+
CurrencyCode["DKK"] = "DKK";
|
|
34
|
+
CurrencyCode["PLN"] = "PLN";
|
|
35
|
+
CurrencyCode["CZK"] = "CZK";
|
|
36
|
+
CurrencyCode["HUF"] = "HUF";
|
|
37
|
+
CurrencyCode["RON"] = "RON";
|
|
38
|
+
CurrencyCode["TRY"] = "TRY";
|
|
39
|
+
CurrencyCode["AED"] = "AED";
|
|
40
|
+
CurrencyCode["SAR"] = "SAR";
|
|
41
|
+
CurrencyCode["QAR"] = "QAR";
|
|
42
|
+
CurrencyCode["EGP"] = "EGP";
|
|
43
|
+
CurrencyCode["MAD"] = "MAD";
|
|
44
|
+
CurrencyCode["ZAR"] = "ZAR";
|
|
45
|
+
CurrencyCode["INR"] = "INR";
|
|
46
|
+
CurrencyCode["CNY"] = "CNY";
|
|
47
|
+
CurrencyCode["HKD"] = "HKD";
|
|
48
|
+
CurrencyCode["SGD"] = "SGD";
|
|
49
|
+
CurrencyCode["THB"] = "THB";
|
|
50
|
+
CurrencyCode["MXN"] = "MXN";
|
|
51
|
+
CurrencyCode["BRL"] = "BRL";
|
|
52
|
+
CurrencyCode["JPY"] = "JPY";
|
|
53
|
+
CurrencyCode["KRW"] = "KRW";
|
|
54
|
+
CurrencyCode["VND"] = "VND";
|
|
55
|
+
CurrencyCode["CLP"] = "CLP";
|
|
56
|
+
CurrencyCode["ISK"] = "ISK";
|
|
57
|
+
CurrencyCode["BHD"] = "BHD";
|
|
58
|
+
CurrencyCode["KWD"] = "KWD";
|
|
59
|
+
CurrencyCode["JOD"] = "JOD";
|
|
60
|
+
CurrencyCode["OMR"] = "OMR";
|
|
61
|
+
CurrencyCode["TND"] = "TND";
|
|
62
|
+
})(CurrencyCode || (CurrencyCode = {}));
|
|
63
|
+
/** ISO-4217 minor units — our own table, never Intl's CLDR digits (they differ for some codes). */
|
|
64
|
+
const CURRENCY_EXPONENTS = Object.freeze({
|
|
65
|
+
[CurrencyCode.ILS]: 2,
|
|
66
|
+
[CurrencyCode.USD]: 2,
|
|
67
|
+
[CurrencyCode.EUR]: 2,
|
|
68
|
+
[CurrencyCode.GBP]: 2,
|
|
69
|
+
[CurrencyCode.CHF]: 2,
|
|
70
|
+
[CurrencyCode.CAD]: 2,
|
|
71
|
+
[CurrencyCode.AUD]: 2,
|
|
72
|
+
[CurrencyCode.NZD]: 2,
|
|
73
|
+
[CurrencyCode.SEK]: 2,
|
|
74
|
+
[CurrencyCode.NOK]: 2,
|
|
75
|
+
[CurrencyCode.DKK]: 2,
|
|
76
|
+
[CurrencyCode.PLN]: 2,
|
|
77
|
+
[CurrencyCode.CZK]: 2,
|
|
78
|
+
[CurrencyCode.HUF]: 2,
|
|
79
|
+
[CurrencyCode.RON]: 2,
|
|
80
|
+
[CurrencyCode.TRY]: 2,
|
|
81
|
+
[CurrencyCode.AED]: 2,
|
|
82
|
+
[CurrencyCode.SAR]: 2,
|
|
83
|
+
[CurrencyCode.QAR]: 2,
|
|
84
|
+
[CurrencyCode.EGP]: 2,
|
|
85
|
+
[CurrencyCode.MAD]: 2,
|
|
86
|
+
[CurrencyCode.ZAR]: 2,
|
|
87
|
+
[CurrencyCode.INR]: 2,
|
|
88
|
+
[CurrencyCode.CNY]: 2,
|
|
89
|
+
[CurrencyCode.HKD]: 2,
|
|
90
|
+
[CurrencyCode.SGD]: 2,
|
|
91
|
+
[CurrencyCode.THB]: 2,
|
|
92
|
+
[CurrencyCode.MXN]: 2,
|
|
93
|
+
[CurrencyCode.BRL]: 2,
|
|
94
|
+
[CurrencyCode.JPY]: 0,
|
|
95
|
+
[CurrencyCode.KRW]: 0,
|
|
96
|
+
[CurrencyCode.VND]: 0,
|
|
97
|
+
[CurrencyCode.CLP]: 0,
|
|
98
|
+
[CurrencyCode.ISK]: 0,
|
|
99
|
+
[CurrencyCode.BHD]: 3,
|
|
100
|
+
[CurrencyCode.KWD]: 3,
|
|
101
|
+
[CurrencyCode.JOD]: 3,
|
|
102
|
+
[CurrencyCode.OMR]: 3,
|
|
103
|
+
[CurrencyCode.TND]: 3,
|
|
104
|
+
});
|
|
105
|
+
const CURRENCY_CODES = Object.freeze(Object.values(CurrencyCode));
|
|
106
|
+
function isCurrencyCode(value) {
|
|
107
|
+
return typeof value === 'string' && Object.prototype.hasOwnProperty.call(CURRENCY_EXPONENTS, value);
|
|
108
|
+
}
|
|
109
|
+
function currencyExponent(currency) {
|
|
110
|
+
if (!isCurrencyCode(currency)) {
|
|
111
|
+
throw new MoneyError(MoneyErrorCode.UnknownCurrency, `Unknown currency: ${String(currency)}`);
|
|
112
|
+
}
|
|
113
|
+
return CURRENCY_EXPONENTS[currency];
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
var DecimalRounding;
|
|
117
|
+
(function (DecimalRounding) {
|
|
118
|
+
DecimalRounding["Exact"] = "exact";
|
|
119
|
+
DecimalRounding["HalfEven"] = "half-even";
|
|
120
|
+
})(DecimalRounding || (DecimalRounding = {}));
|
|
121
|
+
const DECIMAL = /^([+-])?(\d*)(?:\.(\d*))?(?:[eE]([+-]?\d{1,3}))?$/;
|
|
122
|
+
/** Plain decimal text, or the e-notation `String(number)` produces below 1e-6 and from 1e21. */
|
|
123
|
+
function parseDecimal(text) {
|
|
124
|
+
const match = DECIMAL.exec(text);
|
|
125
|
+
if (!match)
|
|
126
|
+
return null;
|
|
127
|
+
const int = match[2] ?? '';
|
|
128
|
+
const frac = match[3] ?? '';
|
|
129
|
+
if (!int && !frac)
|
|
130
|
+
return null;
|
|
131
|
+
const digits = int + frac;
|
|
132
|
+
const point = int.length + Number(match[4] ?? 0);
|
|
133
|
+
const shiftedInt = point <= 0 ? '' : point >= digits.length ? digits + '0'.repeat(point - digits.length) : digits.slice(0, point);
|
|
134
|
+
const shiftedFrac = point <= 0 ? '0'.repeat(-point) + digits : point >= digits.length ? '' : digits.slice(point);
|
|
135
|
+
return {
|
|
136
|
+
negative: match[1] === '-',
|
|
137
|
+
int: shiftedInt.replace(/^0+/, ''),
|
|
138
|
+
frac: shiftedFrac.replace(/0+$/, ''),
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
function safeFromDigits(digits) {
|
|
142
|
+
const trimmed = digits.replace(/^0+/, '') || '0';
|
|
143
|
+
const value = trimmed.length > 16 ? Infinity : Number(trimmed);
|
|
144
|
+
if (!Number.isSafeInteger(value)) {
|
|
145
|
+
throw new MoneyError(MoneyErrorCode.Overflow, `${digits} is beyond the safe integer range`);
|
|
146
|
+
}
|
|
147
|
+
return value;
|
|
148
|
+
}
|
|
149
|
+
/** Scales a parsed decimal by 10^exponent into an integer, without ever touching a float. */
|
|
150
|
+
function decimalToScaledInteger(decimal, exponent, rounding) {
|
|
151
|
+
const kept = decimal.frac.slice(0, exponent);
|
|
152
|
+
const rest = decimal.frac.slice(exponent);
|
|
153
|
+
if (rest && rounding === DecimalRounding.Exact) {
|
|
154
|
+
throw new MoneyError(MoneyErrorCode.TooManyDecimals, `More than ${exponent} decimal digits`);
|
|
155
|
+
}
|
|
156
|
+
let magnitude = safeFromDigits(decimal.int + kept.padEnd(exponent, '0'));
|
|
157
|
+
if (rest) {
|
|
158
|
+
const first = Number(rest[0]);
|
|
159
|
+
const tie = first === 5 && /^5$/.test(rest);
|
|
160
|
+
const up = first > 5 || (first === 5 && !tie) || (tie && magnitude % 2 === 1);
|
|
161
|
+
if (up)
|
|
162
|
+
magnitude += 1;
|
|
163
|
+
if (!Number.isSafeInteger(magnitude)) {
|
|
164
|
+
throw new MoneyError(MoneyErrorCode.Overflow, 'Rounded value is beyond the safe integer range');
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return decimal.negative && magnitude !== 0 ? -magnitude : magnitude;
|
|
168
|
+
}
|
|
169
|
+
/** Integer division rounded half-to-even; numerator ≥ 0, denominator > 0, both safe integers. */
|
|
170
|
+
function divideHalfEven(numerator, denominator) {
|
|
171
|
+
let quotient = Math.trunc(numerator / denominator);
|
|
172
|
+
let remainder = numerator - quotient * denominator;
|
|
173
|
+
while (remainder < 0) {
|
|
174
|
+
quotient -= 1;
|
|
175
|
+
remainder += denominator;
|
|
176
|
+
}
|
|
177
|
+
while (remainder >= denominator) {
|
|
178
|
+
quotient += 1;
|
|
179
|
+
remainder -= denominator;
|
|
180
|
+
}
|
|
181
|
+
const twice = remainder * 2;
|
|
182
|
+
if (twice > denominator || (twice === denominator && quotient % 2 === 1))
|
|
183
|
+
quotient += 1;
|
|
184
|
+
return quotient;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const MAX_PERCENT_DECIMALS = 6;
|
|
188
|
+
function isMoney(value) {
|
|
189
|
+
if (typeof value !== 'object' || value === null)
|
|
190
|
+
return false;
|
|
191
|
+
const record = value;
|
|
192
|
+
return Number.isSafeInteger(record['amount']) && isCurrencyCode(record['currency']);
|
|
193
|
+
}
|
|
194
|
+
function assertWhole(amount, what) {
|
|
195
|
+
if (typeof amount !== 'number' || !Number.isSafeInteger(amount)) {
|
|
196
|
+
throw new MoneyError(MoneyErrorCode.NotInteger, `${what} must be a whole number of minor units, got ${String(amount)}`);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
function assertMoney(value) {
|
|
200
|
+
if (typeof value !== 'object' || value === null) {
|
|
201
|
+
throw new MoneyError(MoneyErrorCode.NotMoney, `Not a Money value: ${String(value)}`);
|
|
202
|
+
}
|
|
203
|
+
currencyExponent(value.currency);
|
|
204
|
+
assertWhole(value.amount, 'Money.amount');
|
|
205
|
+
}
|
|
206
|
+
function assertSameCurrency(a, b) {
|
|
207
|
+
assertMoney(a);
|
|
208
|
+
assertMoney(b);
|
|
209
|
+
if (a.currency !== b.currency) {
|
|
210
|
+
throw new MoneyError(MoneyErrorCode.CurrencyMismatch, `Cannot combine ${a.currency} with ${b.currency}`);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
function safeResult(amount, currency) {
|
|
214
|
+
if (!Number.isSafeInteger(amount)) {
|
|
215
|
+
throw new MoneyError(MoneyErrorCode.Overflow, 'Result is beyond the safe integer range');
|
|
216
|
+
}
|
|
217
|
+
return { amount: amount === 0 ? 0 : amount, currency };
|
|
218
|
+
}
|
|
219
|
+
function money(amount, currency) {
|
|
220
|
+
currencyExponent(currency);
|
|
221
|
+
assertWhole(amount, 'amount');
|
|
222
|
+
return { amount: amount === 0 ? 0 : amount, currency };
|
|
223
|
+
}
|
|
224
|
+
function decimalText(value) {
|
|
225
|
+
if (typeof value === 'number')
|
|
226
|
+
return Number.isFinite(value) ? String(value) : null;
|
|
227
|
+
if (typeof value === 'string')
|
|
228
|
+
return value.trim();
|
|
229
|
+
return null;
|
|
230
|
+
}
|
|
231
|
+
/** Exact: `19.99` → 1999 by reading the digits, never `x * 100`; refuses digits the currency lacks. */
|
|
232
|
+
function majorToMinor(major, currency) {
|
|
233
|
+
const exponent = currencyExponent(currency);
|
|
234
|
+
const text = decimalText(major);
|
|
235
|
+
const decimal = text === null ? null : parseDecimal(text);
|
|
236
|
+
if (!decimal) {
|
|
237
|
+
throw new MoneyError(MoneyErrorCode.NotANumber, `Not a decimal amount: ${String(major)}`);
|
|
238
|
+
}
|
|
239
|
+
return decimalToScaledInteger(decimal, exponent, DecimalRounding.Exact);
|
|
240
|
+
}
|
|
241
|
+
function minorToMajor(minor, currency) {
|
|
242
|
+
const exponent = currencyExponent(currency);
|
|
243
|
+
assertWhole(minor, 'minor');
|
|
244
|
+
return exponent === 0 ? minor : minor / 10 ** exponent;
|
|
245
|
+
}
|
|
246
|
+
function addMoney(a, b) {
|
|
247
|
+
assertSameCurrency(a, b);
|
|
248
|
+
return safeResult(a.amount + b.amount, a.currency);
|
|
249
|
+
}
|
|
250
|
+
function subtractMoney(a, b) {
|
|
251
|
+
assertSameCurrency(a, b);
|
|
252
|
+
return safeResult(a.amount - b.amount, a.currency);
|
|
253
|
+
}
|
|
254
|
+
function timesMoney(value, quantity) {
|
|
255
|
+
assertMoney(value);
|
|
256
|
+
if (typeof quantity !== 'number' || !Number.isSafeInteger(quantity)) {
|
|
257
|
+
throw new MoneyError(MoneyErrorCode.NotWhole, `Quantity must be a whole number, got ${String(quantity)}`);
|
|
258
|
+
}
|
|
259
|
+
if (quantity < 0) {
|
|
260
|
+
throw new MoneyError(MoneyErrorCode.Negative, `Quantity cannot be negative, got ${quantity}`);
|
|
261
|
+
}
|
|
262
|
+
return safeResult(value.amount * quantity, value.currency);
|
|
263
|
+
}
|
|
264
|
+
/** `percent` of an amount, rounded ONCE to a minor unit, half-to-even (banker's). */
|
|
265
|
+
function percentOf(value, percent) {
|
|
266
|
+
assertMoney(value);
|
|
267
|
+
if (typeof percent !== 'number' || !Number.isFinite(percent)) {
|
|
268
|
+
throw new MoneyError(MoneyErrorCode.NotANumber, `Percent must be a finite number, got ${String(percent)}`);
|
|
269
|
+
}
|
|
270
|
+
if (percent < 0) {
|
|
271
|
+
throw new MoneyError(MoneyErrorCode.Negative, `Percent cannot be negative, got ${percent}`);
|
|
272
|
+
}
|
|
273
|
+
const decimal = parseDecimal(String(percent));
|
|
274
|
+
if (!decimal) {
|
|
275
|
+
throw new MoneyError(MoneyErrorCode.NotANumber, `Percent must be a finite number, got ${String(percent)}`);
|
|
276
|
+
}
|
|
277
|
+
if (decimal.frac.length > MAX_PERCENT_DECIMALS) {
|
|
278
|
+
throw new MoneyError(MoneyErrorCode.TooManyDecimals, `Percent has more than ${MAX_PERCENT_DECIMALS} decimal digits`);
|
|
279
|
+
}
|
|
280
|
+
const scale = decimal.frac.length;
|
|
281
|
+
const percentScaled = decimalToScaledInteger(decimal, scale, DecimalRounding.Exact);
|
|
282
|
+
const numerator = Math.abs(value.amount) * percentScaled;
|
|
283
|
+
if (!Number.isSafeInteger(numerator)) {
|
|
284
|
+
throw new MoneyError(MoneyErrorCode.Overflow, 'Percent of this amount is beyond the safe integer range');
|
|
285
|
+
}
|
|
286
|
+
const magnitude = divideHalfEven(numerator, 100 * 10 ** scale);
|
|
287
|
+
return safeResult(value.amount < 0 ? -magnitude : magnitude, value.currency);
|
|
288
|
+
}
|
|
289
|
+
const formatters = new Map();
|
|
290
|
+
function formatMoney(value, locale) {
|
|
291
|
+
assertMoney(value);
|
|
292
|
+
const exponent = currencyExponent(value.currency);
|
|
293
|
+
const key = `${locale}|${value.currency}`;
|
|
294
|
+
let formatter = formatters.get(key);
|
|
295
|
+
if (!formatter) {
|
|
296
|
+
formatter = new Intl.NumberFormat(locale, {
|
|
297
|
+
style: 'currency',
|
|
298
|
+
currency: value.currency,
|
|
299
|
+
minimumFractionDigits: exponent,
|
|
300
|
+
maximumFractionDigits: exponent,
|
|
301
|
+
});
|
|
302
|
+
formatters.set(key, formatter);
|
|
303
|
+
}
|
|
304
|
+
return formatter.format(minorToMajor(value.amount, value.currency));
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* For the one boot migration of stored major-unit prices. A stored float may carry arithmetic noise
|
|
308
|
+
* (19.990000000000002), so extra digits round half-to-even instead of refusing. No usable price
|
|
309
|
+
* (null, '', NaN, text, a negative) → null; it never applies twice by itself — the caller marks rows.
|
|
310
|
+
*/
|
|
311
|
+
function migrateMajorPrice(value, currency) {
|
|
312
|
+
const exponent = currencyExponent(currency);
|
|
313
|
+
if (typeof value !== 'number' && typeof value !== 'string')
|
|
314
|
+
return null;
|
|
315
|
+
const text = decimalText(value);
|
|
316
|
+
const decimal = text ? parseDecimal(text) : null;
|
|
317
|
+
if (!decimal || (decimal.negative && (decimal.int || decimal.frac)))
|
|
318
|
+
return null;
|
|
319
|
+
try {
|
|
320
|
+
return decimalToScaledInteger(decimal, exponent, DecimalRounding.HalfEven);
|
|
321
|
+
}
|
|
322
|
+
catch {
|
|
323
|
+
return null;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* @vectoriox/iox-ui/commerce-core — the shared, FRAMEWORK-FREE core of selling (commerce plan C-D7).
|
|
329
|
+
*
|
|
330
|
+
* Money is integer minor units in one ISO-4217 currency, so the engine, the builder and iox-cms
|
|
331
|
+
* compute the same totals (trap T6: never a float). E0 ships Money and its helpers; priceCart,
|
|
332
|
+
* ORDER_TRANSITIONS and carts arrive with E1.
|
|
333
|
+
* ⚠️ Not re-exported from the main entry. Consumers wire the usual trio — ng-package raw-ts assets,
|
|
334
|
+
* jest moduleNameMapper, tsconfig paths — or `nest start` dies with ERR_REQUIRE_ESM.
|
|
335
|
+
*/
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Generated bundle index. Do not edit.
|
|
339
|
+
*/
|
|
340
|
+
|
|
341
|
+
export { CURRENCY_CODES, CURRENCY_EXPONENTS, CurrencyCode, MoneyError, MoneyErrorCode, addMoney, currencyExponent, formatMoney, isCurrencyCode, isMoney, majorToMinor, migrateMajorPrice, minorToMajor, money, percentOf, subtractMoney, timesMoney };
|
|
342
|
+
//# sourceMappingURL=vectoriox-iox-ui-commerce-core.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vectoriox-iox-ui-commerce-core.mjs","sources":["../../../projects/iox-ui/src/commerce-core/money-error.ts","../../../projects/iox-ui/src/commerce-core/currency.ts","../../../projects/iox-ui/src/commerce-core/decimal.ts","../../../projects/iox-ui/src/commerce-core/money.ts","../../../projects/iox-ui/src/commerce-core/public-api.ts","../../../projects/iox-ui/src/commerce-core/vectoriox-iox-ui-commerce-core.ts"],"sourcesContent":["export enum MoneyErrorCode {\n UnknownCurrency = 'unknown-currency',\n NotMoney = 'not-money',\n NotInteger = 'not-integer',\n NotANumber = 'not-a-number',\n TooManyDecimals = 'too-many-decimals',\n CurrencyMismatch = 'currency-mismatch',\n NotWhole = 'not-whole',\n Negative = 'negative',\n Overflow = 'overflow',\n}\n\nexport class MoneyError extends Error {\n constructor(readonly code: MoneyErrorCode, message: string) {\n super(message);\n this.name = 'MoneyError';\n }\n}\n","import { MoneyError, MoneyErrorCode } from './money-error';\n\nexport enum CurrencyCode {\n ILS = 'ILS',\n USD = 'USD',\n EUR = 'EUR',\n GBP = 'GBP',\n CHF = 'CHF',\n CAD = 'CAD',\n AUD = 'AUD',\n NZD = 'NZD',\n SEK = 'SEK',\n NOK = 'NOK',\n DKK = 'DKK',\n PLN = 'PLN',\n CZK = 'CZK',\n HUF = 'HUF',\n RON = 'RON',\n TRY = 'TRY',\n AED = 'AED',\n SAR = 'SAR',\n QAR = 'QAR',\n EGP = 'EGP',\n MAD = 'MAD',\n ZAR = 'ZAR',\n INR = 'INR',\n CNY = 'CNY',\n HKD = 'HKD',\n SGD = 'SGD',\n THB = 'THB',\n MXN = 'MXN',\n BRL = 'BRL',\n JPY = 'JPY',\n KRW = 'KRW',\n VND = 'VND',\n CLP = 'CLP',\n ISK = 'ISK',\n BHD = 'BHD',\n KWD = 'KWD',\n JOD = 'JOD',\n OMR = 'OMR',\n TND = 'TND',\n}\n\n/** ISO-4217 minor units — our own table, never Intl's CLDR digits (they differ for some codes). */\nexport const CURRENCY_EXPONENTS: Readonly<Record<CurrencyCode, number>> = Object.freeze({\n [CurrencyCode.ILS]: 2,\n [CurrencyCode.USD]: 2,\n [CurrencyCode.EUR]: 2,\n [CurrencyCode.GBP]: 2,\n [CurrencyCode.CHF]: 2,\n [CurrencyCode.CAD]: 2,\n [CurrencyCode.AUD]: 2,\n [CurrencyCode.NZD]: 2,\n [CurrencyCode.SEK]: 2,\n [CurrencyCode.NOK]: 2,\n [CurrencyCode.DKK]: 2,\n [CurrencyCode.PLN]: 2,\n [CurrencyCode.CZK]: 2,\n [CurrencyCode.HUF]: 2,\n [CurrencyCode.RON]: 2,\n [CurrencyCode.TRY]: 2,\n [CurrencyCode.AED]: 2,\n [CurrencyCode.SAR]: 2,\n [CurrencyCode.QAR]: 2,\n [CurrencyCode.EGP]: 2,\n [CurrencyCode.MAD]: 2,\n [CurrencyCode.ZAR]: 2,\n [CurrencyCode.INR]: 2,\n [CurrencyCode.CNY]: 2,\n [CurrencyCode.HKD]: 2,\n [CurrencyCode.SGD]: 2,\n [CurrencyCode.THB]: 2,\n [CurrencyCode.MXN]: 2,\n [CurrencyCode.BRL]: 2,\n [CurrencyCode.JPY]: 0,\n [CurrencyCode.KRW]: 0,\n [CurrencyCode.VND]: 0,\n [CurrencyCode.CLP]: 0,\n [CurrencyCode.ISK]: 0,\n [CurrencyCode.BHD]: 3,\n [CurrencyCode.KWD]: 3,\n [CurrencyCode.JOD]: 3,\n [CurrencyCode.OMR]: 3,\n [CurrencyCode.TND]: 3,\n});\n\nexport const CURRENCY_CODES: readonly CurrencyCode[] = Object.freeze(Object.values(CurrencyCode));\n\nexport function isCurrencyCode(value: unknown): value is CurrencyCode {\n return typeof value === 'string' && Object.prototype.hasOwnProperty.call(CURRENCY_EXPONENTS, value);\n}\n\nexport function currencyExponent(currency: CurrencyCode): number {\n if (!isCurrencyCode(currency)) {\n throw new MoneyError(MoneyErrorCode.UnknownCurrency, `Unknown currency: ${String(currency)}`);\n }\n return CURRENCY_EXPONENTS[currency];\n}\n","import { MoneyError, MoneyErrorCode } from './money-error';\n\nexport interface DecimalDigits {\n negative: boolean;\n int: string;\n frac: string;\n}\n\nexport enum DecimalRounding {\n Exact = 'exact',\n HalfEven = 'half-even',\n}\n\nconst DECIMAL = /^([+-])?(\\d*)(?:\\.(\\d*))?(?:[eE]([+-]?\\d{1,3}))?$/;\n\n/** Plain decimal text, or the e-notation `String(number)` produces below 1e-6 and from 1e21. */\nexport function parseDecimal(text: string): DecimalDigits | null {\n const match = DECIMAL.exec(text);\n if (!match) return null;\n const int = match[2] ?? '';\n const frac = match[3] ?? '';\n if (!int && !frac) return null;\n const digits = int + frac;\n const point = int.length + Number(match[4] ?? 0);\n const shiftedInt = point <= 0 ? '' : point >= digits.length ? digits + '0'.repeat(point - digits.length) : digits.slice(0, point);\n const shiftedFrac = point <= 0 ? '0'.repeat(-point) + digits : point >= digits.length ? '' : digits.slice(point);\n return {\n negative: match[1] === '-',\n int: shiftedInt.replace(/^0+/, ''),\n frac: shiftedFrac.replace(/0+$/, ''),\n };\n}\n\nfunction safeFromDigits(digits: string): number {\n const trimmed = digits.replace(/^0+/, '') || '0';\n const value = trimmed.length > 16 ? Infinity : Number(trimmed);\n if (!Number.isSafeInteger(value)) {\n throw new MoneyError(MoneyErrorCode.Overflow, `${digits} is beyond the safe integer range`);\n }\n return value;\n}\n\n/** Scales a parsed decimal by 10^exponent into an integer, without ever touching a float. */\nexport function decimalToScaledInteger(decimal: DecimalDigits, exponent: number, rounding: DecimalRounding): number {\n const kept = decimal.frac.slice(0, exponent);\n const rest = decimal.frac.slice(exponent);\n if (rest && rounding === DecimalRounding.Exact) {\n throw new MoneyError(MoneyErrorCode.TooManyDecimals, `More than ${exponent} decimal digits`);\n }\n let magnitude = safeFromDigits(decimal.int + kept.padEnd(exponent, '0'));\n if (rest) {\n const first = Number(rest[0]);\n const tie = first === 5 && /^5$/.test(rest);\n const up = first > 5 || (first === 5 && !tie) || (tie && magnitude % 2 === 1);\n if (up) magnitude += 1;\n if (!Number.isSafeInteger(magnitude)) {\n throw new MoneyError(MoneyErrorCode.Overflow, 'Rounded value is beyond the safe integer range');\n }\n }\n return decimal.negative && magnitude !== 0 ? -magnitude : magnitude;\n}\n\n/** Integer division rounded half-to-even; numerator ≥ 0, denominator > 0, both safe integers. */\nexport function divideHalfEven(numerator: number, denominator: number): number {\n let quotient = Math.trunc(numerator / denominator);\n let remainder = numerator - quotient * denominator;\n while (remainder < 0) {\n quotient -= 1;\n remainder += denominator;\n }\n while (remainder >= denominator) {\n quotient += 1;\n remainder -= denominator;\n }\n const twice = remainder * 2;\n if (twice > denominator || (twice === denominator && quotient % 2 === 1)) quotient += 1;\n return quotient;\n}\n","import { CurrencyCode, currencyExponent, isCurrencyCode } from './currency';\nimport { DecimalRounding, decimalToScaledInteger, divideHalfEven, parseDecimal } from './decimal';\nimport { MoneyError, MoneyErrorCode } from './money-error';\n\nexport interface Money {\n /** Integer minor units (agorot, cents, fils…). */\n amount: number;\n currency: CurrencyCode;\n}\n\nconst MAX_PERCENT_DECIMALS = 6;\n\nexport function isMoney(value: unknown): value is Money {\n if (typeof value !== 'object' || value === null) return false;\n const record = value as Record<string, unknown>;\n return Number.isSafeInteger(record['amount']) && isCurrencyCode(record['currency']);\n}\n\nfunction assertWhole(amount: number, what: string): void {\n if (typeof amount !== 'number' || !Number.isSafeInteger(amount)) {\n throw new MoneyError(MoneyErrorCode.NotInteger, `${what} must be a whole number of minor units, got ${String(amount)}`);\n }\n}\n\nfunction assertMoney(value: Money): void {\n if (typeof value !== 'object' || value === null) {\n throw new MoneyError(MoneyErrorCode.NotMoney, `Not a Money value: ${String(value)}`);\n }\n currencyExponent(value.currency);\n assertWhole(value.amount, 'Money.amount');\n}\n\nfunction assertSameCurrency(a: Money, b: Money): void {\n assertMoney(a);\n assertMoney(b);\n if (a.currency !== b.currency) {\n throw new MoneyError(MoneyErrorCode.CurrencyMismatch, `Cannot combine ${a.currency} with ${b.currency}`);\n }\n}\n\nfunction safeResult(amount: number, currency: CurrencyCode): Money {\n if (!Number.isSafeInteger(amount)) {\n throw new MoneyError(MoneyErrorCode.Overflow, 'Result is beyond the safe integer range');\n }\n return { amount: amount === 0 ? 0 : amount, currency };\n}\n\nexport function money(amount: number, currency: CurrencyCode): Money {\n currencyExponent(currency);\n assertWhole(amount, 'amount');\n return { amount: amount === 0 ? 0 : amount, currency };\n}\n\nfunction decimalText(value: number | string): string | null {\n if (typeof value === 'number') return Number.isFinite(value) ? String(value) : null;\n if (typeof value === 'string') return value.trim();\n return null;\n}\n\n/** Exact: `19.99` → 1999 by reading the digits, never `x * 100`; refuses digits the currency lacks. */\nexport function majorToMinor(major: number | string, currency: CurrencyCode): number {\n const exponent = currencyExponent(currency);\n const text = decimalText(major);\n const decimal = text === null ? null : parseDecimal(text);\n if (!decimal) {\n throw new MoneyError(MoneyErrorCode.NotANumber, `Not a decimal amount: ${String(major)}`);\n }\n return decimalToScaledInteger(decimal, exponent, DecimalRounding.Exact);\n}\n\nexport function minorToMajor(minor: number, currency: CurrencyCode): number {\n const exponent = currencyExponent(currency);\n assertWhole(minor, 'minor');\n return exponent === 0 ? minor : minor / 10 ** exponent;\n}\n\nexport function addMoney(a: Money, b: Money): Money {\n assertSameCurrency(a, b);\n return safeResult(a.amount + b.amount, a.currency);\n}\n\nexport function subtractMoney(a: Money, b: Money): Money {\n assertSameCurrency(a, b);\n return safeResult(a.amount - b.amount, a.currency);\n}\n\nexport function timesMoney(value: Money, quantity: number): Money {\n assertMoney(value);\n if (typeof quantity !== 'number' || !Number.isSafeInteger(quantity)) {\n throw new MoneyError(MoneyErrorCode.NotWhole, `Quantity must be a whole number, got ${String(quantity)}`);\n }\n if (quantity < 0) {\n throw new MoneyError(MoneyErrorCode.Negative, `Quantity cannot be negative, got ${quantity}`);\n }\n return safeResult(value.amount * quantity, value.currency);\n}\n\n/** `percent` of an amount, rounded ONCE to a minor unit, half-to-even (banker's). */\nexport function percentOf(value: Money, percent: number): Money {\n assertMoney(value);\n if (typeof percent !== 'number' || !Number.isFinite(percent)) {\n throw new MoneyError(MoneyErrorCode.NotANumber, `Percent must be a finite number, got ${String(percent)}`);\n }\n if (percent < 0) {\n throw new MoneyError(MoneyErrorCode.Negative, `Percent cannot be negative, got ${percent}`);\n }\n const decimal = parseDecimal(String(percent));\n if (!decimal) {\n throw new MoneyError(MoneyErrorCode.NotANumber, `Percent must be a finite number, got ${String(percent)}`);\n }\n if (decimal.frac.length > MAX_PERCENT_DECIMALS) {\n throw new MoneyError(MoneyErrorCode.TooManyDecimals, `Percent has more than ${MAX_PERCENT_DECIMALS} decimal digits`);\n }\n const scale = decimal.frac.length;\n const percentScaled = decimalToScaledInteger(decimal, scale, DecimalRounding.Exact);\n const numerator = Math.abs(value.amount) * percentScaled;\n if (!Number.isSafeInteger(numerator)) {\n throw new MoneyError(MoneyErrorCode.Overflow, 'Percent of this amount is beyond the safe integer range');\n }\n const magnitude = divideHalfEven(numerator, 100 * 10 ** scale);\n return safeResult(value.amount < 0 ? -magnitude : magnitude, value.currency);\n}\n\nconst formatters = new Map<string, Intl.NumberFormat>();\n\nexport function formatMoney(value: Money, locale: string): string {\n assertMoney(value);\n const exponent = currencyExponent(value.currency);\n const key = `${locale}|${value.currency}`;\n let formatter = formatters.get(key);\n if (!formatter) {\n formatter = new Intl.NumberFormat(locale, {\n style: 'currency',\n currency: value.currency,\n minimumFractionDigits: exponent,\n maximumFractionDigits: exponent,\n });\n formatters.set(key, formatter);\n }\n return formatter.format(minorToMajor(value.amount, value.currency));\n}\n\n/**\n * For the one boot migration of stored major-unit prices. A stored float may carry arithmetic noise\n * (19.990000000000002), so extra digits round half-to-even instead of refusing. No usable price\n * (null, '', NaN, text, a negative) → null; it never applies twice by itself — the caller marks rows.\n */\nexport function migrateMajorPrice(value: unknown, currency: CurrencyCode): number | null {\n const exponent = currencyExponent(currency);\n if (typeof value !== 'number' && typeof value !== 'string') return null;\n const text = decimalText(value);\n const decimal = text ? parseDecimal(text) : null;\n if (!decimal || (decimal.negative && (decimal.int || decimal.frac))) return null;\n try {\n return decimalToScaledInteger(decimal, exponent, DecimalRounding.HalfEven);\n } catch {\n return null;\n }\n}\n","/**\n * @vectoriox/iox-ui/commerce-core — the shared, FRAMEWORK-FREE core of selling (commerce plan C-D7).\n *\n * Money is integer minor units in one ISO-4217 currency, so the engine, the builder and iox-cms\n * compute the same totals (trap T6: never a float). E0 ships Money and its helpers; priceCart,\n * ORDER_TRANSITIONS and carts arrive with E1.\n * ⚠️ Not re-exported from the main entry. Consumers wire the usual trio — ng-package raw-ts assets,\n * jest moduleNameMapper, tsconfig paths — or `nest start` dies with ERR_REQUIRE_ESM.\n */\nexport * from './money-error';\nexport * from './currency';\nexport * from './money';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":"IAAY;AAAZ,CAAA,UAAY,cAAc,EAAA;AACtB,IAAA,cAAA,CAAA,iBAAA,CAAA,GAAA,kBAAoC;AACpC,IAAA,cAAA,CAAA,UAAA,CAAA,GAAA,WAAsB;AACtB,IAAA,cAAA,CAAA,YAAA,CAAA,GAAA,aAA0B;AAC1B,IAAA,cAAA,CAAA,YAAA,CAAA,GAAA,cAA2B;AAC3B,IAAA,cAAA,CAAA,iBAAA,CAAA,GAAA,mBAAqC;AACrC,IAAA,cAAA,CAAA,kBAAA,CAAA,GAAA,mBAAsC;AACtC,IAAA,cAAA,CAAA,UAAA,CAAA,GAAA,WAAsB;AACtB,IAAA,cAAA,CAAA,UAAA,CAAA,GAAA,UAAqB;AACrB,IAAA,cAAA,CAAA,UAAA,CAAA,GAAA,UAAqB;AACzB,CAAC,EAVW,cAAc,KAAd,cAAc,GAAA,EAAA,CAAA,CAAA;AAYpB,MAAO,UAAW,SAAQ,KAAK,CAAA;IACjC,WAAA,CAAqB,IAAoB,EAAE,OAAe,EAAA;QACtD,KAAK,CAAC,OAAO,CAAC;QADG,IAAA,CAAA,IAAI,GAAJ,IAAI;AAErB,QAAA,IAAI,CAAC,IAAI,GAAG,YAAY;IAC5B;AACH;;ICfW;AAAZ,CAAA,UAAY,YAAY,EAAA;AACpB,IAAA,YAAA,CAAA,KAAA,CAAA,GAAA,KAAW;AACX,IAAA,YAAA,CAAA,KAAA,CAAA,GAAA,KAAW;AACX,IAAA,YAAA,CAAA,KAAA,CAAA,GAAA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0",
|
|
@@ -23,6 +23,10 @@
|
|
|
23
23
|
"types": "./actions-core/index.d.ts",
|
|
24
24
|
"default": "./fesm2022/vectoriox-iox-ui-actions-core.mjs"
|
|
25
25
|
},
|
|
26
|
+
"./commerce-core": {
|
|
27
|
+
"types": "./commerce-core/index.d.ts",
|
|
28
|
+
"default": "./fesm2022/vectoriox-iox-ui-commerce-core.mjs"
|
|
29
|
+
},
|
|
26
30
|
"./composite-core": {
|
|
27
31
|
"types": "./composite-core/index.d.ts",
|
|
28
32
|
"default": "./fesm2022/vectoriox-iox-ui-composite-core.mjs"
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { MoneyError, MoneyErrorCode } from './money-error';
|
|
2
|
+
|
|
3
|
+
export enum CurrencyCode {
|
|
4
|
+
ILS = 'ILS',
|
|
5
|
+
USD = 'USD',
|
|
6
|
+
EUR = 'EUR',
|
|
7
|
+
GBP = 'GBP',
|
|
8
|
+
CHF = 'CHF',
|
|
9
|
+
CAD = 'CAD',
|
|
10
|
+
AUD = 'AUD',
|
|
11
|
+
NZD = 'NZD',
|
|
12
|
+
SEK = 'SEK',
|
|
13
|
+
NOK = 'NOK',
|
|
14
|
+
DKK = 'DKK',
|
|
15
|
+
PLN = 'PLN',
|
|
16
|
+
CZK = 'CZK',
|
|
17
|
+
HUF = 'HUF',
|
|
18
|
+
RON = 'RON',
|
|
19
|
+
TRY = 'TRY',
|
|
20
|
+
AED = 'AED',
|
|
21
|
+
SAR = 'SAR',
|
|
22
|
+
QAR = 'QAR',
|
|
23
|
+
EGP = 'EGP',
|
|
24
|
+
MAD = 'MAD',
|
|
25
|
+
ZAR = 'ZAR',
|
|
26
|
+
INR = 'INR',
|
|
27
|
+
CNY = 'CNY',
|
|
28
|
+
HKD = 'HKD',
|
|
29
|
+
SGD = 'SGD',
|
|
30
|
+
THB = 'THB',
|
|
31
|
+
MXN = 'MXN',
|
|
32
|
+
BRL = 'BRL',
|
|
33
|
+
JPY = 'JPY',
|
|
34
|
+
KRW = 'KRW',
|
|
35
|
+
VND = 'VND',
|
|
36
|
+
CLP = 'CLP',
|
|
37
|
+
ISK = 'ISK',
|
|
38
|
+
BHD = 'BHD',
|
|
39
|
+
KWD = 'KWD',
|
|
40
|
+
JOD = 'JOD',
|
|
41
|
+
OMR = 'OMR',
|
|
42
|
+
TND = 'TND',
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** ISO-4217 minor units — our own table, never Intl's CLDR digits (they differ for some codes). */
|
|
46
|
+
export const CURRENCY_EXPONENTS: Readonly<Record<CurrencyCode, number>> = Object.freeze({
|
|
47
|
+
[CurrencyCode.ILS]: 2,
|
|
48
|
+
[CurrencyCode.USD]: 2,
|
|
49
|
+
[CurrencyCode.EUR]: 2,
|
|
50
|
+
[CurrencyCode.GBP]: 2,
|
|
51
|
+
[CurrencyCode.CHF]: 2,
|
|
52
|
+
[CurrencyCode.CAD]: 2,
|
|
53
|
+
[CurrencyCode.AUD]: 2,
|
|
54
|
+
[CurrencyCode.NZD]: 2,
|
|
55
|
+
[CurrencyCode.SEK]: 2,
|
|
56
|
+
[CurrencyCode.NOK]: 2,
|
|
57
|
+
[CurrencyCode.DKK]: 2,
|
|
58
|
+
[CurrencyCode.PLN]: 2,
|
|
59
|
+
[CurrencyCode.CZK]: 2,
|
|
60
|
+
[CurrencyCode.HUF]: 2,
|
|
61
|
+
[CurrencyCode.RON]: 2,
|
|
62
|
+
[CurrencyCode.TRY]: 2,
|
|
63
|
+
[CurrencyCode.AED]: 2,
|
|
64
|
+
[CurrencyCode.SAR]: 2,
|
|
65
|
+
[CurrencyCode.QAR]: 2,
|
|
66
|
+
[CurrencyCode.EGP]: 2,
|
|
67
|
+
[CurrencyCode.MAD]: 2,
|
|
68
|
+
[CurrencyCode.ZAR]: 2,
|
|
69
|
+
[CurrencyCode.INR]: 2,
|
|
70
|
+
[CurrencyCode.CNY]: 2,
|
|
71
|
+
[CurrencyCode.HKD]: 2,
|
|
72
|
+
[CurrencyCode.SGD]: 2,
|
|
73
|
+
[CurrencyCode.THB]: 2,
|
|
74
|
+
[CurrencyCode.MXN]: 2,
|
|
75
|
+
[CurrencyCode.BRL]: 2,
|
|
76
|
+
[CurrencyCode.JPY]: 0,
|
|
77
|
+
[CurrencyCode.KRW]: 0,
|
|
78
|
+
[CurrencyCode.VND]: 0,
|
|
79
|
+
[CurrencyCode.CLP]: 0,
|
|
80
|
+
[CurrencyCode.ISK]: 0,
|
|
81
|
+
[CurrencyCode.BHD]: 3,
|
|
82
|
+
[CurrencyCode.KWD]: 3,
|
|
83
|
+
[CurrencyCode.JOD]: 3,
|
|
84
|
+
[CurrencyCode.OMR]: 3,
|
|
85
|
+
[CurrencyCode.TND]: 3,
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
export const CURRENCY_CODES: readonly CurrencyCode[] = Object.freeze(Object.values(CurrencyCode));
|
|
89
|
+
|
|
90
|
+
export function isCurrencyCode(value: unknown): value is CurrencyCode {
|
|
91
|
+
return typeof value === 'string' && Object.prototype.hasOwnProperty.call(CURRENCY_EXPONENTS, value);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function currencyExponent(currency: CurrencyCode): number {
|
|
95
|
+
if (!isCurrencyCode(currency)) {
|
|
96
|
+
throw new MoneyError(MoneyErrorCode.UnknownCurrency, `Unknown currency: ${String(currency)}`);
|
|
97
|
+
}
|
|
98
|
+
return CURRENCY_EXPONENTS[currency];
|
|
99
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { MoneyError, MoneyErrorCode } from './money-error';
|
|
2
|
+
|
|
3
|
+
export interface DecimalDigits {
|
|
4
|
+
negative: boolean;
|
|
5
|
+
int: string;
|
|
6
|
+
frac: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export enum DecimalRounding {
|
|
10
|
+
Exact = 'exact',
|
|
11
|
+
HalfEven = 'half-even',
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const DECIMAL = /^([+-])?(\d*)(?:\.(\d*))?(?:[eE]([+-]?\d{1,3}))?$/;
|
|
15
|
+
|
|
16
|
+
/** Plain decimal text, or the e-notation `String(number)` produces below 1e-6 and from 1e21. */
|
|
17
|
+
export function parseDecimal(text: string): DecimalDigits | null {
|
|
18
|
+
const match = DECIMAL.exec(text);
|
|
19
|
+
if (!match) return null;
|
|
20
|
+
const int = match[2] ?? '';
|
|
21
|
+
const frac = match[3] ?? '';
|
|
22
|
+
if (!int && !frac) return null;
|
|
23
|
+
const digits = int + frac;
|
|
24
|
+
const point = int.length + Number(match[4] ?? 0);
|
|
25
|
+
const shiftedInt = point <= 0 ? '' : point >= digits.length ? digits + '0'.repeat(point - digits.length) : digits.slice(0, point);
|
|
26
|
+
const shiftedFrac = point <= 0 ? '0'.repeat(-point) + digits : point >= digits.length ? '' : digits.slice(point);
|
|
27
|
+
return {
|
|
28
|
+
negative: match[1] === '-',
|
|
29
|
+
int: shiftedInt.replace(/^0+/, ''),
|
|
30
|
+
frac: shiftedFrac.replace(/0+$/, ''),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function safeFromDigits(digits: string): number {
|
|
35
|
+
const trimmed = digits.replace(/^0+/, '') || '0';
|
|
36
|
+
const value = trimmed.length > 16 ? Infinity : Number(trimmed);
|
|
37
|
+
if (!Number.isSafeInteger(value)) {
|
|
38
|
+
throw new MoneyError(MoneyErrorCode.Overflow, `${digits} is beyond the safe integer range`);
|
|
39
|
+
}
|
|
40
|
+
return value;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Scales a parsed decimal by 10^exponent into an integer, without ever touching a float. */
|
|
44
|
+
export function decimalToScaledInteger(decimal: DecimalDigits, exponent: number, rounding: DecimalRounding): number {
|
|
45
|
+
const kept = decimal.frac.slice(0, exponent);
|
|
46
|
+
const rest = decimal.frac.slice(exponent);
|
|
47
|
+
if (rest && rounding === DecimalRounding.Exact) {
|
|
48
|
+
throw new MoneyError(MoneyErrorCode.TooManyDecimals, `More than ${exponent} decimal digits`);
|
|
49
|
+
}
|
|
50
|
+
let magnitude = safeFromDigits(decimal.int + kept.padEnd(exponent, '0'));
|
|
51
|
+
if (rest) {
|
|
52
|
+
const first = Number(rest[0]);
|
|
53
|
+
const tie = first === 5 && /^5$/.test(rest);
|
|
54
|
+
const up = first > 5 || (first === 5 && !tie) || (tie && magnitude % 2 === 1);
|
|
55
|
+
if (up) magnitude += 1;
|
|
56
|
+
if (!Number.isSafeInteger(magnitude)) {
|
|
57
|
+
throw new MoneyError(MoneyErrorCode.Overflow, 'Rounded value is beyond the safe integer range');
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return decimal.negative && magnitude !== 0 ? -magnitude : magnitude;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Integer division rounded half-to-even; numerator ≥ 0, denominator > 0, both safe integers. */
|
|
64
|
+
export function divideHalfEven(numerator: number, denominator: number): number {
|
|
65
|
+
let quotient = Math.trunc(numerator / denominator);
|
|
66
|
+
let remainder = numerator - quotient * denominator;
|
|
67
|
+
while (remainder < 0) {
|
|
68
|
+
quotient -= 1;
|
|
69
|
+
remainder += denominator;
|
|
70
|
+
}
|
|
71
|
+
while (remainder >= denominator) {
|
|
72
|
+
quotient += 1;
|
|
73
|
+
remainder -= denominator;
|
|
74
|
+
}
|
|
75
|
+
const twice = remainder * 2;
|
|
76
|
+
if (twice > denominator || (twice === denominator && quotient % 2 === 1)) quotient += 1;
|
|
77
|
+
return quotient;
|
|
78
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export enum MoneyErrorCode {
|
|
2
|
+
UnknownCurrency = 'unknown-currency',
|
|
3
|
+
NotMoney = 'not-money',
|
|
4
|
+
NotInteger = 'not-integer',
|
|
5
|
+
NotANumber = 'not-a-number',
|
|
6
|
+
TooManyDecimals = 'too-many-decimals',
|
|
7
|
+
CurrencyMismatch = 'currency-mismatch',
|
|
8
|
+
NotWhole = 'not-whole',
|
|
9
|
+
Negative = 'negative',
|
|
10
|
+
Overflow = 'overflow',
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export class MoneyError extends Error {
|
|
14
|
+
constructor(readonly code: MoneyErrorCode, message: string) {
|
|
15
|
+
super(message);
|
|
16
|
+
this.name = 'MoneyError';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { CurrencyCode, currencyExponent, isCurrencyCode } from './currency';
|
|
2
|
+
import { DecimalRounding, decimalToScaledInteger, divideHalfEven, parseDecimal } from './decimal';
|
|
3
|
+
import { MoneyError, MoneyErrorCode } from './money-error';
|
|
4
|
+
|
|
5
|
+
export interface Money {
|
|
6
|
+
/** Integer minor units (agorot, cents, fils…). */
|
|
7
|
+
amount: number;
|
|
8
|
+
currency: CurrencyCode;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const MAX_PERCENT_DECIMALS = 6;
|
|
12
|
+
|
|
13
|
+
export function isMoney(value: unknown): value is Money {
|
|
14
|
+
if (typeof value !== 'object' || value === null) return false;
|
|
15
|
+
const record = value as Record<string, unknown>;
|
|
16
|
+
return Number.isSafeInteger(record['amount']) && isCurrencyCode(record['currency']);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function assertWhole(amount: number, what: string): void {
|
|
20
|
+
if (typeof amount !== 'number' || !Number.isSafeInteger(amount)) {
|
|
21
|
+
throw new MoneyError(MoneyErrorCode.NotInteger, `${what} must be a whole number of minor units, got ${String(amount)}`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function assertMoney(value: Money): void {
|
|
26
|
+
if (typeof value !== 'object' || value === null) {
|
|
27
|
+
throw new MoneyError(MoneyErrorCode.NotMoney, `Not a Money value: ${String(value)}`);
|
|
28
|
+
}
|
|
29
|
+
currencyExponent(value.currency);
|
|
30
|
+
assertWhole(value.amount, 'Money.amount');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function assertSameCurrency(a: Money, b: Money): void {
|
|
34
|
+
assertMoney(a);
|
|
35
|
+
assertMoney(b);
|
|
36
|
+
if (a.currency !== b.currency) {
|
|
37
|
+
throw new MoneyError(MoneyErrorCode.CurrencyMismatch, `Cannot combine ${a.currency} with ${b.currency}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function safeResult(amount: number, currency: CurrencyCode): Money {
|
|
42
|
+
if (!Number.isSafeInteger(amount)) {
|
|
43
|
+
throw new MoneyError(MoneyErrorCode.Overflow, 'Result is beyond the safe integer range');
|
|
44
|
+
}
|
|
45
|
+
return { amount: amount === 0 ? 0 : amount, currency };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function money(amount: number, currency: CurrencyCode): Money {
|
|
49
|
+
currencyExponent(currency);
|
|
50
|
+
assertWhole(amount, 'amount');
|
|
51
|
+
return { amount: amount === 0 ? 0 : amount, currency };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function decimalText(value: number | string): string | null {
|
|
55
|
+
if (typeof value === 'number') return Number.isFinite(value) ? String(value) : null;
|
|
56
|
+
if (typeof value === 'string') return value.trim();
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Exact: `19.99` → 1999 by reading the digits, never `x * 100`; refuses digits the currency lacks. */
|
|
61
|
+
export function majorToMinor(major: number | string, currency: CurrencyCode): number {
|
|
62
|
+
const exponent = currencyExponent(currency);
|
|
63
|
+
const text = decimalText(major);
|
|
64
|
+
const decimal = text === null ? null : parseDecimal(text);
|
|
65
|
+
if (!decimal) {
|
|
66
|
+
throw new MoneyError(MoneyErrorCode.NotANumber, `Not a decimal amount: ${String(major)}`);
|
|
67
|
+
}
|
|
68
|
+
return decimalToScaledInteger(decimal, exponent, DecimalRounding.Exact);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function minorToMajor(minor: number, currency: CurrencyCode): number {
|
|
72
|
+
const exponent = currencyExponent(currency);
|
|
73
|
+
assertWhole(minor, 'minor');
|
|
74
|
+
return exponent === 0 ? minor : minor / 10 ** exponent;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function addMoney(a: Money, b: Money): Money {
|
|
78
|
+
assertSameCurrency(a, b);
|
|
79
|
+
return safeResult(a.amount + b.amount, a.currency);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function subtractMoney(a: Money, b: Money): Money {
|
|
83
|
+
assertSameCurrency(a, b);
|
|
84
|
+
return safeResult(a.amount - b.amount, a.currency);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function timesMoney(value: Money, quantity: number): Money {
|
|
88
|
+
assertMoney(value);
|
|
89
|
+
if (typeof quantity !== 'number' || !Number.isSafeInteger(quantity)) {
|
|
90
|
+
throw new MoneyError(MoneyErrorCode.NotWhole, `Quantity must be a whole number, got ${String(quantity)}`);
|
|
91
|
+
}
|
|
92
|
+
if (quantity < 0) {
|
|
93
|
+
throw new MoneyError(MoneyErrorCode.Negative, `Quantity cannot be negative, got ${quantity}`);
|
|
94
|
+
}
|
|
95
|
+
return safeResult(value.amount * quantity, value.currency);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** `percent` of an amount, rounded ONCE to a minor unit, half-to-even (banker's). */
|
|
99
|
+
export function percentOf(value: Money, percent: number): Money {
|
|
100
|
+
assertMoney(value);
|
|
101
|
+
if (typeof percent !== 'number' || !Number.isFinite(percent)) {
|
|
102
|
+
throw new MoneyError(MoneyErrorCode.NotANumber, `Percent must be a finite number, got ${String(percent)}`);
|
|
103
|
+
}
|
|
104
|
+
if (percent < 0) {
|
|
105
|
+
throw new MoneyError(MoneyErrorCode.Negative, `Percent cannot be negative, got ${percent}`);
|
|
106
|
+
}
|
|
107
|
+
const decimal = parseDecimal(String(percent));
|
|
108
|
+
if (!decimal) {
|
|
109
|
+
throw new MoneyError(MoneyErrorCode.NotANumber, `Percent must be a finite number, got ${String(percent)}`);
|
|
110
|
+
}
|
|
111
|
+
if (decimal.frac.length > MAX_PERCENT_DECIMALS) {
|
|
112
|
+
throw new MoneyError(MoneyErrorCode.TooManyDecimals, `Percent has more than ${MAX_PERCENT_DECIMALS} decimal digits`);
|
|
113
|
+
}
|
|
114
|
+
const scale = decimal.frac.length;
|
|
115
|
+
const percentScaled = decimalToScaledInteger(decimal, scale, DecimalRounding.Exact);
|
|
116
|
+
const numerator = Math.abs(value.amount) * percentScaled;
|
|
117
|
+
if (!Number.isSafeInteger(numerator)) {
|
|
118
|
+
throw new MoneyError(MoneyErrorCode.Overflow, 'Percent of this amount is beyond the safe integer range');
|
|
119
|
+
}
|
|
120
|
+
const magnitude = divideHalfEven(numerator, 100 * 10 ** scale);
|
|
121
|
+
return safeResult(value.amount < 0 ? -magnitude : magnitude, value.currency);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const formatters = new Map<string, Intl.NumberFormat>();
|
|
125
|
+
|
|
126
|
+
export function formatMoney(value: Money, locale: string): string {
|
|
127
|
+
assertMoney(value);
|
|
128
|
+
const exponent = currencyExponent(value.currency);
|
|
129
|
+
const key = `${locale}|${value.currency}`;
|
|
130
|
+
let formatter = formatters.get(key);
|
|
131
|
+
if (!formatter) {
|
|
132
|
+
formatter = new Intl.NumberFormat(locale, {
|
|
133
|
+
style: 'currency',
|
|
134
|
+
currency: value.currency,
|
|
135
|
+
minimumFractionDigits: exponent,
|
|
136
|
+
maximumFractionDigits: exponent,
|
|
137
|
+
});
|
|
138
|
+
formatters.set(key, formatter);
|
|
139
|
+
}
|
|
140
|
+
return formatter.format(minorToMajor(value.amount, value.currency));
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* For the one boot migration of stored major-unit prices. A stored float may carry arithmetic noise
|
|
145
|
+
* (19.990000000000002), so extra digits round half-to-even instead of refusing. No usable price
|
|
146
|
+
* (null, '', NaN, text, a negative) → null; it never applies twice by itself — the caller marks rows.
|
|
147
|
+
*/
|
|
148
|
+
export function migrateMajorPrice(value: unknown, currency: CurrencyCode): number | null {
|
|
149
|
+
const exponent = currencyExponent(currency);
|
|
150
|
+
if (typeof value !== 'number' && typeof value !== 'string') return null;
|
|
151
|
+
const text = decimalText(value);
|
|
152
|
+
const decimal = text ? parseDecimal(text) : null;
|
|
153
|
+
if (!decimal || (decimal.negative && (decimal.int || decimal.frac))) return null;
|
|
154
|
+
try {
|
|
155
|
+
return decimalToScaledInteger(decimal, exponent, DecimalRounding.HalfEven);
|
|
156
|
+
} catch {
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vectoriox/iox-ui/commerce-core — the shared, FRAMEWORK-FREE core of selling (commerce plan C-D7).
|
|
3
|
+
*
|
|
4
|
+
* Money is integer minor units in one ISO-4217 currency, so the engine, the builder and iox-cms
|
|
5
|
+
* compute the same totals (trap T6: never a float). E0 ships Money and its helpers; priceCart,
|
|
6
|
+
* ORDER_TRANSITIONS and carts arrive with E1.
|
|
7
|
+
* ⚠️ Not re-exported from the main entry. Consumers wire the usual trio — ng-package raw-ts assets,
|
|
8
|
+
* jest moduleNameMapper, tsconfig paths — or `nest start` dies with ERR_REQUIRE_ESM.
|
|
9
|
+
*/
|
|
10
|
+
export * from './money-error';
|
|
11
|
+
export * from './currency';
|
|
12
|
+
export * from './money';
|