@temboplus/frontend-core 1.0.1-beta.3 → 1.0.1
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/domain/amount/amount.d.ts +15 -0
- package/dist/domain/amount/amount.helpers.d.ts +13 -0
- package/dist/factories/amount.factory.d.ts +1 -9
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
|
@@ -316,6 +316,21 @@ declare class Amount {
|
|
|
316
316
|
* ```
|
|
317
317
|
*/
|
|
318
318
|
percentage(percentage: number): Amount;
|
|
319
|
+
/**
|
|
320
|
+
* Returns this amount as a percentage of another amount or numeric value.
|
|
321
|
+
*
|
|
322
|
+
* @param other - Amount object or number to use as the denominator
|
|
323
|
+
* @returns Percentage value as a number
|
|
324
|
+
* @throws {Error} If currencies don't match when comparing Amount objects
|
|
325
|
+
* @throws {Error} If the denominator is zero
|
|
326
|
+
*
|
|
327
|
+
* @example
|
|
328
|
+
* ```typescript
|
|
329
|
+
* Amount.from(25).asPercentageOf(Amount.from(100)); // 25
|
|
330
|
+
* Amount.from(50).asPercentageOf(200); // 25
|
|
331
|
+
* ```
|
|
332
|
+
*/
|
|
333
|
+
asPercentageOf(other: Amount | number): number;
|
|
319
334
|
/**
|
|
320
335
|
* Checks if this amount is zero
|
|
321
336
|
*
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Currency } from "../currency/currency.js";
|
|
2
2
|
import type { CurrencyCode } from "../currency/currency.types.js";
|
|
3
|
+
import type { Amount } from "./amount.js";
|
|
3
4
|
/**
|
|
4
5
|
* Formatting options for the enhanced format method.
|
|
5
6
|
*/
|
|
@@ -52,13 +53,25 @@ declare function formatAmountText(value: number, currency: Currency): string;
|
|
|
52
53
|
declare function formatAmountWithIntl(value: number, currency: Currency, options: AmountFormatOptions): string;
|
|
53
54
|
declare function formatAmountManually(value: number, currency: Currency, options: AmountFormatOptions): string;
|
|
54
55
|
declare function formatCompactAmount(value: number, currency: Currency, precision?: number, options?: AmountCompactFormatOptions): string;
|
|
56
|
+
/** Sum of every Amount, requiring a non-empty array with matching currencies. */
|
|
57
|
+
declare function sum(amounts: Amount[]): Amount;
|
|
58
|
+
/** Mean of every Amount, requiring a non-empty array with matching currencies. */
|
|
59
|
+
declare function average(amounts: Amount[]): Amount;
|
|
60
|
+
/** Smallest Amount in the array. */
|
|
61
|
+
declare function min(amounts: Amount[]): Amount;
|
|
62
|
+
/** Largest Amount in the array. */
|
|
63
|
+
declare function max(amounts: Amount[]): Amount;
|
|
55
64
|
export declare const AmountHelpers: {
|
|
56
65
|
AMOUNT_REGEX: RegExp;
|
|
66
|
+
average: typeof average;
|
|
57
67
|
containsForbiddenCurrencySymbol: typeof containsForbiddenCurrencySymbol;
|
|
58
68
|
formatAmountText: typeof formatAmountText;
|
|
59
69
|
formatAmountManually: typeof formatAmountManually;
|
|
60
70
|
formatAmountWithIntl: typeof formatAmountWithIntl;
|
|
61
71
|
formatCompactAmount: typeof formatCompactAmount;
|
|
72
|
+
max: typeof max;
|
|
73
|
+
min: typeof min;
|
|
62
74
|
parseCurrencyAmountInput: typeof parseCurrencyAmountInput;
|
|
75
|
+
sum: typeof sum;
|
|
63
76
|
};
|
|
64
77
|
export {};
|
|
@@ -2,7 +2,7 @@ import { Amount } from "@domain/amount/amount.js";
|
|
|
2
2
|
import { type AmountJSON } from "@domain/amount/amount.schema.js";
|
|
3
3
|
import type { CurrencyCode } from "@domain/currency/currency.types.js";
|
|
4
4
|
/**
|
|
5
|
-
* Owns Amount construction, parsing,
|
|
5
|
+
* Owns Amount construction, parsing, and validation.
|
|
6
6
|
* Resolves currencies through CurrencyRegistry; never owns currency data itself.
|
|
7
7
|
*/
|
|
8
8
|
export declare class AmountFactory {
|
|
@@ -35,14 +35,6 @@ export declare class AmountFactory {
|
|
|
35
35
|
isAmountJSON(obj: unknown): obj is AmountJSON;
|
|
36
36
|
/** Verifies that an Amount instance can still be reconstructed cleanly. */
|
|
37
37
|
validate(amount: Amount): boolean;
|
|
38
|
-
/** Sum of every Amount, requiring matching currencies. */
|
|
39
|
-
sum(amounts: Amount[]): Amount;
|
|
40
|
-
/** Mean of every Amount, requiring matching currencies and non-empty array. */
|
|
41
|
-
average(amounts: Amount[]): Amount;
|
|
42
|
-
/** Smallest Amount in the array (most negative wins). */
|
|
43
|
-
min(amounts: Amount[]): Amount;
|
|
44
|
-
/** Largest Amount in the array. */
|
|
45
|
-
max(amounts: Amount[]): Amount;
|
|
46
38
|
/** Builds an Amount by validating a numeric string and currency code. */
|
|
47
39
|
private createFromString;
|
|
48
40
|
/** Resolves a (possibly mixed-case) currency code to its canonical form. */
|