You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Normalize a cents amount input into a trimmed string representing whole cents.
10
-
*
11
-
* @param amountCents - A `bigint`, `number`, or `string` representing cents. If a `number`, it must be an integer; if a `string`, surrounding whitespace will be trimmed.
12
-
* @returns The normalized string representation of whole cents.
13
-
* @throws Error if `amountCents` is a `number` that is not an integer.
@@ -24,17 +17,13 @@ function normalizeCentsInput(amountCents: bigint | number | string): string {
24
17
returnString(amountCents);
25
18
}
26
19
27
-
returnamountCents.trim();
20
+
consttrimmed=amountCents.trim();
21
+
if(!/^-?\d+$/.test(trimmed)){
22
+
thrownewError('Currency formatter expects a valid integer string.');
23
+
}
24
+
returntrimmed;
28
25
}
29
26
30
-
/**
31
-
* Format a whole-cents monetary value into a currency string with symbol, thousands separators, and two decimal places.
32
-
*
33
-
* @param amountCents - The amount in whole cents (`bigint | number | string`). If a `number` is provided it must be an integer; `string` inputs are trimmed.
34
-
* @param currency - The target currency code used to pick the symbol (defaults to `'USD'`).
35
-
* @returns The formatted currency string including the currency symbol, grouped thousands, a decimal point, and exactly two fractional digits; a leading `-` is preserved for negative values.
36
-
* @throws If `amountCents` is a `number` that is not an integer.
0 commit comments