@temboplus/frontend-core 1.0.1-beta.2 → 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/domain/amount/amount.schema.d.ts +4 -4
- package/dist/domain/bank/bank.schema.d.ts +6 -6
- package/dist/domain/country/country.schema.d.ts +8 -8
- package/dist/domain/currency/currency.schema.d.ts +4 -4
- package/dist/domain/mobile-money-provider/mobile-money-provider.schema.d.ts +3 -3
- package/dist/domain/phone-number/phone-number.schema.d.ts +3 -3
- 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 {};
|
|
@@ -10,10 +10,10 @@ export declare const AmountJSONSchema: z.ZodObject<{
|
|
|
10
10
|
text: z.ZodString;
|
|
11
11
|
/** The ISO currency code */
|
|
12
12
|
currencyCode: z.ZodString;
|
|
13
|
-
/**
|
|
14
|
-
|
|
13
|
+
/** Model JSON schema version for future compatibility. */
|
|
14
|
+
_version: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
15
15
|
}, "strip", z.ZodTypeAny, {
|
|
16
|
-
|
|
16
|
+
_version: string;
|
|
17
17
|
value: number;
|
|
18
18
|
text: string;
|
|
19
19
|
currencyCode: string;
|
|
@@ -21,7 +21,7 @@ export declare const AmountJSONSchema: z.ZodObject<{
|
|
|
21
21
|
value: number;
|
|
22
22
|
text: string;
|
|
23
23
|
currencyCode: string;
|
|
24
|
-
|
|
24
|
+
_version?: string | undefined;
|
|
25
25
|
}>;
|
|
26
26
|
/**
|
|
27
27
|
* Compact JSON identity for an Amount, sufficient to reconstruct the value via
|
|
@@ -14,26 +14,26 @@ export declare const BankJSONSchema: z.ZodEffects<z.ZodObject<{
|
|
|
14
14
|
swiftCode: z.ZodOptional<z.ZodString>;
|
|
15
15
|
/** The ISO 3166-1 alpha-2 country code */
|
|
16
16
|
countryCode: z.ZodString;
|
|
17
|
-
/**
|
|
18
|
-
|
|
17
|
+
/** Model JSON schema version for future compatibility. */
|
|
18
|
+
_version: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
19
19
|
}, "strip", z.ZodTypeAny, {
|
|
20
|
-
|
|
20
|
+
_version: string;
|
|
21
21
|
countryCode: string;
|
|
22
22
|
bic?: string | undefined;
|
|
23
23
|
swiftCode?: string | undefined;
|
|
24
24
|
}, {
|
|
25
25
|
countryCode: string;
|
|
26
|
-
|
|
26
|
+
_version?: string | undefined;
|
|
27
27
|
bic?: string | undefined;
|
|
28
28
|
swiftCode?: string | undefined;
|
|
29
29
|
}>, {
|
|
30
|
-
|
|
30
|
+
_version: string;
|
|
31
31
|
countryCode: string;
|
|
32
32
|
bic?: string | undefined;
|
|
33
33
|
swiftCode?: string | undefined;
|
|
34
34
|
}, {
|
|
35
35
|
countryCode: string;
|
|
36
|
-
|
|
36
|
+
_version?: string | undefined;
|
|
37
37
|
bic?: string | undefined;
|
|
38
38
|
swiftCode?: string | undefined;
|
|
39
39
|
}>;
|
|
@@ -6,14 +6,14 @@ import { z } from "zod";
|
|
|
6
6
|
export declare const CountryJSONSchema: z.ZodObject<{
|
|
7
7
|
/** The ISO 3166-1 alpha-2 country code */
|
|
8
8
|
code: z.ZodString;
|
|
9
|
-
/**
|
|
10
|
-
|
|
9
|
+
/** Model JSON schema version for future compatibility. */
|
|
10
|
+
_version: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
11
11
|
}, "strip", z.ZodTypeAny, {
|
|
12
12
|
code: string;
|
|
13
|
-
|
|
13
|
+
_version: string;
|
|
14
14
|
}, {
|
|
15
15
|
code: string;
|
|
16
|
-
|
|
16
|
+
_version?: string | undefined;
|
|
17
17
|
}>;
|
|
18
18
|
/**
|
|
19
19
|
* Zod schema for validating ISO 3166-1 alpha-2 country codes.
|
|
@@ -62,12 +62,12 @@ export declare const ISO3CountryCodeSchema: z.ZodEffects<z.ZodString, string, st
|
|
|
62
62
|
export declare const CountryCodeSchema: z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodString, string, string>, z.ZodObject<{
|
|
63
63
|
/** The ISO 3166-1 alpha-2 country code */
|
|
64
64
|
code: z.ZodString;
|
|
65
|
-
/**
|
|
66
|
-
|
|
65
|
+
/** Model JSON schema version for future compatibility. */
|
|
66
|
+
_version: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
67
67
|
}, "strip", z.ZodTypeAny, {
|
|
68
68
|
code: string;
|
|
69
|
-
|
|
69
|
+
_version: string;
|
|
70
70
|
}, {
|
|
71
71
|
code: string;
|
|
72
|
-
|
|
72
|
+
_version?: string | undefined;
|
|
73
73
|
}>]>;
|
|
@@ -13,12 +13,12 @@ export declare const CurrencyCodeSchema: z.ZodEffects<z.ZodString, string, strin
|
|
|
13
13
|
export declare const CurrencyJSONSchema: z.ZodObject<{
|
|
14
14
|
/** The ISO 4217 currency code */
|
|
15
15
|
code: z.ZodString;
|
|
16
|
-
/**
|
|
17
|
-
|
|
16
|
+
/** Model JSON schema version for future compatibility. */
|
|
17
|
+
_version: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
18
18
|
}, "strip", z.ZodTypeAny, {
|
|
19
19
|
code: string;
|
|
20
|
-
|
|
20
|
+
_version: string;
|
|
21
21
|
}, {
|
|
22
22
|
code: string;
|
|
23
|
-
|
|
23
|
+
_version?: string | undefined;
|
|
24
24
|
}>;
|
|
@@ -5,9 +5,9 @@ export declare const MobileMoneyProviderJSONSchema: z.ZodObject<{
|
|
|
5
5
|
countryCode: z.ZodString;
|
|
6
6
|
channelType: z.ZodDefault<z.ZodLiteral<ChannelType.MOBILE_MONEY>>;
|
|
7
7
|
direction: z.ZodOptional<z.ZodNativeEnum<typeof TransactionDirection>>;
|
|
8
|
-
|
|
8
|
+
_version: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
9
9
|
}, "strip", z.ZodTypeAny, {
|
|
10
|
-
|
|
10
|
+
_version: string;
|
|
11
11
|
countryCode: string;
|
|
12
12
|
id: string;
|
|
13
13
|
channelType: ChannelType.MOBILE_MONEY;
|
|
@@ -15,7 +15,7 @@ export declare const MobileMoneyProviderJSONSchema: z.ZodObject<{
|
|
|
15
15
|
}, {
|
|
16
16
|
countryCode: string;
|
|
17
17
|
id: string;
|
|
18
|
-
|
|
18
|
+
_version?: string | undefined;
|
|
19
19
|
channelType?: ChannelType.MOBILE_MONEY | undefined;
|
|
20
20
|
direction?: TransactionDirection | undefined;
|
|
21
21
|
}>;
|
|
@@ -10,12 +10,12 @@ import { z } from "zod";
|
|
|
10
10
|
*/
|
|
11
11
|
export declare const PhoneNumberJSONSchema: z.ZodObject<{
|
|
12
12
|
e164Format: z.ZodString;
|
|
13
|
-
|
|
13
|
+
_version: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
14
14
|
}, "strip", z.ZodTypeAny, {
|
|
15
|
-
|
|
15
|
+
_version: string;
|
|
16
16
|
e164Format: string;
|
|
17
17
|
}, {
|
|
18
18
|
e164Format: string;
|
|
19
|
-
|
|
19
|
+
_version?: string | undefined;
|
|
20
20
|
}>;
|
|
21
21
|
export type PhoneNumberJSON = z.infer<typeof PhoneNumberJSONSchema>;
|
|
@@ -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. */
|