subunit-money 3.0.0 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,58 +1,1275 @@
1
- "use strict";
1
+ var __typeError = (msg) => {
2
+ throw TypeError(msg);
3
+ };
4
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
5
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
6
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
7
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
8
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
9
+
10
+ // lib/errors.ts
11
+ var CurrencyMismatchError = class _CurrencyMismatchError extends TypeError {
12
+ constructor(fromCurrency, toCurrency) {
13
+ super(`Cannot operate on ${fromCurrency} and ${toCurrency} - currencies must match`);
14
+ this.name = "CurrencyMismatchError";
15
+ this.fromCurrency = fromCurrency;
16
+ this.toCurrency = toCurrency;
17
+ Error.captureStackTrace?.(this, _CurrencyMismatchError);
18
+ }
19
+ };
20
+ var CurrencyUnknownError = class _CurrencyUnknownError extends TypeError {
21
+ constructor(currency) {
22
+ super(`Unknown currency '${currency}' - register it first with Money.registerCurrency()`);
23
+ this.name = "CurrencyUnknownError";
24
+ this.currency = currency;
25
+ Error.captureStackTrace?.(this, _CurrencyUnknownError);
26
+ }
27
+ };
28
+ var SubunitError = class _SubunitError extends RangeError {
29
+ constructor(currency, maxDecimals) {
30
+ super(`${currency} only supports ${maxDecimals} decimal place(s)`);
31
+ this.name = "SubunitError";
32
+ this.currency = currency;
33
+ this.maxDecimals = maxDecimals;
34
+ Error.captureStackTrace?.(this, _SubunitError);
35
+ }
36
+ };
37
+ var AmountError = class _AmountError extends TypeError {
38
+ constructor(amount) {
39
+ super(`Invalid amount: ${JSON.stringify(amount)}`);
40
+ this.name = "AmountError";
41
+ this.amount = amount;
42
+ Error.captureStackTrace?.(this, _AmountError);
43
+ }
44
+ };
45
+ var ExchangeRateError = class _ExchangeRateError extends Error {
46
+ constructor(fromCurrency, toCurrency) {
47
+ super(`No exchange rate available from ${fromCurrency} to ${toCurrency}`);
48
+ this.name = "ExchangeRateError";
49
+ this.fromCurrency = fromCurrency;
50
+ this.toCurrency = toCurrency;
51
+ Error.captureStackTrace?.(this, _ExchangeRateError);
52
+ }
53
+ };
54
+
55
+ // lib/currency.ts
56
+ var currencies = /* @__PURE__ */ new Map();
57
+ function registerCurrency(code, decimalDigits, displayDecimals) {
58
+ currencies.set(code, { code, decimalDigits, displayDecimals });
59
+ }
60
+ function getCurrency(code) {
61
+ return currencies.get(code);
62
+ }
63
+ function hasCurrency(code) {
64
+ return currencies.has(code);
65
+ }
66
+ function getAllCurrencies() {
67
+ return Array.from(currencies.values()).sort((a, b) => a.code.localeCompare(b.code));
68
+ }
69
+ function loadCurrencyMap(map) {
70
+ for (const [code, data] of Object.entries(map)) {
71
+ registerCurrency(code, data.decimal_digits);
72
+ }
73
+ }
74
+ function clearCurrencies() {
75
+ currencies.clear();
76
+ }
77
+
78
+ // lib/money.ts
79
+ var _subunits, _currencyDef, _Money_instances, parseAmount_fn, _Money_static, formatForDisplay_fn, assertSameCurrency_fn, getInternalValue_fn, parseFactor_fn, roundedDivide_fn, createFromSubunits_fn, formatSubunits_fn;
80
+ var _Money = class _Money {
81
+ /**
82
+ * Create a new Money instance.
83
+ *
84
+ * @param currency - ISO 4217 currency code (must be registered)
85
+ * @param amount - The amount as a number or string
86
+ * @throws {CurrencyUnknownError} If the currency is not registered
87
+ * @throws {AmountError} If the amount is not a valid number
88
+ * @throws {SubunitError} If the amount has more decimals than the currency allows
89
+ */
90
+ constructor(currency, amount) {
91
+ __privateAdd(this, _Money_instances);
92
+ // Private BigInt storage - stores currency native subunits directly
93
+ __privateAdd(this, _subunits);
94
+ __privateAdd(this, _currencyDef);
95
+ var _a, _b;
96
+ const currencyDef = getCurrency(currency);
97
+ if (!currencyDef) {
98
+ throw new CurrencyUnknownError(currency);
99
+ }
100
+ this.currency = currency;
101
+ __privateSet(this, _currencyDef, currencyDef);
102
+ __privateSet(this, _subunits, __privateMethod(this, _Money_instances, parseAmount_fn).call(this, amount));
103
+ this.amount = __privateMethod(_a = _Money, _Money_static, formatSubunits_fn).call(_a, __privateGet(this, _subunits), currencyDef);
104
+ this.displayAmount = __privateMethod(_b = _Money, _Money_static, formatForDisplay_fn).call(_b, this.amount, currencyDef);
105
+ }
106
+ /**
107
+ * Custom console inspection for Node.js.
108
+ * Shows the amount and currency instead of just the class name.
109
+ */
110
+ [/* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom")]() {
111
+ return `Money { amount: '${this.displayAmount}', currency: '${this.currency}' }`;
112
+ }
113
+ // ============ Arithmetic Operations ============
114
+ /**
115
+ * Add another Money amount.
116
+ * @throws {CurrencyMismatchError} If currencies don't match
117
+ */
118
+ add(other) {
119
+ var _a, _b;
120
+ __privateMethod(this, _Money_instances, assertSameCurrency_fn).call(this, other);
121
+ const result = __privateGet(this, _subunits) + __privateMethod(_a = other, _Money_instances, getInternalValue_fn).call(_a);
122
+ return __privateMethod(_b = _Money, _Money_static, createFromSubunits_fn).call(_b, result, this.currency, __privateGet(this, _currencyDef));
123
+ }
124
+ /**
125
+ * Subtract another Money amount.
126
+ * @throws {CurrencyMismatchError} If currencies don't match
127
+ */
128
+ subtract(other) {
129
+ var _a, _b;
130
+ __privateMethod(this, _Money_instances, assertSameCurrency_fn).call(this, other);
131
+ const result = __privateGet(this, _subunits) - __privateMethod(_a = other, _Money_instances, getInternalValue_fn).call(_a);
132
+ return __privateMethod(_b = _Money, _Money_static, createFromSubunits_fn).call(_b, result, this.currency, __privateGet(this, _currencyDef));
133
+ }
134
+ /**
135
+ * Multiply by a factor.
136
+ *
137
+ * DESIGN: Rounds immediately after multiplication using banker's rounding
138
+ * (round half-to-even). This prevents the "split penny problem".
139
+ */
140
+ multiply(factor) {
141
+ var _a, _b, _c;
142
+ if (typeof factor !== "number" || !Number.isFinite(factor)) {
143
+ throw new TypeError(`Factor must be a finite number, got: ${factor}`);
144
+ }
145
+ const { value: factorValue, scale } = __privateMethod(_a = _Money, _Money_static, parseFactor_fn).call(_a, factor);
146
+ const product = __privateGet(this, _subunits) * factorValue;
147
+ const divisor = 10n ** scale;
148
+ const result = __privateMethod(_b = _Money, _Money_static, roundedDivide_fn).call(_b, product, divisor);
149
+ return __privateMethod(_c = _Money, _Money_static, createFromSubunits_fn).call(_c, result, this.currency, __privateGet(this, _currencyDef));
150
+ }
151
+ /**
152
+ * Allocate this amount proportionally.
153
+ * Handles remainder distribution to avoid losing pennies.
154
+ *
155
+ * @param proportions - Array of proportions (e.g., [1, 1, 1] for three-way split)
156
+ * @returns Array of Money objects that sum to the original amount
157
+ */
158
+ allocate(proportions) {
159
+ if (!Array.isArray(proportions) || proportions.length === 0) {
160
+ throw new TypeError("Proportions must be a non-empty array");
161
+ }
162
+ for (const p of proportions) {
163
+ if (typeof p !== "number" || !Number.isFinite(p) || p < 0) {
164
+ throw new TypeError("All proportions must be non-negative finite numbers");
165
+ }
166
+ }
167
+ const total = proportions.reduce((sum, p) => sum + p, 0);
168
+ if (total <= 0) {
169
+ throw new TypeError("Sum of proportions must be positive");
170
+ }
171
+ const totalSubunits = __privateGet(this, _subunits);
172
+ const allocations = proportions.map((p) => {
173
+ return totalSubunits * BigInt(Math.round(p * 1e6)) / BigInt(Math.round(total * 1e6));
174
+ });
175
+ let remainder = totalSubunits - allocations.reduce((sum, a) => sum + a, 0n);
176
+ let i = 0;
177
+ while (remainder > 0n) {
178
+ allocations[i % allocations.length] += 1n;
179
+ remainder -= 1n;
180
+ i++;
181
+ }
182
+ while (remainder < 0n) {
183
+ allocations[i % allocations.length] -= 1n;
184
+ remainder += 1n;
185
+ i++;
186
+ }
187
+ return allocations.map((subunits) => {
188
+ var _a;
189
+ return __privateMethod(_a = _Money, _Money_static, createFromSubunits_fn).call(_a, subunits, this.currency, __privateGet(this, _currencyDef));
190
+ });
191
+ }
192
+ // ============ Comparison Operations ============
193
+ /**
194
+ * Check if this amount equals another.
195
+ * @throws {CurrencyMismatchError} If currencies don't match
196
+ */
197
+ equalTo(other) {
198
+ var _a;
199
+ __privateMethod(this, _Money_instances, assertSameCurrency_fn).call(this, other);
200
+ return __privateGet(this, _subunits) === __privateMethod(_a = other, _Money_instances, getInternalValue_fn).call(_a);
201
+ }
202
+ /**
203
+ * Check if this amount is greater than another.
204
+ * @throws {CurrencyMismatchError} If currencies don't match
205
+ */
206
+ greaterThan(other) {
207
+ var _a;
208
+ __privateMethod(this, _Money_instances, assertSameCurrency_fn).call(this, other);
209
+ return __privateGet(this, _subunits) > __privateMethod(_a = other, _Money_instances, getInternalValue_fn).call(_a);
210
+ }
211
+ /**
212
+ * Check if this amount is less than another.
213
+ * @throws {CurrencyMismatchError} If currencies don't match
214
+ */
215
+ lessThan(other) {
216
+ var _a;
217
+ __privateMethod(this, _Money_instances, assertSameCurrency_fn).call(this, other);
218
+ return __privateGet(this, _subunits) < __privateMethod(_a = other, _Money_instances, getInternalValue_fn).call(_a);
219
+ }
220
+ /**
221
+ * Check if this amount is greater than or equal to another.
222
+ * @throws {CurrencyMismatchError} If currencies don't match
223
+ */
224
+ greaterThanOrEqual(other) {
225
+ var _a;
226
+ __privateMethod(this, _Money_instances, assertSameCurrency_fn).call(this, other);
227
+ return __privateGet(this, _subunits) >= __privateMethod(_a = other, _Money_instances, getInternalValue_fn).call(_a);
228
+ }
229
+ /**
230
+ * Check if this amount is less than or equal to another.
231
+ * @throws {CurrencyMismatchError} If currencies don't match
232
+ */
233
+ lessThanOrEqual(other) {
234
+ var _a;
235
+ __privateMethod(this, _Money_instances, assertSameCurrency_fn).call(this, other);
236
+ return __privateGet(this, _subunits) <= __privateMethod(_a = other, _Money_instances, getInternalValue_fn).call(_a);
237
+ }
238
+ /**
239
+ * Check if this amount is zero.
240
+ */
241
+ isZero() {
242
+ return __privateGet(this, _subunits) === 0n;
243
+ }
244
+ /**
245
+ * Check if this amount is positive (greater than zero).
246
+ */
247
+ isPositive() {
248
+ return __privateGet(this, _subunits) > 0n;
249
+ }
250
+ /**
251
+ * Check if this amount is negative (less than zero).
252
+ */
253
+ isNegative() {
254
+ return __privateGet(this, _subunits) < 0n;
255
+ }
256
+ // ============ Serialization ============
257
+ /**
258
+ * Convert to a plain object (safe for JSON).
259
+ */
260
+ toJSON() {
261
+ return {
262
+ currency: this.currency,
263
+ amount: this.amount
264
+ };
265
+ }
266
+ /**
267
+ * Convert to string representation.
268
+ */
269
+ toString() {
270
+ return `${this.displayAmount} ${this.currency}`;
271
+ }
272
+ /**
273
+ * Get the amount as a number (may lose precision for large values).
274
+ * Use with caution - prefer string-based operations.
275
+ */
276
+ toNumber() {
277
+ return Number(this.amount);
278
+ }
279
+ /**
280
+ * Get the amount in subunits (e.g., cents for USD).
281
+ * Useful for database storage (Stripe-style integer storage).
282
+ */
283
+ toSubunits() {
284
+ return __privateGet(this, _subunits);
285
+ }
286
+ // ============ Static Factory Methods ============
287
+ /**
288
+ * Create a Money instance from a plain object.
289
+ */
290
+ static fromObject(obj) {
291
+ return new _Money(obj.currency, obj.amount);
292
+ }
293
+ /**
294
+ * Create a Money instance from subunits (e.g., cents).
295
+ * Useful for loading from database (Stripe-style integer storage).
296
+ */
297
+ static fromSubunits(subunits, currency) {
298
+ var _a;
299
+ const currencyDef = getCurrency(currency);
300
+ if (!currencyDef) {
301
+ throw new CurrencyUnknownError(currency);
302
+ }
303
+ const bigintSubunits = typeof subunits === "number" ? BigInt(subunits) : subunits;
304
+ return __privateMethod(_a = _Money, _Money_static, createFromSubunits_fn).call(_a, bigintSubunits, currency, currencyDef);
305
+ }
306
+ /**
307
+ * Compare two Money objects (for use with Array.sort).
308
+ * @throws {CurrencyMismatchError} If currencies don't match
309
+ */
310
+ static compare(a, b) {
311
+ var _a, _b;
312
+ if (a.currency !== b.currency) {
313
+ throw new CurrencyMismatchError(a.currency, b.currency);
314
+ }
315
+ const aVal = __privateMethod(_a = a, _Money_instances, getInternalValue_fn).call(_a);
316
+ const bVal = __privateMethod(_b = b, _Money_instances, getInternalValue_fn).call(_b);
317
+ if (aVal < bVal) return -1;
318
+ if (aVal > bVal) return 1;
319
+ return 0;
320
+ }
321
+ /**
322
+ * Create a zero amount in the specified currency.
323
+ */
324
+ static zero(currency) {
325
+ return new _Money(currency, "0");
326
+ }
327
+ };
328
+ _subunits = new WeakMap();
329
+ _currencyDef = new WeakMap();
330
+ _Money_instances = new WeakSet();
331
+ /**
332
+ * Parse an amount into native subunits.
333
+ */
334
+ parseAmount_fn = function(amount) {
335
+ const str = typeof amount === "number" ? String(amount) : amount;
336
+ const match = str.match(/^(-)?(\d+)(?:\.(\d+))?$/);
337
+ if (!match) {
338
+ throw new AmountError(amount);
339
+ }
340
+ const [, sign, whole, frac = ""] = match;
341
+ if (frac.length > __privateGet(this, _currencyDef).decimalDigits) {
342
+ throw new SubunitError(this.currency, __privateGet(this, _currencyDef).decimalDigits);
343
+ }
344
+ const paddedFrac = frac.padEnd(__privateGet(this, _currencyDef).decimalDigits, "0");
345
+ const combined = BigInt(whole + paddedFrac);
346
+ return sign === "-" ? -combined : combined;
347
+ };
348
+ _Money_static = new WeakSet();
349
+ formatForDisplay_fn = function(fullAmount, currencyDef) {
350
+ const preferredDecimals = currencyDef.displayDecimals ?? currencyDef.decimalDigits;
351
+ if (preferredDecimals === currencyDef.decimalDigits) {
352
+ return fullAmount;
353
+ }
354
+ const [whole, frac = ""] = fullAmount.split(".");
355
+ if (!frac) return whole;
356
+ let trimmedFrac = frac.replace(/0+$/, "");
357
+ if (trimmedFrac.length < preferredDecimals) {
358
+ trimmedFrac = trimmedFrac.padEnd(preferredDecimals, "0");
359
+ }
360
+ if (trimmedFrac === "" && preferredDecimals === 0) {
361
+ return whole;
362
+ }
363
+ return `${whole}.${trimmedFrac}`;
364
+ };
365
+ /**
366
+ * Ensure another Money has the same currency.
367
+ */
368
+ assertSameCurrency_fn = function(other) {
369
+ if (this.currency !== other.currency) {
370
+ throw new CurrencyMismatchError(this.currency, other.currency);
371
+ }
372
+ };
2
373
  /**
3
- * subunit-money - A type-safe value object for monetary amounts
4
- *
5
- * @example
6
- * import { Money, ExchangeRateService, MoneyConverter } from '@cbrunnkvist/subunit-money'
7
- *
8
- * // Basic usage
9
- * const price = new Money('USD', '19.99')
10
- * const tax = price.multiply(0.08)
11
- * const total = price.add(tax)
12
- *
13
- * // Currency conversion
14
- * const rates = new ExchangeRateService()
15
- * rates.setRate('USD', 'EUR', 0.92)
16
- * const converter = new MoneyConverter(rates)
17
- * const euros = converter.convert(total, 'EUR')
374
+ * Get the internal BigInt value (for operations).
18
375
  */
19
- var __importDefault = (this && this.__importDefault) || function (mod) {
20
- return (mod && mod.__esModule) ? mod : { "default": mod };
21
- };
22
- Object.defineProperty(exports, "__esModule", { value: true });
23
- exports.clearCurrencies = exports.loadCurrencyMap = exports.getAllCurrencies = exports.hasCurrency = exports.getCurrency = exports.registerCurrency = exports.ExchangeRateError = exports.AmountError = exports.SubunitError = exports.CurrencyUnknownError = exports.CurrencyMismatchError = exports.MoneyConverter = exports.ExchangeRateService = exports.Money = void 0;
24
- // Core classes
25
- var money_js_1 = require("./money.js");
26
- Object.defineProperty(exports, "Money", { enumerable: true, get: function () { return money_js_1.Money; } });
27
- var exchange_rate_service_js_1 = require("./exchange-rate-service.js");
28
- Object.defineProperty(exports, "ExchangeRateService", { enumerable: true, get: function () { return exchange_rate_service_js_1.ExchangeRateService; } });
29
- var money_converter_js_1 = require("./money-converter.js");
30
- Object.defineProperty(exports, "MoneyConverter", { enumerable: true, get: function () { return money_converter_js_1.MoneyConverter; } });
31
- // Error types
32
- var errors_js_1 = require("./errors.js");
33
- Object.defineProperty(exports, "CurrencyMismatchError", { enumerable: true, get: function () { return errors_js_1.CurrencyMismatchError; } });
34
- Object.defineProperty(exports, "CurrencyUnknownError", { enumerable: true, get: function () { return errors_js_1.CurrencyUnknownError; } });
35
- Object.defineProperty(exports, "SubunitError", { enumerable: true, get: function () { return errors_js_1.SubunitError; } });
36
- Object.defineProperty(exports, "AmountError", { enumerable: true, get: function () { return errors_js_1.AmountError; } });
37
- Object.defineProperty(exports, "ExchangeRateError", { enumerable: true, get: function () { return errors_js_1.ExchangeRateError; } });
38
- // Currency utilities
39
- var currency_js_1 = require("./currency.js");
40
- Object.defineProperty(exports, "registerCurrency", { enumerable: true, get: function () { return currency_js_1.registerCurrency; } });
41
- Object.defineProperty(exports, "getCurrency", { enumerable: true, get: function () { return currency_js_1.getCurrency; } });
42
- Object.defineProperty(exports, "hasCurrency", { enumerable: true, get: function () { return currency_js_1.hasCurrency; } });
43
- Object.defineProperty(exports, "getAllCurrencies", { enumerable: true, get: function () { return currency_js_1.getAllCurrencies; } });
44
- Object.defineProperty(exports, "loadCurrencyMap", { enumerable: true, get: function () { return currency_js_1.loadCurrencyMap; } });
45
- Object.defineProperty(exports, "clearCurrencies", { enumerable: true, get: function () { return currency_js_1.clearCurrencies; } });
46
- // Auto-load default currencies
47
- // The currencymap.json file is the official ISO 4217 currency list (List One) as of 2026-01-01,
48
- // sourced from SIX Financial Information AG (the ISO 4217 Maintenance Agency).
49
- //
50
- // To regenerate:
51
- // 1. Download list-one.xml from https://www.six-group.com/en/products-services/financial-information/data-standards.html
52
- // 2. Convert with: yq -p xml -o json '.' list-one.xml | jq '.ISO_4217.CcyTbl.CcyNtry | map(select(.Ccy) | {(.Ccy): {decimal_digits: (if (.CcyMnrUnts == "N.A." or .CcyMnrUnts == null) then 0 else (.CcyMnrUnts | tonumber) end)}}) | add | to_entries | sort_by(.key) | from_entries' > currencymap.json
53
- //
54
- // Note: This excludes historical currencies, supranational funds, and precious metals,
55
- // keeping only active national and regional currencies for practical use.
56
- const currency_js_2 = require("./currency.js");
57
- const currencymap_json_1 = __importDefault(require("../currencymap.json"));
58
- (0, currency_js_2.loadCurrencyMap)(currencymap_json_1.default);
376
+ getInternalValue_fn = function() {
377
+ return __privateGet(this, _subunits);
378
+ };
379
+ parseFactor_fn = function(factor) {
380
+ const str = String(factor);
381
+ const [base, exponent] = str.split("e");
382
+ const baseMatch = base.match(/^(-)?(\d+)(?:\.(\d+))?$/);
383
+ if (!baseMatch) {
384
+ throw new TypeError(`Invalid factor format: ${str}`);
385
+ }
386
+ const [, sign, whole, frac = ""] = baseMatch;
387
+ const baseValue = BigInt((sign || "") + whole + frac);
388
+ const baseDecimals = frac.length;
389
+ const exp = exponent ? Number(exponent) : 0;
390
+ const netExp = exp - baseDecimals;
391
+ if (netExp >= 0) {
392
+ return { value: baseValue * 10n ** BigInt(netExp), scale: 0n };
393
+ } else {
394
+ return { value: baseValue, scale: BigInt(-netExp) };
395
+ }
396
+ };
397
+ roundedDivide_fn = function(numerator, denominator) {
398
+ if (denominator === 1n) return numerator;
399
+ const quotient = numerator / denominator;
400
+ const remainder = numerator % denominator;
401
+ if (remainder === 0n) return quotient;
402
+ const halfDenominator = denominator / 2n;
403
+ const absRemainder = remainder < 0n ? -remainder : remainder;
404
+ if (absRemainder > halfDenominator) {
405
+ return numerator < 0n ? quotient - 1n : quotient + 1n;
406
+ }
407
+ if (absRemainder === halfDenominator) {
408
+ const isQuotientEven = quotient % 2n === 0n;
409
+ if (isQuotientEven) {
410
+ return quotient;
411
+ }
412
+ return numerator < 0n ? quotient - 1n : quotient + 1n;
413
+ }
414
+ return quotient;
415
+ };
416
+ createFromSubunits_fn = function(subunits, currency, currencyDef) {
417
+ var _a;
418
+ return new _Money(currency, __privateMethod(_a = _Money, _Money_static, formatSubunits_fn).call(_a, subunits, currencyDef));
419
+ };
420
+ formatSubunits_fn = function(subunits, currencyDef) {
421
+ const decimals = currencyDef.decimalDigits;
422
+ const abs = subunits < 0n ? -subunits : subunits;
423
+ const isNegative = subunits < 0n;
424
+ if (decimals === 0) {
425
+ return `${isNegative ? "-" : ""}${abs}`;
426
+ }
427
+ const multiplier = 10n ** BigInt(decimals);
428
+ const wholePart = abs / multiplier;
429
+ const fracPart = abs % multiplier;
430
+ const sign = isNegative ? "-" : "";
431
+ return `${sign}${wholePart}.${fracPart.toString().padStart(decimals, "0")}`;
432
+ };
433
+ __privateAdd(_Money, _Money_static);
434
+ var Money = _Money;
435
+
436
+ // lib/exchange-rate-service.ts
437
+ var _rates, _ExchangeRateService_instances, key_fn;
438
+ var ExchangeRateService = class {
439
+ constructor() {
440
+ __privateAdd(this, _ExchangeRateService_instances);
441
+ __privateAdd(this, _rates, /* @__PURE__ */ new Map());
442
+ }
443
+ /**
444
+ * Set an exchange rate.
445
+ *
446
+ * @param from - Source currency code
447
+ * @param to - Target currency code
448
+ * @param rate - Exchange rate (1 unit of 'from' = rate units of 'to')
449
+ * @param source - Optional source identifier (e.g., 'ECB', 'Coinbase')
450
+ * @param autoInverse - If true, automatically create inverse rate (default: true)
451
+ */
452
+ setRate(from, to, rate, source, autoInverse = true) {
453
+ const rateStr = typeof rate === "number" ? rate.toPrecision(15) : rate;
454
+ __privateGet(this, _rates).set(__privateMethod(this, _ExchangeRateService_instances, key_fn).call(this, from, to), {
455
+ from,
456
+ to,
457
+ rate: rateStr,
458
+ timestamp: /* @__PURE__ */ new Date(),
459
+ source
460
+ });
461
+ if (autoInverse) {
462
+ const inverseKey = __privateMethod(this, _ExchangeRateService_instances, key_fn).call(this, to, from);
463
+ if (!__privateGet(this, _rates).has(inverseKey)) {
464
+ const inverseRate = 1 / Number(rateStr);
465
+ __privateGet(this, _rates).set(inverseKey, {
466
+ from: to,
467
+ to: from,
468
+ rate: inverseRate.toPrecision(15),
469
+ timestamp: /* @__PURE__ */ new Date(),
470
+ source: source ? `${source} (inverse)` : "(inverse)"
471
+ });
472
+ }
473
+ }
474
+ }
475
+ /**
476
+ * Get an exchange rate.
477
+ *
478
+ * @param from - Source currency code
479
+ * @param to - Target currency code
480
+ * @returns The exchange rate, or undefined if not set
481
+ */
482
+ getRate(from, to) {
483
+ if (from === to) {
484
+ return {
485
+ from,
486
+ to,
487
+ rate: "1",
488
+ timestamp: /* @__PURE__ */ new Date(),
489
+ source: "(identity)"
490
+ };
491
+ }
492
+ return __privateGet(this, _rates).get(__privateMethod(this, _ExchangeRateService_instances, key_fn).call(this, from, to));
493
+ }
494
+ /**
495
+ * Check if a rate exists.
496
+ */
497
+ hasRate(from, to) {
498
+ return from === to || __privateGet(this, _rates).has(__privateMethod(this, _ExchangeRateService_instances, key_fn).call(this, from, to));
499
+ }
500
+ /**
501
+ * Remove a rate.
502
+ */
503
+ removeRate(from, to) {
504
+ return __privateGet(this, _rates).delete(__privateMethod(this, _ExchangeRateService_instances, key_fn).call(this, from, to));
505
+ }
506
+ /**
507
+ * Get both forward and reverse rates, with discrepancy analysis.
508
+ * Useful for detecting rate inconsistencies.
509
+ *
510
+ * @param currencyA - First currency
511
+ * @param currencyB - Second currency
512
+ * @returns Rate pair with discrepancy, or undefined if either rate is missing
513
+ */
514
+ getRatePair(currencyA, currencyB) {
515
+ const forward = this.getRate(currencyA, currencyB);
516
+ const reverse = this.getRate(currencyB, currencyA);
517
+ if (!forward || !reverse) {
518
+ return void 0;
519
+ }
520
+ const product = Number(forward.rate) * Number(reverse.rate);
521
+ const discrepancy = Math.abs(1 - product);
522
+ return { forward, reverse, discrepancy };
523
+ }
524
+ /**
525
+ * Get all rates for a specific base currency.
526
+ *
527
+ * @param base - The base currency code
528
+ * @returns Array of rates from this currency
529
+ */
530
+ getRatesFrom(base) {
531
+ const rates = [];
532
+ for (const rate of __privateGet(this, _rates).values()) {
533
+ if (rate.from === base) {
534
+ rates.push(rate);
535
+ }
536
+ }
537
+ return rates.sort((a, b) => a.to.localeCompare(b.to));
538
+ }
539
+ /**
540
+ * Get all registered rates.
541
+ */
542
+ getAllRates() {
543
+ return Array.from(__privateGet(this, _rates).values()).sort((a, b) => {
544
+ const fromCompare = a.from.localeCompare(b.from);
545
+ return fromCompare !== 0 ? fromCompare : a.to.localeCompare(b.to);
546
+ });
547
+ }
548
+ /**
549
+ * Clear all rates.
550
+ */
551
+ clear() {
552
+ __privateGet(this, _rates).clear();
553
+ }
554
+ /**
555
+ * Load rates from a simple object.
556
+ *
557
+ * @param rates - Object where keys are "FROM:TO" and values are rates
558
+ * @param source - Optional source identifier
559
+ *
560
+ * @example
561
+ * service.loadRates({
562
+ * 'USD:EUR': 0.92,
563
+ * 'USD:GBP': 0.79,
564
+ * }, 'daily-update')
565
+ */
566
+ loadRates(rates, source) {
567
+ for (const [key, rate] of Object.entries(rates)) {
568
+ const [from, to] = key.split(":");
569
+ if (from && to) {
570
+ this.setRate(from, to, rate, source, false);
571
+ }
572
+ }
573
+ }
574
+ };
575
+ _rates = new WeakMap();
576
+ _ExchangeRateService_instances = new WeakSet();
577
+ /**
578
+ * Create a rate key for storage.
579
+ */
580
+ key_fn = function(from, to) {
581
+ return `${from}:${to}`;
582
+ };
583
+
584
+ // lib/money-converter.ts
585
+ var _rateService, _MoneyConverter_instances, bankersRound_fn;
586
+ var MoneyConverter = class {
587
+ constructor(rateService) {
588
+ __privateAdd(this, _MoneyConverter_instances);
589
+ __privateAdd(this, _rateService);
590
+ __privateSet(this, _rateService, rateService);
591
+ }
592
+ /**
593
+ * Convert a Money amount to another currency.
594
+ *
595
+ * @param money - The amount to convert
596
+ * @param targetCurrency - The target currency code
597
+ * @returns A new Money in the target currency
598
+ * @throws {ExchangeRateError} If no rate is available
599
+ */
600
+ convert(money, targetCurrency) {
601
+ if (money.currency === targetCurrency) {
602
+ return money;
603
+ }
604
+ const currencyDef = getCurrency(targetCurrency);
605
+ if (!currencyDef) {
606
+ throw new CurrencyUnknownError(targetCurrency);
607
+ }
608
+ const rate = __privateGet(this, _rateService).getRate(money.currency, targetCurrency);
609
+ if (!rate) {
610
+ throw new ExchangeRateError(money.currency, targetCurrency);
611
+ }
612
+ const sourceCurrencyDef = getCurrency(money.currency);
613
+ const sourceSubunits = money.toSubunits();
614
+ const sourceMultiplier = 10n ** BigInt(sourceCurrencyDef.decimalDigits);
615
+ const targetMultiplier = 10n ** BigInt(currencyDef.decimalDigits);
616
+ const RATE_PRECISION = 15n;
617
+ const rateMultiplier = 10n ** RATE_PRECISION;
618
+ const rateValue = Number(rate.rate);
619
+ const rateBigInt = BigInt(Math.round(rateValue * Number(rateMultiplier)));
620
+ const product = sourceSubunits * rateBigInt * targetMultiplier;
621
+ const divisor = rateMultiplier * sourceMultiplier;
622
+ const targetSubunits = __privateMethod(this, _MoneyConverter_instances, bankersRound_fn).call(this, product, divisor);
623
+ return Money.fromSubunits(targetSubunits, targetCurrency);
624
+ }
625
+ /**
626
+ * Add two Money amounts, converting as needed.
627
+ *
628
+ * @param a - First amount
629
+ * @param b - Second amount
630
+ * @param resultCurrency - Currency for the result (must be one of the input currencies)
631
+ * @returns Sum in the result currency
632
+ */
633
+ add(a, b, resultCurrency) {
634
+ const aConverted = this.convert(a, resultCurrency);
635
+ const bConverted = this.convert(b, resultCurrency);
636
+ return aConverted.add(bConverted);
637
+ }
638
+ /**
639
+ * Subtract two Money amounts, converting as needed.
640
+ *
641
+ * @param a - Amount to subtract from
642
+ * @param b - Amount to subtract
643
+ * @param resultCurrency - Currency for the result
644
+ * @returns Difference in the result currency
645
+ */
646
+ subtract(a, b, resultCurrency) {
647
+ const aConverted = this.convert(a, resultCurrency);
648
+ const bConverted = this.convert(b, resultCurrency);
649
+ return aConverted.subtract(bConverted);
650
+ }
651
+ /**
652
+ * Calculate what percentage one amount is of another.
653
+ * Converts both to the same currency before comparison.
654
+ *
655
+ * @param part - The partial amount
656
+ * @param whole - The whole amount
657
+ * @returns Percentage as a number (e.g., 25 for 25%)
658
+ */
659
+ percentageOf(part, whole) {
660
+ const partConverted = this.convert(part, whole.currency);
661
+ return partConverted.toNumber() / whole.toNumber() * 100;
662
+ }
663
+ /**
664
+ * Sum multiple Money amounts, converting all to a target currency.
665
+ *
666
+ * @param amounts - Array of Money objects (can be different currencies)
667
+ * @param targetCurrency - Currency for the result
668
+ * @returns Total in the target currency
669
+ */
670
+ sum(amounts, targetCurrency) {
671
+ let total = Money.zero(targetCurrency);
672
+ for (const amount of amounts) {
673
+ const converted = this.convert(amount, targetCurrency);
674
+ total = total.add(converted);
675
+ }
676
+ return total;
677
+ }
678
+ /**
679
+ * Compare two Money amounts across currencies.
680
+ * Returns negative if a < b, zero if equal, positive if a > b.
681
+ *
682
+ * @param a - First amount
683
+ * @param b - Second amount
684
+ * @returns Comparison result
685
+ */
686
+ compare(a, b) {
687
+ const bConverted = this.convert(b, a.currency);
688
+ return Money.compare(a, bConverted);
689
+ }
690
+ /**
691
+ * Get the exchange rate service (for direct rate access).
692
+ */
693
+ get rateService() {
694
+ return __privateGet(this, _rateService);
695
+ }
696
+ };
697
+ _rateService = new WeakMap();
698
+ _MoneyConverter_instances = new WeakSet();
699
+ bankersRound_fn = function(numerator, denominator) {
700
+ if (denominator === 1n) return numerator;
701
+ const quotient = numerator / denominator;
702
+ const remainder = numerator % denominator;
703
+ if (remainder === 0n) return quotient;
704
+ const halfDenominator = denominator / 2n;
705
+ const absRemainder = remainder < 0n ? -remainder : remainder;
706
+ if (absRemainder > halfDenominator) {
707
+ return numerator < 0n ? quotient - 1n : quotient + 1n;
708
+ }
709
+ if (absRemainder === halfDenominator) {
710
+ const isQuotientEven = quotient % 2n === 0n;
711
+ if (isQuotientEven) {
712
+ return quotient;
713
+ }
714
+ return numerator < 0n ? quotient - 1n : quotient + 1n;
715
+ }
716
+ return quotient;
717
+ };
718
+
719
+ // currencymap.json
720
+ var currencymap_default = {
721
+ AED: {
722
+ decimal_digits: 2
723
+ },
724
+ AFN: {
725
+ decimal_digits: 2
726
+ },
727
+ ALL: {
728
+ decimal_digits: 2
729
+ },
730
+ AMD: {
731
+ decimal_digits: 2
732
+ },
733
+ AOA: {
734
+ decimal_digits: 2
735
+ },
736
+ ARS: {
737
+ decimal_digits: 2
738
+ },
739
+ AUD: {
740
+ decimal_digits: 2
741
+ },
742
+ AWG: {
743
+ decimal_digits: 2
744
+ },
745
+ AZN: {
746
+ decimal_digits: 2
747
+ },
748
+ BAM: {
749
+ decimal_digits: 2
750
+ },
751
+ BBD: {
752
+ decimal_digits: 2
753
+ },
754
+ BDT: {
755
+ decimal_digits: 2
756
+ },
757
+ BHD: {
758
+ decimal_digits: 3
759
+ },
760
+ BIF: {
761
+ decimal_digits: 0
762
+ },
763
+ BMD: {
764
+ decimal_digits: 2
765
+ },
766
+ BND: {
767
+ decimal_digits: 2
768
+ },
769
+ BOB: {
770
+ decimal_digits: 2
771
+ },
772
+ BOV: {
773
+ decimal_digits: 2
774
+ },
775
+ BRL: {
776
+ decimal_digits: 2
777
+ },
778
+ BSD: {
779
+ decimal_digits: 2
780
+ },
781
+ BTN: {
782
+ decimal_digits: 2
783
+ },
784
+ BWP: {
785
+ decimal_digits: 2
786
+ },
787
+ BYN: {
788
+ decimal_digits: 2
789
+ },
790
+ BZD: {
791
+ decimal_digits: 2
792
+ },
793
+ CAD: {
794
+ decimal_digits: 2
795
+ },
796
+ CDF: {
797
+ decimal_digits: 2
798
+ },
799
+ CHE: {
800
+ decimal_digits: 2
801
+ },
802
+ CHF: {
803
+ decimal_digits: 2
804
+ },
805
+ CHW: {
806
+ decimal_digits: 2
807
+ },
808
+ CLF: {
809
+ decimal_digits: 4
810
+ },
811
+ CLP: {
812
+ decimal_digits: 0
813
+ },
814
+ CNY: {
815
+ decimal_digits: 2
816
+ },
817
+ COP: {
818
+ decimal_digits: 2
819
+ },
820
+ COU: {
821
+ decimal_digits: 2
822
+ },
823
+ CRC: {
824
+ decimal_digits: 2
825
+ },
826
+ CUP: {
827
+ decimal_digits: 2
828
+ },
829
+ CVE: {
830
+ decimal_digits: 2
831
+ },
832
+ CZK: {
833
+ decimal_digits: 2
834
+ },
835
+ DJF: {
836
+ decimal_digits: 0
837
+ },
838
+ DKK: {
839
+ decimal_digits: 2
840
+ },
841
+ DOP: {
842
+ decimal_digits: 2
843
+ },
844
+ DZD: {
845
+ decimal_digits: 2
846
+ },
847
+ EGP: {
848
+ decimal_digits: 2
849
+ },
850
+ ERN: {
851
+ decimal_digits: 2
852
+ },
853
+ ETB: {
854
+ decimal_digits: 2
855
+ },
856
+ EUR: {
857
+ decimal_digits: 2
858
+ },
859
+ FJD: {
860
+ decimal_digits: 2
861
+ },
862
+ FKP: {
863
+ decimal_digits: 2
864
+ },
865
+ GBP: {
866
+ decimal_digits: 2
867
+ },
868
+ GEL: {
869
+ decimal_digits: 2
870
+ },
871
+ GHS: {
872
+ decimal_digits: 2
873
+ },
874
+ GIP: {
875
+ decimal_digits: 2
876
+ },
877
+ GMD: {
878
+ decimal_digits: 2
879
+ },
880
+ GNF: {
881
+ decimal_digits: 0
882
+ },
883
+ GTQ: {
884
+ decimal_digits: 2
885
+ },
886
+ GYD: {
887
+ decimal_digits: 2
888
+ },
889
+ HKD: {
890
+ decimal_digits: 2
891
+ },
892
+ HNL: {
893
+ decimal_digits: 2
894
+ },
895
+ HTG: {
896
+ decimal_digits: 2
897
+ },
898
+ HUF: {
899
+ decimal_digits: 2
900
+ },
901
+ IDR: {
902
+ decimal_digits: 2
903
+ },
904
+ ILS: {
905
+ decimal_digits: 2
906
+ },
907
+ INR: {
908
+ decimal_digits: 2
909
+ },
910
+ IQD: {
911
+ decimal_digits: 3
912
+ },
913
+ IRR: {
914
+ decimal_digits: 2
915
+ },
916
+ ISK: {
917
+ decimal_digits: 0
918
+ },
919
+ JMD: {
920
+ decimal_digits: 2
921
+ },
922
+ JOD: {
923
+ decimal_digits: 3
924
+ },
925
+ JPY: {
926
+ decimal_digits: 0
927
+ },
928
+ KES: {
929
+ decimal_digits: 2
930
+ },
931
+ KGS: {
932
+ decimal_digits: 2
933
+ },
934
+ KHR: {
935
+ decimal_digits: 2
936
+ },
937
+ KMF: {
938
+ decimal_digits: 0
939
+ },
940
+ KPW: {
941
+ decimal_digits: 2
942
+ },
943
+ KRW: {
944
+ decimal_digits: 0
945
+ },
946
+ KWD: {
947
+ decimal_digits: 3
948
+ },
949
+ KYD: {
950
+ decimal_digits: 2
951
+ },
952
+ KZT: {
953
+ decimal_digits: 2
954
+ },
955
+ LAK: {
956
+ decimal_digits: 2
957
+ },
958
+ LBP: {
959
+ decimal_digits: 2
960
+ },
961
+ LKR: {
962
+ decimal_digits: 2
963
+ },
964
+ LRD: {
965
+ decimal_digits: 2
966
+ },
967
+ LSL: {
968
+ decimal_digits: 2
969
+ },
970
+ LYD: {
971
+ decimal_digits: 3
972
+ },
973
+ MAD: {
974
+ decimal_digits: 2
975
+ },
976
+ MDL: {
977
+ decimal_digits: 2
978
+ },
979
+ MGA: {
980
+ decimal_digits: 2
981
+ },
982
+ MKD: {
983
+ decimal_digits: 2
984
+ },
985
+ MMK: {
986
+ decimal_digits: 2
987
+ },
988
+ MNT: {
989
+ decimal_digits: 2
990
+ },
991
+ MOP: {
992
+ decimal_digits: 2
993
+ },
994
+ MRU: {
995
+ decimal_digits: 2
996
+ },
997
+ MUR: {
998
+ decimal_digits: 2
999
+ },
1000
+ MVR: {
1001
+ decimal_digits: 2
1002
+ },
1003
+ MWK: {
1004
+ decimal_digits: 2
1005
+ },
1006
+ MXN: {
1007
+ decimal_digits: 2
1008
+ },
1009
+ MXV: {
1010
+ decimal_digits: 2
1011
+ },
1012
+ MYR: {
1013
+ decimal_digits: 2
1014
+ },
1015
+ MZN: {
1016
+ decimal_digits: 2
1017
+ },
1018
+ NAD: {
1019
+ decimal_digits: 2
1020
+ },
1021
+ NGN: {
1022
+ decimal_digits: 2
1023
+ },
1024
+ NIO: {
1025
+ decimal_digits: 2
1026
+ },
1027
+ NOK: {
1028
+ decimal_digits: 2
1029
+ },
1030
+ NPR: {
1031
+ decimal_digits: 2
1032
+ },
1033
+ NZD: {
1034
+ decimal_digits: 2
1035
+ },
1036
+ OMR: {
1037
+ decimal_digits: 3
1038
+ },
1039
+ PAB: {
1040
+ decimal_digits: 2
1041
+ },
1042
+ PEN: {
1043
+ decimal_digits: 2
1044
+ },
1045
+ PGK: {
1046
+ decimal_digits: 2
1047
+ },
1048
+ PHP: {
1049
+ decimal_digits: 2
1050
+ },
1051
+ PKR: {
1052
+ decimal_digits: 2
1053
+ },
1054
+ PLN: {
1055
+ decimal_digits: 2
1056
+ },
1057
+ PYG: {
1058
+ decimal_digits: 0
1059
+ },
1060
+ QAR: {
1061
+ decimal_digits: 2
1062
+ },
1063
+ RON: {
1064
+ decimal_digits: 2
1065
+ },
1066
+ RSD: {
1067
+ decimal_digits: 2
1068
+ },
1069
+ RUB: {
1070
+ decimal_digits: 2
1071
+ },
1072
+ RWF: {
1073
+ decimal_digits: 0
1074
+ },
1075
+ SAR: {
1076
+ decimal_digits: 2
1077
+ },
1078
+ SBD: {
1079
+ decimal_digits: 2
1080
+ },
1081
+ SCR: {
1082
+ decimal_digits: 2
1083
+ },
1084
+ SDG: {
1085
+ decimal_digits: 2
1086
+ },
1087
+ SEK: {
1088
+ decimal_digits: 2
1089
+ },
1090
+ SGD: {
1091
+ decimal_digits: 2
1092
+ },
1093
+ SHP: {
1094
+ decimal_digits: 2
1095
+ },
1096
+ SLE: {
1097
+ decimal_digits: 2
1098
+ },
1099
+ SOS: {
1100
+ decimal_digits: 2
1101
+ },
1102
+ SRD: {
1103
+ decimal_digits: 2
1104
+ },
1105
+ SSP: {
1106
+ decimal_digits: 2
1107
+ },
1108
+ STN: {
1109
+ decimal_digits: 2
1110
+ },
1111
+ SVC: {
1112
+ decimal_digits: 2
1113
+ },
1114
+ SYP: {
1115
+ decimal_digits: 2
1116
+ },
1117
+ SZL: {
1118
+ decimal_digits: 2
1119
+ },
1120
+ THB: {
1121
+ decimal_digits: 2
1122
+ },
1123
+ TJS: {
1124
+ decimal_digits: 2
1125
+ },
1126
+ TMT: {
1127
+ decimal_digits: 2
1128
+ },
1129
+ TND: {
1130
+ decimal_digits: 3
1131
+ },
1132
+ TOP: {
1133
+ decimal_digits: 2
1134
+ },
1135
+ TRY: {
1136
+ decimal_digits: 2
1137
+ },
1138
+ TTD: {
1139
+ decimal_digits: 2
1140
+ },
1141
+ TWD: {
1142
+ decimal_digits: 2
1143
+ },
1144
+ TZS: {
1145
+ decimal_digits: 2
1146
+ },
1147
+ UAH: {
1148
+ decimal_digits: 2
1149
+ },
1150
+ UGX: {
1151
+ decimal_digits: 0
1152
+ },
1153
+ USD: {
1154
+ decimal_digits: 2
1155
+ },
1156
+ USN: {
1157
+ decimal_digits: 2
1158
+ },
1159
+ UYI: {
1160
+ decimal_digits: 0
1161
+ },
1162
+ UYU: {
1163
+ decimal_digits: 2
1164
+ },
1165
+ UYW: {
1166
+ decimal_digits: 4
1167
+ },
1168
+ UZS: {
1169
+ decimal_digits: 2
1170
+ },
1171
+ VED: {
1172
+ decimal_digits: 2
1173
+ },
1174
+ VES: {
1175
+ decimal_digits: 2
1176
+ },
1177
+ VND: {
1178
+ decimal_digits: 0
1179
+ },
1180
+ VUV: {
1181
+ decimal_digits: 0
1182
+ },
1183
+ WST: {
1184
+ decimal_digits: 2
1185
+ },
1186
+ XAD: {
1187
+ decimal_digits: 2
1188
+ },
1189
+ XAF: {
1190
+ decimal_digits: 0
1191
+ },
1192
+ XAG: {
1193
+ decimal_digits: 0
1194
+ },
1195
+ XAU: {
1196
+ decimal_digits: 0
1197
+ },
1198
+ XBA: {
1199
+ decimal_digits: 0
1200
+ },
1201
+ XBB: {
1202
+ decimal_digits: 0
1203
+ },
1204
+ XBC: {
1205
+ decimal_digits: 0
1206
+ },
1207
+ XBD: {
1208
+ decimal_digits: 0
1209
+ },
1210
+ XCD: {
1211
+ decimal_digits: 2
1212
+ },
1213
+ XCG: {
1214
+ decimal_digits: 2
1215
+ },
1216
+ XDR: {
1217
+ decimal_digits: 0
1218
+ },
1219
+ XOF: {
1220
+ decimal_digits: 0
1221
+ },
1222
+ XPD: {
1223
+ decimal_digits: 0
1224
+ },
1225
+ XPF: {
1226
+ decimal_digits: 0
1227
+ },
1228
+ XPT: {
1229
+ decimal_digits: 0
1230
+ },
1231
+ XSU: {
1232
+ decimal_digits: 0
1233
+ },
1234
+ XTS: {
1235
+ decimal_digits: 0
1236
+ },
1237
+ XUA: {
1238
+ decimal_digits: 0
1239
+ },
1240
+ XXX: {
1241
+ decimal_digits: 0
1242
+ },
1243
+ YER: {
1244
+ decimal_digits: 2
1245
+ },
1246
+ ZAR: {
1247
+ decimal_digits: 2
1248
+ },
1249
+ ZMW: {
1250
+ decimal_digits: 2
1251
+ },
1252
+ ZWG: {
1253
+ decimal_digits: 2
1254
+ }
1255
+ };
1256
+
1257
+ // lib/index.ts
1258
+ loadCurrencyMap(currencymap_default);
1259
+ export {
1260
+ AmountError,
1261
+ CurrencyMismatchError,
1262
+ CurrencyUnknownError,
1263
+ ExchangeRateError,
1264
+ ExchangeRateService,
1265
+ Money,
1266
+ MoneyConverter,
1267
+ SubunitError,
1268
+ clearCurrencies,
1269
+ getAllCurrencies,
1270
+ getCurrency,
1271
+ hasCurrency,
1272
+ loadCurrencyMap,
1273
+ registerCurrency
1274
+ };
1275
+ //# sourceMappingURL=index.js.map