@temboplus/frontend-core 0.2.14 → 0.2.16
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.cjs.js +3 -3
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +2 -2
- package/dist/index.esm.js.map +1 -1
- package/dist/models/amount/amount.d.ts +56 -27
- package/package.json +1 -1
|
@@ -2,19 +2,33 @@ import { CurrencyCode } from "../../models/currency";
|
|
|
2
2
|
/**
|
|
3
3
|
* Regular expression for validating amount strings
|
|
4
4
|
* Supports both positive and negative amounts with optional comma separators and decimals
|
|
5
|
+
*/
|
|
6
|
+
declare const AMOUNT_REGEX: RegExp;
|
|
7
|
+
/**
|
|
8
|
+
* Represents a monetary amount with currency information
|
|
5
9
|
*
|
|
6
|
-
*
|
|
7
|
-
* -
|
|
8
|
-
* -
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* -
|
|
12
|
-
* - $ : End of string
|
|
10
|
+
* Enhanced with currency-amount parsing support:
|
|
11
|
+
* - Supports formats like "TZS1000", "1000TZS", "TZS1,000.00", "1,000.00TZS"
|
|
12
|
+
* - Case-insensitive currency codes
|
|
13
|
+
* - US/UK format (comma for thousands, period for decimal)
|
|
14
|
+
* - Automatic whitespace removal
|
|
15
|
+
* - Clear error messages for invalid formats
|
|
13
16
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* // Currency-amount combinations
|
|
20
|
+
* Amount.from('TZS10000'); // TSh 10,000.00
|
|
21
|
+
* Amount.from('TZS 10,000'); // TSh 10,000.00 (spaces removed)
|
|
22
|
+
* Amount.from('10000TZS'); // TSh 10,000.00
|
|
23
|
+
* Amount.from('TZS1,234.56'); // TSh 1,234.56
|
|
24
|
+
* Amount.from('-TZS1000'); // -TSh 1,000.00
|
|
25
|
+
* Amount.from('TZS-1000'); // -TSh 1,000.00
|
|
26
|
+
*
|
|
27
|
+
* // Traditional usage still works
|
|
28
|
+
* Amount.from(1000, 'TZS'); // TSh 1,000.00
|
|
29
|
+
* Amount.from('1000', 'USD'); // $1,000.00
|
|
30
|
+
* ```
|
|
16
31
|
*/
|
|
17
|
-
declare const AMOUNT_REGEX: RegExp;
|
|
18
32
|
/**
|
|
19
33
|
* JSON representation interface for Amount serialization
|
|
20
34
|
*/
|
|
@@ -101,27 +115,42 @@ declare class Amount {
|
|
|
101
115
|
*/
|
|
102
116
|
private constructor();
|
|
103
117
|
/**
|
|
104
|
-
* Creates an Amount instance from
|
|
118
|
+
* Creates an Amount instance from string or number input
|
|
105
119
|
*
|
|
106
|
-
* Supports
|
|
107
|
-
* -
|
|
108
|
-
* -
|
|
109
|
-
* -
|
|
120
|
+
* Supports currency-amount combinations like:
|
|
121
|
+
* - "TZS10000", "10000TZS" (no space)
|
|
122
|
+
* - "TZS 10,000", "10,000 TZS" (with spaces - automatically cleaned)
|
|
123
|
+
* - "-TZS1000", "TZS-1000", "-1000TZS" (negative amounts)
|
|
124
|
+
* - Case-insensitive: "tzs10000", "TZS10000", "Tzs10000"
|
|
110
125
|
*
|
|
111
|
-
* @param input -
|
|
112
|
-
* @param currencyCode -
|
|
113
|
-
* @returns Amount instance or undefined if
|
|
114
|
-
*
|
|
115
|
-
* @example
|
|
116
|
-
* ```typescript
|
|
117
|
-
* Amount.from(1000); // Valid: TSh 1,000.00
|
|
118
|
-
* Amount.from(-500, 'USD'); // Valid: -$500.00
|
|
119
|
-
* Amount.from('-1,234.56'); // Valid: -TSh 1,234.56
|
|
120
|
-
* Amount.from('abc'); // Invalid: returns undefined
|
|
121
|
-
* Amount.from(''); // Invalid: returns undefined
|
|
122
|
-
* ```
|
|
126
|
+
* @param input - String with currency-amount or number
|
|
127
|
+
* @param currencyCode - Currency code (optional if detected from string)
|
|
128
|
+
* @returns Amount instance or undefined if invalid
|
|
129
|
+
* @throws Error with clear message if format is invalid
|
|
123
130
|
*/
|
|
124
131
|
static from(input: string | number, currencyCode?: CurrencyCode | null): Amount | undefined;
|
|
132
|
+
/**
|
|
133
|
+
* Parse currency-amount combination from cleaned string
|
|
134
|
+
* @param cleaned - String with whitespace already removed
|
|
135
|
+
* @returns Object with currency code and amount string
|
|
136
|
+
*/
|
|
137
|
+
private static parseCurrencyAmount;
|
|
138
|
+
/**
|
|
139
|
+
* Validate and normalize currency code
|
|
140
|
+
* @param code - Currency code string (e.g., "TZS", "tzs")
|
|
141
|
+
* @returns Normalized currency code or undefined if invalid
|
|
142
|
+
*/
|
|
143
|
+
private static validateCurrencyCode;
|
|
144
|
+
/**
|
|
145
|
+
* Create Amount from numeric value
|
|
146
|
+
*/
|
|
147
|
+
private static fromNumericValue;
|
|
148
|
+
/**
|
|
149
|
+
* Create Amount from parsed currency and amount values
|
|
150
|
+
* @param amountStr - Numeric amount string (may include commas, decimal, minus)
|
|
151
|
+
* @param currencyCode - Validated currency code
|
|
152
|
+
*/
|
|
153
|
+
private static fromParsedValues;
|
|
125
154
|
/**
|
|
126
155
|
* Returns the currency code
|
|
127
156
|
*
|
package/package.json
CHANGED