monetra 2.0.0 → 2.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.
Files changed (59) hide show
  1. package/README.md +177 -160
  2. package/dist/currency/Currency.d.ts +27 -0
  3. package/dist/currency/index.d.ts +4 -0
  4. package/dist/currency/iso4217.d.ts +245 -0
  5. package/dist/currency/precision.d.ts +2 -0
  6. package/dist/currency/registry.d.ts +22 -0
  7. package/dist/errors/BaseError.d.ts +22 -0
  8. package/dist/errors/CurrencyMismatchError.d.ts +12 -0
  9. package/dist/errors/InsufficientFundsError.d.ts +4 -0
  10. package/dist/errors/InvalidArgumentError.d.ts +4 -0
  11. package/dist/errors/InvalidPrecisionError.d.ts +4 -0
  12. package/dist/errors/OverflowError.d.ts +4 -0
  13. package/dist/errors/RoundingRequiredError.d.ts +4 -0
  14. package/dist/errors/index.d.ts +7 -0
  15. package/dist/financial/compound.d.ts +20 -0
  16. package/dist/financial/depreciation.d.ts +30 -0
  17. package/dist/financial/index.d.ts +7 -0
  18. package/dist/financial/index.js +1323 -0
  19. package/dist/financial/index.js.map +1 -0
  20. package/dist/financial/index.mjs +1275 -0
  21. package/dist/financial/index.mjs.map +1 -0
  22. package/dist/financial/investment.d.ts +31 -0
  23. package/dist/financial/leverage.d.ts +66 -0
  24. package/dist/financial/loan.d.ts +67 -0
  25. package/dist/financial/rate.d.ts +169 -0
  26. package/dist/financial/simple.d.ts +60 -0
  27. package/dist/format/formatter.d.ts +42 -0
  28. package/dist/format/parser.d.ts +53 -0
  29. package/dist/index.d.ts +11 -1202
  30. package/dist/index.js +263 -41
  31. package/dist/index.js.map +1 -1
  32. package/dist/index.mjs +248 -41
  33. package/dist/index.mjs.map +1 -1
  34. package/dist/ledger/Ledger.d.ts +65 -0
  35. package/dist/ledger/index.d.ts +3 -0
  36. package/dist/ledger/index.js +1054 -0
  37. package/dist/ledger/index.js.map +1 -0
  38. package/dist/ledger/index.mjs +1029 -0
  39. package/dist/ledger/index.mjs.map +1 -0
  40. package/dist/ledger/types.d.ts +30 -0
  41. package/dist/ledger/verification.d.ts +36 -0
  42. package/dist/money/Converter.d.ts +26 -0
  43. package/dist/money/Money.d.ts +299 -0
  44. package/dist/money/MoneyBag.d.ts +46 -0
  45. package/dist/money/allocation.d.ts +13 -0
  46. package/dist/money/arithmetic.d.ts +32 -0
  47. package/dist/money/guards.d.ts +3 -0
  48. package/dist/money/index.d.ts +4 -0
  49. package/dist/rounding/index.d.ts +3 -0
  50. package/dist/rounding/strategies.d.ts +36 -0
  51. package/dist/tokens/defineToken.d.ts +30 -0
  52. package/dist/tokens/index.d.ts +2 -0
  53. package/dist/tokens/index.js +100 -0
  54. package/dist/tokens/index.js.map +1 -0
  55. package/dist/tokens/index.mjs +69 -0
  56. package/dist/tokens/index.mjs.map +1 -0
  57. package/dist/tokens/types.d.ts +13 -0
  58. package/package.json +34 -14
  59. package/dist/index.d.mts +0 -1211
@@ -0,0 +1,245 @@
1
+ import { Currency } from "./Currency";
2
+ /**
3
+ * United States Dollar (USD).
4
+ */
5
+ export declare const USD: Currency;
6
+ /**
7
+ * Euro (EUR).
8
+ */
9
+ export declare const EUR: Currency;
10
+ /**
11
+ * British Pound Sterling (GBP).
12
+ */
13
+ export declare const GBP: Currency;
14
+ /**
15
+ * Japanese Yen (JPY).
16
+ */
17
+ export declare const JPY: Currency;
18
+ /**
19
+ * Swiss Franc (CHF).
20
+ */
21
+ export declare const CHF: Currency;
22
+ /**
23
+ * Canadian Dollar (CAD).
24
+ */
25
+ export declare const CAD: Currency;
26
+ /**
27
+ * Australian Dollar (AUD).
28
+ */
29
+ export declare const AUD: Currency;
30
+ /**
31
+ * New Zealand Dollar (NZD).
32
+ */
33
+ export declare const NZD: Currency;
34
+ /**
35
+ * Chinese Yuan Renminbi (CNY).
36
+ */
37
+ export declare const CNY: Currency;
38
+ /**
39
+ * Hong Kong Dollar (HKD).
40
+ */
41
+ export declare const HKD: Currency;
42
+ /**
43
+ * Singapore Dollar (SGD).
44
+ */
45
+ export declare const SGD: Currency;
46
+ /**
47
+ * South Korean Won (KRW).
48
+ */
49
+ export declare const KRW: Currency;
50
+ /**
51
+ * Indian Rupee (INR).
52
+ */
53
+ export declare const INR: Currency;
54
+ /**
55
+ * Swedish Krona (SEK).
56
+ */
57
+ export declare const SEK: Currency;
58
+ /**
59
+ * Norwegian Krone (NOK).
60
+ */
61
+ export declare const NOK: Currency;
62
+ /**
63
+ * Danish Krone (DKK).
64
+ */
65
+ export declare const DKK: Currency;
66
+ /**
67
+ * Polish Zloty (PLN).
68
+ */
69
+ export declare const PLN: Currency;
70
+ /**
71
+ * Czech Koruna (CZK).
72
+ */
73
+ export declare const CZK: Currency;
74
+ /**
75
+ * Hungarian Forint (HUF).
76
+ */
77
+ export declare const HUF: Currency;
78
+ /**
79
+ * Romanian Leu (RON).
80
+ */
81
+ export declare const RON: Currency;
82
+ /**
83
+ * Bulgarian Lev (BGN).
84
+ */
85
+ export declare const BGN: Currency;
86
+ /**
87
+ * Croatian Kuna (HRK).
88
+ * Note: Croatia adopted EUR on Jan 1, 2023, but HRK may still be needed for historical data.
89
+ */
90
+ export declare const HRK: Currency;
91
+ /**
92
+ * Turkish Lira (TRY).
93
+ */
94
+ export declare const TRY: Currency;
95
+ /**
96
+ * Russian Ruble (RUB).
97
+ */
98
+ export declare const RUB: Currency;
99
+ /**
100
+ * Ukrainian Hryvnia (UAH).
101
+ */
102
+ export declare const UAH: Currency;
103
+ /**
104
+ * Israeli New Shekel (ILS).
105
+ */
106
+ export declare const ILS: Currency;
107
+ /**
108
+ * Mexican Peso (MXN).
109
+ */
110
+ export declare const MXN: Currency;
111
+ /**
112
+ * Brazilian Real (BRL).
113
+ */
114
+ export declare const BRL: Currency;
115
+ /**
116
+ * Argentine Peso (ARS).
117
+ */
118
+ export declare const ARS: Currency;
119
+ /**
120
+ * Chilean Peso (CLP).
121
+ */
122
+ export declare const CLP: Currency;
123
+ /**
124
+ * Colombian Peso (COP).
125
+ */
126
+ export declare const COP: Currency;
127
+ /**
128
+ * Peruvian Sol (PEN).
129
+ */
130
+ export declare const PEN: Currency;
131
+ /**
132
+ * South African Rand (ZAR).
133
+ */
134
+ export declare const ZAR: Currency;
135
+ /**
136
+ * Nigerian Naira (NGN).
137
+ */
138
+ export declare const NGN: Currency;
139
+ /**
140
+ * Kenyan Shilling (KES).
141
+ */
142
+ export declare const KES: Currency;
143
+ /**
144
+ * Egyptian Pound (EGP).
145
+ */
146
+ export declare const EGP: Currency;
147
+ /**
148
+ * Moroccan Dirham (MAD).
149
+ */
150
+ export declare const MAD: Currency;
151
+ /**
152
+ * Ghanaian Cedi (GHS).
153
+ */
154
+ export declare const GHS: Currency;
155
+ /**
156
+ * Tanzanian Shilling (TZS).
157
+ */
158
+ export declare const TZS: Currency;
159
+ /**
160
+ * Ugandan Shilling (UGX).
161
+ */
162
+ export declare const UGX: Currency;
163
+ /**
164
+ * Thai Baht (THB).
165
+ */
166
+ export declare const THB: Currency;
167
+ /**
168
+ * Malaysian Ringgit (MYR).
169
+ */
170
+ export declare const MYR: Currency;
171
+ /**
172
+ * Indonesian Rupiah (IDR).
173
+ */
174
+ export declare const IDR: Currency;
175
+ /**
176
+ * Philippine Peso (PHP).
177
+ */
178
+ export declare const PHP: Currency;
179
+ /**
180
+ * Vietnamese Dong (VND).
181
+ */
182
+ export declare const VND: Currency;
183
+ /**
184
+ * Taiwan Dollar (TWD).
185
+ */
186
+ export declare const TWD: Currency;
187
+ /**
188
+ * Pakistani Rupee (PKR).
189
+ */
190
+ export declare const PKR: Currency;
191
+ /**
192
+ * Bangladeshi Taka (BDT).
193
+ */
194
+ export declare const BDT: Currency;
195
+ /**
196
+ * Sri Lankan Rupee (LKR).
197
+ */
198
+ export declare const LKR: Currency;
199
+ /**
200
+ * United Arab Emirates Dirham (AED).
201
+ */
202
+ export declare const AED: Currency;
203
+ /**
204
+ * Saudi Riyal (SAR).
205
+ */
206
+ export declare const SAR: Currency;
207
+ /**
208
+ * Qatari Riyal (QAR).
209
+ */
210
+ export declare const QAR: Currency;
211
+ /**
212
+ * Kuwaiti Dinar (KWD).
213
+ * Note: 3 decimal places (fils).
214
+ */
215
+ export declare const KWD: Currency;
216
+ /**
217
+ * Bahraini Dinar (BHD).
218
+ * Note: 3 decimal places (fils).
219
+ */
220
+ export declare const BHD: Currency;
221
+ /**
222
+ * Omani Rial (OMR).
223
+ * Note: 3 decimal places (baisa).
224
+ */
225
+ export declare const OMR: Currency;
226
+ /**
227
+ * Jordanian Dinar (JOD).
228
+ * Note: 3 decimal places (fils).
229
+ */
230
+ export declare const JOD: Currency;
231
+ /**
232
+ * Icelandic Króna (ISK).
233
+ * Note: 0 decimal places.
234
+ */
235
+ export declare const ISK: Currency;
236
+ /**
237
+ * Mauritanian Ouguiya (MRU).
238
+ * Note: Uses 2 decimals (khoums), but often displayed without.
239
+ */
240
+ export declare const MRU: Currency;
241
+ /**
242
+ * A collection of common currencies.
243
+ * @deprecated Use registry instead. Import individual currencies or use getCurrency().
244
+ */
245
+ export declare const CURRENCIES: Record<string, Currency>;
@@ -0,0 +1,2 @@
1
+ import { Currency } from "./Currency";
2
+ export declare function getMinorUnitExponent(currency: Currency): bigint;
@@ -0,0 +1,22 @@
1
+ import { Currency } from "./Currency";
2
+ /**
3
+ * Registers a currency in the global registry.
4
+ * @param currency The currency to register.
5
+ */
6
+ export declare function registerCurrency(currency: Currency): void;
7
+ /**
8
+ * Retrieves a currency by its code.
9
+ * @param code The currency code (e.g., "USD").
10
+ * @returns The Currency object.
11
+ * @throws Error if the currency is not found.
12
+ */
13
+ export declare function getCurrency(code: string): Currency;
14
+ /**
15
+ * Checks if a currency is registered.
16
+ */
17
+ export declare function isCurrencyRegistered(code: string): boolean;
18
+ /**
19
+ * Returns all registered currencies as a map.
20
+ * @internal Use for testing only.
21
+ */
22
+ export declare function getAllCurrencies(): Record<string, Currency>;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Error codes for programmatic handling of Monetra errors.
3
+ */
4
+ export declare enum MonetraErrorCode {
5
+ CURRENCY_MISMATCH = "MONETRA_CURRENCY_MISMATCH",
6
+ INSUFFICIENT_FUNDS = "MONETRA_INSUFFICIENT_FUNDS",
7
+ INVALID_ARGUMENT = "MONETRA_INVALID_ARGUMENT",
8
+ INVALID_PRECISION = "MONETRA_INVALID_PRECISION",
9
+ OVERFLOW = "MONETRA_OVERFLOW",
10
+ ROUNDING_REQUIRED = "MONETRA_ROUNDING_REQUIRED"
11
+ }
12
+ /**
13
+ * Base error class for all Monetra errors.
14
+ * All Monetra errors include an error code for programmatic handling.
15
+ */
16
+ export declare class MonetraError extends Error {
17
+ /**
18
+ * A unique error code for programmatic handling.
19
+ */
20
+ readonly code: MonetraErrorCode;
21
+ constructor(message: string, code: MonetraErrorCode);
22
+ }
@@ -0,0 +1,12 @@
1
+ import { MonetraError } from "./BaseError";
2
+ export declare class CurrencyMismatchError extends MonetraError {
3
+ /**
4
+ * The expected currency code.
5
+ */
6
+ readonly expected: string;
7
+ /**
8
+ * The received currency code.
9
+ */
10
+ readonly received: string;
11
+ constructor(expected: string, received: string);
12
+ }
@@ -0,0 +1,4 @@
1
+ import { MonetraError } from "./BaseError";
2
+ export declare class InsufficientFundsError extends MonetraError {
3
+ constructor(message?: string);
4
+ }
@@ -0,0 +1,4 @@
1
+ import { MonetraError } from "./BaseError";
2
+ export declare class InvalidArgumentError extends MonetraError {
3
+ constructor(message: string);
4
+ }
@@ -0,0 +1,4 @@
1
+ import { MonetraError } from "./BaseError";
2
+ export declare class InvalidPrecisionError extends MonetraError {
3
+ constructor(message: string);
4
+ }
@@ -0,0 +1,4 @@
1
+ import { MonetraError } from "./BaseError";
2
+ export declare class OverflowError extends MonetraError {
3
+ constructor(message?: string);
4
+ }
@@ -0,0 +1,4 @@
1
+ import { MonetraError } from "./BaseError";
2
+ export declare class RoundingRequiredError extends MonetraError {
3
+ constructor(operation?: string, result?: number);
4
+ }
@@ -0,0 +1,7 @@
1
+ export * from "./BaseError";
2
+ export * from "./CurrencyMismatchError";
3
+ export * from "./InvalidPrecisionError";
4
+ export * from "./RoundingRequiredError";
5
+ export * from "./InsufficientFundsError";
6
+ export * from "./InvalidArgumentError";
7
+ export * from "./OverflowError";
@@ -0,0 +1,20 @@
1
+ import { Money } from "../money/Money";
2
+ import { RoundingMode } from "../rounding/strategies";
3
+ export interface CompoundOptions {
4
+ rate: number;
5
+ years: number;
6
+ compoundingPerYear?: number;
7
+ rounding?: RoundingMode;
8
+ }
9
+ /**
10
+ * Calculates future value with compound interest.
11
+ * FV = PV * (1 + r/n)^(n*t)
12
+ */
13
+ export declare function futureValue(presentValue: Money, options: CompoundOptions): Money;
14
+ /**
15
+ * Calculates present value (discounting).
16
+ * PV = FV / (1 + r/n)^(n*t)
17
+ */
18
+ export declare function presentValue(futureVal: Money, options: CompoundOptions): Money;
19
+ export declare const compound: typeof futureValue;
20
+ export declare const discount: typeof presentValue;
@@ -0,0 +1,30 @@
1
+ import { Money } from "../money/Money";
2
+ import { RoundingMode } from "../rounding/strategies";
3
+ export interface DepreciationOptions {
4
+ cost: Money;
5
+ salvageValue: Money;
6
+ usefulLife: number;
7
+ rounding?: RoundingMode;
8
+ }
9
+ export interface DepreciationResult {
10
+ annualDepreciation: Money;
11
+ bookValueAtYear(year: number): Money;
12
+ schedule(): {
13
+ year: number;
14
+ depreciation: Money;
15
+ bookValue: Money;
16
+ }[];
17
+ }
18
+ /**
19
+ * Calculates straight-line depreciation for an asset.
20
+ *
21
+ * Formula:
22
+ * Annual Depreciation = (Cost - Salvage Value) / Useful Life
23
+ * Book Value at Year N = Cost - (Annual Depreciation × N)
24
+ *
25
+ * @param options - Configuration for depreciation calculation
26
+ * @returns Object containing annual depreciation, book value calculator, and schedule generator
27
+ * @throws {CurrencyMismatchError} If cost and salvage value currencies differ
28
+ * @throws {InvalidArgumentError} If useful life is not positive or salvage value > cost
29
+ */
30
+ export declare function straightLineDepreciation(options: DepreciationOptions): DepreciationResult;
@@ -0,0 +1,7 @@
1
+ export * from "./loan";
2
+ export * from "./compound";
3
+ export * from "./investment";
4
+ export * from "./rate";
5
+ export * from "./simple";
6
+ export * from "./leverage";
7
+ export * from "./depreciation";