@cranberry-money/shared-utils 8.19.1 → 8.19.2
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/README.md +1 -1
- package/dist/allocations.d.ts +18 -0
- package/dist/allocations.d.ts.map +1 -0
- package/dist/allocations.js +21 -0
- package/dist/allocations.js.map +1 -0
- package/dist/badge-status.d.ts +65 -0
- package/dist/badge-status.d.ts.map +1 -0
- package/dist/badge-status.js +171 -0
- package/dist/badge-status.js.map +1 -0
- package/dist/badge.d.ts +41 -0
- package/dist/badge.d.ts.map +1 -0
- package/dist/badge.js +73 -0
- package/dist/badge.js.map +1 -0
- package/dist/cash-account.d.ts +43 -0
- package/dist/cash-account.d.ts.map +1 -0
- package/dist/cash-account.js +53 -0
- package/dist/cash-account.js.map +1 -0
- package/dist/currency.d.ts +99 -0
- package/dist/currency.d.ts.map +1 -0
- package/dist/currency.js +129 -0
- package/dist/currency.js.map +1 -0
- package/dist/dashboard.d.ts +72 -0
- package/dist/dashboard.d.ts.map +1 -0
- package/dist/dashboard.js +122 -0
- package/dist/dashboard.js.map +1 -0
- package/dist/date.d.ts +64 -0
- package/dist/date.d.ts.map +1 -0
- package/dist/date.js +92 -0
- package/dist/date.js.map +1 -0
- package/dist/downloads.d.ts +12 -0
- package/dist/downloads.d.ts.map +1 -0
- package/dist/downloads.js +21 -0
- package/dist/downloads.js.map +1 -0
- package/dist/filters.d.ts +82 -0
- package/dist/filters.d.ts.map +1 -0
- package/dist/filters.js +110 -0
- package/dist/filters.js.map +1 -0
- package/dist/holdings.d.ts +16 -0
- package/dist/holdings.d.ts.map +1 -0
- package/dist/holdings.js +24 -0
- package/dist/holdings.js.map +1 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +47 -0
- package/dist/index.js.map +1 -0
- package/dist/instruments.d.ts +17 -0
- package/dist/instruments.d.ts.map +1 -0
- package/dist/instruments.js +37 -0
- package/dist/instruments.js.map +1 -0
- package/dist/numbers.d.ts +16 -0
- package/dist/numbers.d.ts.map +1 -0
- package/dist/numbers.js +28 -0
- package/dist/numbers.js.map +1 -0
- package/dist/portfolio-template.d.ts +57 -0
- package/dist/portfolio-template.d.ts.map +1 -0
- package/dist/portfolio-template.js +62 -0
- package/dist/portfolio-template.js.map +1 -0
- package/dist/portfolio-validation.d.ts +36 -0
- package/dist/portfolio-validation.d.ts.map +1 -0
- package/dist/portfolio-validation.js +40 -0
- package/dist/portfolio-validation.js.map +1 -0
- package/dist/portfolio.d.ts +68 -0
- package/dist/portfolio.d.ts.map +1 -0
- package/dist/portfolio.js +88 -0
- package/dist/portfolio.js.map +1 -0
- package/dist/text.d.ts +22 -0
- package/dist/text.d.ts.map +1 -0
- package/dist/text.js +26 -0
- package/dist/text.js.map +1 -0
- package/dist/validation.d.ts +93 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +144 -0
- package/dist/validation.js.map +1 -0
- package/dist/withdrawal-status.d.ts +68 -0
- package/dist/withdrawal-status.d.ts.map +1 -0
- package/dist/withdrawal-status.js +128 -0
- package/dist/withdrawal-status.js.map +1 -0
- package/dist/withdrawal.d.ts +48 -0
- package/dist/withdrawal.d.ts.map +1 -0
- package/dist/withdrawal.js +63 -0
- package/dist/withdrawal.js.map +1 -0
- package/package.json +18 -16
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @myportfolio/shared-utils
|
|
2
2
|
|
|
3
|
-
Shared utility functions for the
|
|
3
|
+
Shared utility functions for the Blueberry platform, supporting both web (Blueberry) and mobile (Blackberry) applications.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { AssetAllocation } from '@cranberry-money/shared-types';
|
|
2
|
+
/**
|
|
3
|
+
* Validates if allocation percentages sum to 100%
|
|
4
|
+
* Allows for small floating point errors (e.g., 99.99 or 100.01)
|
|
5
|
+
*
|
|
6
|
+
* @param allocations - Array of asset allocations to validate
|
|
7
|
+
* @returns true if allocations sum to approximately 100%, false otherwise
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const allocations = [
|
|
11
|
+
* { percentage: '50.00' },
|
|
12
|
+
* { percentage: '30.00' },
|
|
13
|
+
* { percentage: '20.00' }
|
|
14
|
+
* ];
|
|
15
|
+
* validateAllocations(allocations); // returns true
|
|
16
|
+
*/
|
|
17
|
+
export declare const validateAllocations: (allocations: readonly AssetAllocation[]) => boolean;
|
|
18
|
+
//# sourceMappingURL=allocations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"allocations.d.ts","sourceRoot":"","sources":["../src/allocations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAErE;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,mBAAmB,GAAI,aAAa,SAAS,eAAe,EAAE,KAAG,OAK7E,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validates if allocation percentages sum to 100%
|
|
3
|
+
* Allows for small floating point errors (e.g., 99.99 or 100.01)
|
|
4
|
+
*
|
|
5
|
+
* @param allocations - Array of asset allocations to validate
|
|
6
|
+
* @returns true if allocations sum to approximately 100%, false otherwise
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* const allocations = [
|
|
10
|
+
* { percentage: '50.00' },
|
|
11
|
+
* { percentage: '30.00' },
|
|
12
|
+
* { percentage: '20.00' }
|
|
13
|
+
* ];
|
|
14
|
+
* validateAllocations(allocations); // returns true
|
|
15
|
+
*/
|
|
16
|
+
export const validateAllocations = (allocations) => {
|
|
17
|
+
const totalPercentage = allocations.reduce((sum, allocation) => sum + parseFloat(allocation.percentage), 0);
|
|
18
|
+
// Allow for small floating point errors (e.g., 99.99 or 100.01)
|
|
19
|
+
return Math.abs(totalPercentage - 100) < 0.01;
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=allocations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"allocations.js","sourceRoot":"","sources":["../src/allocations.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,WAAuC,EAAW,EAAE;IACtF,MAAM,eAAe,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,UAAU,EAAE,EAAE,CAAC,GAAG,GAAG,UAAU,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC;IAE5G,gEAAgE;IAChE,OAAO,IAAI,CAAC,GAAG,CAAC,eAAe,GAAG,GAAG,CAAC,GAAG,IAAI,CAAC;AAChD,CAAC,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Badge Status Utilities - Status-specific badge functions
|
|
3
|
+
*
|
|
4
|
+
* This module provides pre-configured badge functions for common status types
|
|
5
|
+
* in the Blueberry platform. It builds on top of the core badge system.
|
|
6
|
+
*/
|
|
7
|
+
import type { StatusBadgeStyle, TradeStatus, WithdrawalStatus, LiquidationStatus, TargetTradeStatus } from '@cranberry-money/shared-types';
|
|
8
|
+
import type { BadgeSize } from '@cranberry-money/shared-types';
|
|
9
|
+
/**
|
|
10
|
+
* Creates a badge for trade status
|
|
11
|
+
*
|
|
12
|
+
* @param status - Trade status constant
|
|
13
|
+
* @param size - Badge size (default: 'md')
|
|
14
|
+
* @returns Badge style with display text and accessibility attributes
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const badge = getTradeStatusBadge(TRADE_STATUS_SETTLED);
|
|
19
|
+
* // Returns badge with success variant and "Settled" display text
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare function getTradeStatusBadge(status: TradeStatus, size?: BadgeSize): StatusBadgeStyle;
|
|
23
|
+
/**
|
|
24
|
+
* Creates a badge for withdrawal status
|
|
25
|
+
*
|
|
26
|
+
* @param status - Withdrawal status constant
|
|
27
|
+
* @param size - Badge size (default: 'md')
|
|
28
|
+
* @returns Badge style with display text and accessibility attributes
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const badge = getWithdrawalStatusBadge(WITHDRAWAL_STATUS_APPROVED);
|
|
33
|
+
* // Returns badge with success variant and "Approved" display text
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare function getWithdrawalStatusBadge(status: WithdrawalStatus, size?: BadgeSize): StatusBadgeStyle;
|
|
37
|
+
/**
|
|
38
|
+
* Creates a badge for liquidation status
|
|
39
|
+
*
|
|
40
|
+
* @param status - Liquidation status constant
|
|
41
|
+
* @param size - Badge size (default: 'md')
|
|
42
|
+
* @returns Badge style with display text and accessibility attributes
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* const badge = getLiquidationStatusBadge(LIQUIDATION_STATUS_SETTLED);
|
|
47
|
+
* // Returns badge with success variant and "Settled" display text
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export declare function getLiquidationStatusBadge(status: LiquidationStatus, size?: BadgeSize): StatusBadgeStyle;
|
|
51
|
+
/**
|
|
52
|
+
* Creates a badge for target trade status
|
|
53
|
+
*
|
|
54
|
+
* @param status - Target trade status constant
|
|
55
|
+
* @param size - Badge size (default: 'md')
|
|
56
|
+
* @returns Badge style with display text and accessibility attributes
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* const badge = getTargetTradeStatusBadge(TARGET_TRADE_STATUS_PENDING);
|
|
61
|
+
* // Returns badge with warning variant and "Pending" display text
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export declare function getTargetTradeStatusBadge(status: TargetTradeStatus, size?: BadgeSize): StatusBadgeStyle;
|
|
65
|
+
//# sourceMappingURL=badge-status.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"badge-status.d.ts","sourceRoot":"","sources":["../src/badge-status.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EACV,gBAAgB,EAChB,WAAW,EACX,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,+BAA+B,CAAC;AAmDvC,OAAO,KAAK,EAAgB,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAiF7E;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,WAAW,EAAE,IAAI,GAAE,SAAgB,GAAG,gBAAgB,CAUjG;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,gBAAgB,EAAE,IAAI,GAAE,SAAgB,GAAG,gBAAgB,CAU3G;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,iBAAiB,EAAE,IAAI,GAAE,SAAgB,GAAG,gBAAgB,CAU7G;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,iBAAiB,EAAE,IAAI,GAAE,SAAgB,GAAG,gBAAgB,CAU7G"}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Badge Status Utilities - Status-specific badge functions
|
|
3
|
+
*
|
|
4
|
+
* This module provides pre-configured badge functions for common status types
|
|
5
|
+
* in the Blueberry platform. It builds on top of the core badge system.
|
|
6
|
+
*/
|
|
7
|
+
import { TRADE_STATUS_EXECUTED, TRADE_STATUS_SETTLED, TRADE_STATUS_CANCELLED, TRADE_STATUS_FAILED, TRADE_STATUS_LABEL_EXECUTED, TRADE_STATUS_LABEL_SETTLED, TRADE_STATUS_LABEL_CANCELLED, TRADE_STATUS_LABEL_FAILED, TARGET_TRADE_STATUS_PENDING, TARGET_TRADE_STATUS_APPROVED, TARGET_TRADE_STATUS_SUBMITTED, TARGET_TRADE_STATUS_CANCELLED, TARGET_TRADE_STATUS_EXPIRED, TARGET_TRADE_STATUS_LABEL_PENDING, TARGET_TRADE_STATUS_LABEL_APPROVED, TARGET_TRADE_STATUS_LABEL_SUBMITTED, TARGET_TRADE_STATUS_LABEL_CANCELLED, TARGET_TRADE_STATUS_LABEL_EXPIRED, WITHDRAWAL_STATUS_PENDING_REVIEW, WITHDRAWAL_STATUS_APPROVED, WITHDRAWAL_STATUS_REJECTED, WITHDRAWAL_STATUS_PROCESSING, WITHDRAWAL_STATUS_AWAITING_LIQUIDATION, WITHDRAWAL_STATUS_LIQUIDATION_IN_PROGRESS, WITHDRAWAL_STATUS_COMPLETED, WITHDRAWAL_STATUS_CANCELLED, WITHDRAWAL_STATUS_FAILED, WITHDRAWAL_STATUS_LABEL_PENDING_REVIEW, WITHDRAWAL_STATUS_LABEL_APPROVED, WITHDRAWAL_STATUS_LABEL_REJECTED, WITHDRAWAL_STATUS_LABEL_PROCESSING, WITHDRAWAL_STATUS_LABEL_AWAITING_LIQUIDATION, WITHDRAWAL_STATUS_LABEL_LIQUIDATION_IN_PROGRESS, WITHDRAWAL_STATUS_LABEL_COMPLETED, WITHDRAWAL_STATUS_LABEL_CANCELLED, WITHDRAWAL_STATUS_LABEL_FAILED, LIQUIDATION_STATUS_PENDING, LIQUIDATION_STATUS_TRADES_CREATED, LIQUIDATION_STATUS_EXECUTED, LIQUIDATION_STATUS_SETTLED, LIQUIDATION_STATUS_FAILED, LIQUIDATION_STATUS_LABEL_PENDING, LIQUIDATION_STATUS_LABEL_TRADES_CREATED, LIQUIDATION_STATUS_LABEL_EXECUTED, LIQUIDATION_STATUS_LABEL_SETTLED, LIQUIDATION_STATUS_LABEL_FAILED, } from '@cranberry-money/shared-constants';
|
|
8
|
+
import { createBadge } from './badge';
|
|
9
|
+
// Status to variant mappings
|
|
10
|
+
const TRADE_STATUS_MAPPING = {
|
|
11
|
+
[TRADE_STATUS_EXECUTED]: 'primary',
|
|
12
|
+
[TRADE_STATUS_SETTLED]: 'success',
|
|
13
|
+
[TRADE_STATUS_CANCELLED]: 'error',
|
|
14
|
+
[TRADE_STATUS_FAILED]: 'error',
|
|
15
|
+
[TARGET_TRADE_STATUS_PENDING]: 'warning',
|
|
16
|
+
[TARGET_TRADE_STATUS_SUBMITTED]: 'primary',
|
|
17
|
+
[TARGET_TRADE_STATUS_EXPIRED]: 'neutral',
|
|
18
|
+
};
|
|
19
|
+
const WITHDRAWAL_STATUS_MAPPING = {
|
|
20
|
+
[WITHDRAWAL_STATUS_PENDING_REVIEW]: 'warning',
|
|
21
|
+
[WITHDRAWAL_STATUS_APPROVED]: 'success',
|
|
22
|
+
[WITHDRAWAL_STATUS_REJECTED]: 'error',
|
|
23
|
+
[WITHDRAWAL_STATUS_PROCESSING]: 'primary',
|
|
24
|
+
[WITHDRAWAL_STATUS_AWAITING_LIQUIDATION]: 'warning',
|
|
25
|
+
[WITHDRAWAL_STATUS_LIQUIDATION_IN_PROGRESS]: 'primary',
|
|
26
|
+
[WITHDRAWAL_STATUS_COMPLETED]: 'success',
|
|
27
|
+
[WITHDRAWAL_STATUS_CANCELLED]: 'neutral',
|
|
28
|
+
[WITHDRAWAL_STATUS_FAILED]: 'error',
|
|
29
|
+
};
|
|
30
|
+
const LIQUIDATION_STATUS_MAPPING = {
|
|
31
|
+
[LIQUIDATION_STATUS_PENDING]: 'warning',
|
|
32
|
+
[LIQUIDATION_STATUS_TRADES_CREATED]: 'primary',
|
|
33
|
+
[LIQUIDATION_STATUS_EXECUTED]: 'primary',
|
|
34
|
+
[LIQUIDATION_STATUS_SETTLED]: 'success',
|
|
35
|
+
[LIQUIDATION_STATUS_FAILED]: 'error',
|
|
36
|
+
};
|
|
37
|
+
const TARGET_TRADE_STATUS_MAPPING = {
|
|
38
|
+
[TARGET_TRADE_STATUS_PENDING]: 'warning',
|
|
39
|
+
[TARGET_TRADE_STATUS_APPROVED]: 'success',
|
|
40
|
+
[TARGET_TRADE_STATUS_SUBMITTED]: 'primary',
|
|
41
|
+
[TARGET_TRADE_STATUS_CANCELLED]: 'error',
|
|
42
|
+
[TARGET_TRADE_STATUS_EXPIRED]: 'neutral',
|
|
43
|
+
};
|
|
44
|
+
// Status to label mappings
|
|
45
|
+
const TRADE_STATUS_LABELS = {
|
|
46
|
+
[TRADE_STATUS_EXECUTED]: TRADE_STATUS_LABEL_EXECUTED,
|
|
47
|
+
[TRADE_STATUS_SETTLED]: TRADE_STATUS_LABEL_SETTLED,
|
|
48
|
+
[TRADE_STATUS_CANCELLED]: TRADE_STATUS_LABEL_CANCELLED,
|
|
49
|
+
[TRADE_STATUS_FAILED]: TRADE_STATUS_LABEL_FAILED,
|
|
50
|
+
[TARGET_TRADE_STATUS_PENDING]: TARGET_TRADE_STATUS_LABEL_PENDING,
|
|
51
|
+
[TARGET_TRADE_STATUS_SUBMITTED]: TARGET_TRADE_STATUS_LABEL_SUBMITTED,
|
|
52
|
+
[TARGET_TRADE_STATUS_EXPIRED]: TARGET_TRADE_STATUS_LABEL_EXPIRED,
|
|
53
|
+
};
|
|
54
|
+
const WITHDRAWAL_STATUS_LABELS = {
|
|
55
|
+
[WITHDRAWAL_STATUS_PENDING_REVIEW]: WITHDRAWAL_STATUS_LABEL_PENDING_REVIEW,
|
|
56
|
+
[WITHDRAWAL_STATUS_APPROVED]: WITHDRAWAL_STATUS_LABEL_APPROVED,
|
|
57
|
+
[WITHDRAWAL_STATUS_REJECTED]: WITHDRAWAL_STATUS_LABEL_REJECTED,
|
|
58
|
+
[WITHDRAWAL_STATUS_PROCESSING]: WITHDRAWAL_STATUS_LABEL_PROCESSING,
|
|
59
|
+
[WITHDRAWAL_STATUS_AWAITING_LIQUIDATION]: WITHDRAWAL_STATUS_LABEL_AWAITING_LIQUIDATION,
|
|
60
|
+
[WITHDRAWAL_STATUS_LIQUIDATION_IN_PROGRESS]: WITHDRAWAL_STATUS_LABEL_LIQUIDATION_IN_PROGRESS,
|
|
61
|
+
[WITHDRAWAL_STATUS_COMPLETED]: WITHDRAWAL_STATUS_LABEL_COMPLETED,
|
|
62
|
+
[WITHDRAWAL_STATUS_CANCELLED]: WITHDRAWAL_STATUS_LABEL_CANCELLED,
|
|
63
|
+
[WITHDRAWAL_STATUS_FAILED]: WITHDRAWAL_STATUS_LABEL_FAILED,
|
|
64
|
+
};
|
|
65
|
+
const LIQUIDATION_STATUS_LABELS = {
|
|
66
|
+
[LIQUIDATION_STATUS_PENDING]: LIQUIDATION_STATUS_LABEL_PENDING,
|
|
67
|
+
[LIQUIDATION_STATUS_TRADES_CREATED]: LIQUIDATION_STATUS_LABEL_TRADES_CREATED,
|
|
68
|
+
[LIQUIDATION_STATUS_EXECUTED]: LIQUIDATION_STATUS_LABEL_EXECUTED,
|
|
69
|
+
[LIQUIDATION_STATUS_SETTLED]: LIQUIDATION_STATUS_LABEL_SETTLED,
|
|
70
|
+
[LIQUIDATION_STATUS_FAILED]: LIQUIDATION_STATUS_LABEL_FAILED,
|
|
71
|
+
};
|
|
72
|
+
const TARGET_TRADE_STATUS_LABELS = {
|
|
73
|
+
[TARGET_TRADE_STATUS_PENDING]: TARGET_TRADE_STATUS_LABEL_PENDING,
|
|
74
|
+
[TARGET_TRADE_STATUS_APPROVED]: TARGET_TRADE_STATUS_LABEL_APPROVED,
|
|
75
|
+
[TARGET_TRADE_STATUS_SUBMITTED]: TARGET_TRADE_STATUS_LABEL_SUBMITTED,
|
|
76
|
+
[TARGET_TRADE_STATUS_CANCELLED]: TARGET_TRADE_STATUS_LABEL_CANCELLED,
|
|
77
|
+
[TARGET_TRADE_STATUS_EXPIRED]: TARGET_TRADE_STATUS_LABEL_EXPIRED,
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Creates a badge for trade status
|
|
81
|
+
*
|
|
82
|
+
* @param status - Trade status constant
|
|
83
|
+
* @param size - Badge size (default: 'md')
|
|
84
|
+
* @returns Badge style with display text and accessibility attributes
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* const badge = getTradeStatusBadge(TRADE_STATUS_SETTLED);
|
|
89
|
+
* // Returns badge with success variant and "Settled" display text
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
export function getTradeStatusBadge(status, size = 'md') {
|
|
93
|
+
const variant = TRADE_STATUS_MAPPING[status] || 'neutral';
|
|
94
|
+
const badge = createBadge({ variant, size });
|
|
95
|
+
const displayText = TRADE_STATUS_LABELS[status] || status.charAt(0) + status.slice(1).toLowerCase();
|
|
96
|
+
return {
|
|
97
|
+
...badge,
|
|
98
|
+
displayText,
|
|
99
|
+
ariaLabel: `Trade status: ${displayText}`,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Creates a badge for withdrawal status
|
|
104
|
+
*
|
|
105
|
+
* @param status - Withdrawal status constant
|
|
106
|
+
* @param size - Badge size (default: 'md')
|
|
107
|
+
* @returns Badge style with display text and accessibility attributes
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```typescript
|
|
111
|
+
* const badge = getWithdrawalStatusBadge(WITHDRAWAL_STATUS_APPROVED);
|
|
112
|
+
* // Returns badge with success variant and "Approved" display text
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
export function getWithdrawalStatusBadge(status, size = 'md') {
|
|
116
|
+
const variant = WITHDRAWAL_STATUS_MAPPING[status] || 'neutral';
|
|
117
|
+
const badge = createBadge({ variant, size });
|
|
118
|
+
const displayText = WITHDRAWAL_STATUS_LABELS[status] || status;
|
|
119
|
+
return {
|
|
120
|
+
...badge,
|
|
121
|
+
displayText,
|
|
122
|
+
ariaLabel: `Withdrawal status: ${displayText}`,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Creates a badge for liquidation status
|
|
127
|
+
*
|
|
128
|
+
* @param status - Liquidation status constant
|
|
129
|
+
* @param size - Badge size (default: 'md')
|
|
130
|
+
* @returns Badge style with display text and accessibility attributes
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* ```typescript
|
|
134
|
+
* const badge = getLiquidationStatusBadge(LIQUIDATION_STATUS_SETTLED);
|
|
135
|
+
* // Returns badge with success variant and "Settled" display text
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
export function getLiquidationStatusBadge(status, size = 'md') {
|
|
139
|
+
const variant = LIQUIDATION_STATUS_MAPPING[status] || 'neutral';
|
|
140
|
+
const badge = createBadge({ variant, size });
|
|
141
|
+
const displayText = LIQUIDATION_STATUS_LABELS[status] || status;
|
|
142
|
+
return {
|
|
143
|
+
...badge,
|
|
144
|
+
displayText,
|
|
145
|
+
ariaLabel: `Liquidation status: ${displayText}`,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Creates a badge for target trade status
|
|
150
|
+
*
|
|
151
|
+
* @param status - Target trade status constant
|
|
152
|
+
* @param size - Badge size (default: 'md')
|
|
153
|
+
* @returns Badge style with display text and accessibility attributes
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```typescript
|
|
157
|
+
* const badge = getTargetTradeStatusBadge(TARGET_TRADE_STATUS_PENDING);
|
|
158
|
+
* // Returns badge with warning variant and "Pending" display text
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
161
|
+
export function getTargetTradeStatusBadge(status, size = 'md') {
|
|
162
|
+
const variant = TARGET_TRADE_STATUS_MAPPING[status] || 'neutral';
|
|
163
|
+
const badge = createBadge({ variant, size });
|
|
164
|
+
const displayText = TARGET_TRADE_STATUS_LABELS[status] || status;
|
|
165
|
+
return {
|
|
166
|
+
...badge,
|
|
167
|
+
displayText,
|
|
168
|
+
ariaLabel: `Target trade status: ${displayText}`,
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
//# sourceMappingURL=badge-status.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"badge-status.js","sourceRoot":"","sources":["../src/badge-status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AAC;AACJ,CAAC"}
|
package/dist/badge.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Badge System Core - Type definitions and factory function
|
|
3
|
+
*
|
|
4
|
+
* This module provides a standardized way to create and style badges.
|
|
5
|
+
* It ensures consistency in colors, typography, and semantic meaning
|
|
6
|
+
* while maintaining accessibility standards.
|
|
7
|
+
*
|
|
8
|
+
* Note: The actual style classes are designed to work with Tailwind CSS
|
|
9
|
+
* and assume a specific color system is in place.
|
|
10
|
+
*/
|
|
11
|
+
import type { BadgeVariant, BadgeSize, BadgeConfig, BadgeStyle } from '@cranberry-money/shared-types';
|
|
12
|
+
/**
|
|
13
|
+
* Creates a badge style configuration with appropriate CSS classes
|
|
14
|
+
*
|
|
15
|
+
* @param config - Badge configuration options
|
|
16
|
+
* @param variantStyles - Optional custom variant styles (defaults to DEFAULT_BADGE_VARIANTS)
|
|
17
|
+
* @param sizeStyles - Optional custom size styles (defaults to DEFAULT_BADGE_SIZES)
|
|
18
|
+
* @returns Badge style object with className and accessibility attributes
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* // Create a success badge
|
|
23
|
+
* const successBadge = createBadge({ variant: 'success' });
|
|
24
|
+
* // Returns: { className: 'inline-flex items-center rounded-md font-medium whitespace-nowrap transition-colors bg-success-900/80 text-success-300 text-xs px-2 py-1', ariaLabel: 'success status' }
|
|
25
|
+
*
|
|
26
|
+
* // Create a large warning badge with custom class
|
|
27
|
+
* const warningBadge = createBadge({ variant: 'warning', size: 'lg', className: 'ml-2' });
|
|
28
|
+
*
|
|
29
|
+
* // Use custom variant styles
|
|
30
|
+
* const customVariants = { primary: 'bg-blue-500 text-white', ... };
|
|
31
|
+
* const customBadge = createBadge({ variant: 'primary' }, customVariants);
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare function createBadge({ variant, size, className }: BadgeConfig, variantStyles?: Record<BadgeVariant, string>, sizeStyles?: Record<BadgeSize, string>): BadgeStyle;
|
|
35
|
+
/**
|
|
36
|
+
* Export the default style mappings for consumers who want to use them directly
|
|
37
|
+
* or extend them with their own styles
|
|
38
|
+
*/
|
|
39
|
+
export declare const BADGE_VARIANTS: Record<BadgeVariant, string>;
|
|
40
|
+
export declare const BADGE_SIZES: Record<BadgeSize, string>;
|
|
41
|
+
//# sourceMappingURL=badge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"badge.d.ts","sourceRoot":"","sources":["../src/badge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AA+BtG;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,WAAW,CACzB,EAAE,OAAO,EAAE,IAAW,EAAE,SAAc,EAAE,EAAE,WAAW,EACrD,aAAa,GAAE,MAAM,CAAC,YAAY,EAAE,MAAM,CAA0B,EACpE,UAAU,GAAE,MAAM,CAAC,SAAS,EAAE,MAAM,CAAuB,GAC1D,UAAU,CAQZ;AAED;;;GAGG;AACH,eAAO,MAAM,cAAc,8BAAyB,CAAC;AACrD,eAAO,MAAM,WAAW,2BAAsB,CAAC"}
|
package/dist/badge.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Badge System Core - Type definitions and factory function
|
|
3
|
+
*
|
|
4
|
+
* This module provides a standardized way to create and style badges.
|
|
5
|
+
* It ensures consistency in colors, typography, and semantic meaning
|
|
6
|
+
* while maintaining accessibility standards.
|
|
7
|
+
*
|
|
8
|
+
* Note: The actual style classes are designed to work with Tailwind CSS
|
|
9
|
+
* and assume a specific color system is in place.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Default variant styles using Tailwind CSS classes
|
|
13
|
+
* These assume a specific color system with surface and semantic colors
|
|
14
|
+
*/
|
|
15
|
+
const DEFAULT_BADGE_VARIANTS = {
|
|
16
|
+
default: 'bg-surface-secondary text-content-body',
|
|
17
|
+
primary: 'bg-surface-tertiary text-content-secondary',
|
|
18
|
+
secondary: 'bg-surface-secondary text-content-body',
|
|
19
|
+
success: 'bg-success-900/80 text-success-300',
|
|
20
|
+
warning: 'bg-warning-900/80 text-warning-300',
|
|
21
|
+
error: 'bg-error-900/80 text-error-300',
|
|
22
|
+
info: 'bg-surface-tertiary text-content-body',
|
|
23
|
+
neutral: 'bg-surface-secondary text-content-muted',
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Default size styles for badges
|
|
27
|
+
*/
|
|
28
|
+
const DEFAULT_BADGE_SIZES = {
|
|
29
|
+
sm: 'text-xs px-1.5 py-0.5',
|
|
30
|
+
md: 'text-xs px-2 py-1',
|
|
31
|
+
lg: 'text-sm px-3 py-1.5',
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Base badge styles that apply to all badges
|
|
35
|
+
*/
|
|
36
|
+
const BASE_BADGE_STYLES = 'inline-flex items-center rounded-md font-medium whitespace-nowrap transition-colors';
|
|
37
|
+
/**
|
|
38
|
+
* Creates a badge style configuration with appropriate CSS classes
|
|
39
|
+
*
|
|
40
|
+
* @param config - Badge configuration options
|
|
41
|
+
* @param variantStyles - Optional custom variant styles (defaults to DEFAULT_BADGE_VARIANTS)
|
|
42
|
+
* @param sizeStyles - Optional custom size styles (defaults to DEFAULT_BADGE_SIZES)
|
|
43
|
+
* @returns Badge style object with className and accessibility attributes
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* // Create a success badge
|
|
48
|
+
* const successBadge = createBadge({ variant: 'success' });
|
|
49
|
+
* // Returns: { className: 'inline-flex items-center rounded-md font-medium whitespace-nowrap transition-colors bg-success-900/80 text-success-300 text-xs px-2 py-1', ariaLabel: 'success status' }
|
|
50
|
+
*
|
|
51
|
+
* // Create a large warning badge with custom class
|
|
52
|
+
* const warningBadge = createBadge({ variant: 'warning', size: 'lg', className: 'ml-2' });
|
|
53
|
+
*
|
|
54
|
+
* // Use custom variant styles
|
|
55
|
+
* const customVariants = { primary: 'bg-blue-500 text-white', ... };
|
|
56
|
+
* const customBadge = createBadge({ variant: 'primary' }, customVariants);
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export function createBadge({ variant, size = 'md', className = '' }, variantStyles = DEFAULT_BADGE_VARIANTS, sizeStyles = DEFAULT_BADGE_SIZES) {
|
|
60
|
+
const variantClasses = variantStyles[variant] || variantStyles.neutral;
|
|
61
|
+
const sizeClasses = sizeStyles[size];
|
|
62
|
+
return {
|
|
63
|
+
className: `${BASE_BADGE_STYLES} ${variantClasses} ${sizeClasses} ${className}`.trim(),
|
|
64
|
+
ariaLabel: `${variant} status`,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Export the default style mappings for consumers who want to use them directly
|
|
69
|
+
* or extend them with their own styles
|
|
70
|
+
*/
|
|
71
|
+
export const BADGE_VARIANTS = DEFAULT_BADGE_VARIANTS;
|
|
72
|
+
export const BADGE_SIZES = DEFAULT_BADGE_SIZES;
|
|
73
|
+
//# sourceMappingURL=badge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"badge.js","sourceRoot":"","sources":["../src/badge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAKH;;;GAGG;AACH,MAAM,sBAAsB,GAAiC;IAC3D,OAAO,EAAE,wCAAwC;IACjD,OAAO,EAAE,4CAA4C;IACrD,SAAS,EAAE,wCAAwC;IACnD,OAAO,EAAE,oCAAoC;IAC7C,OAAO,EAAE,oCAAoC;IAC7C,KAAK,EAAE,gCAAgC;IACvC,IAAI,EAAE,uCAAuC;IAC7C,OAAO,EAAE,yCAAyC;CACnD,CAAC;AAEF;;GAEG;AACH,MAAM,mBAAmB,GAA8B;IACrD,EAAE,EAAE,uBAAuB;IAC3B,EAAE,EAAE,mBAAmB;IACvB,EAAE,EAAE,qBAAqB;CAC1B,CAAC;AAEF;;GAEG;AACH,MAAM,iBAAiB,GAAG,qFAAqF,CAAC;AAEhH;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,WAAW,CACzB,EAAE,OAAO,EAAE,IAAI,GAAG,IAAI,EAAE,SAAS,GAAG,EAAE,EAAe,EACrD,gBAA8C,sBAAsB,EACpE,aAAwC,mBAAmB;IAE3D,MAAM,cAAc,GAAG,aAAa,CAAC,OAAO,CAAC,IAAI,aAAa,CAAC,OAAO,CAAC;IACvE,MAAM,WAAW,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;IAErC,OAAO;QACL,SAAS,EAAE,GAAG,iBAAiB,IAAI,cAAc,IAAI,WAAW,IAAI,SAAS,EAAE,CAAC,IAAI,EAAE;QACtF,SAAS,EAAE,GAAG,OAAO,SAAS;KAC/B,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,sBAAsB,CAAC;AACrD,MAAM,CAAC,MAAM,WAAW,GAAG,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base transaction type interface for type flexibility
|
|
3
|
+
*/
|
|
4
|
+
export interface BaseTransactionType {
|
|
5
|
+
readonly [key: string]: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Format cash account balance with AUD currency formatting
|
|
9
|
+
*
|
|
10
|
+
* @param balance - Balance value to format (string or number)
|
|
11
|
+
* @returns Formatted currency string using Australian locale and AUD currency
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* formatBalance(1234.56); // returns '$1,234.56'
|
|
15
|
+
* formatBalance('1000'); // returns '$1,000.00'
|
|
16
|
+
* formatBalance(0); // returns '$0.00'
|
|
17
|
+
*/
|
|
18
|
+
export declare const formatBalance: (balance: string | number) => string;
|
|
19
|
+
/**
|
|
20
|
+
* Format transaction amount with signed currency formatting (shows + or -)
|
|
21
|
+
*
|
|
22
|
+
* @param amount - Transaction amount to format (string or number)
|
|
23
|
+
* @returns Formatted signed currency string using Australian locale and AUD currency
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* formatTransactionAmount(1234.56); // returns '+$1,234.56'
|
|
27
|
+
* formatTransactionAmount(-500); // returns '-$500.00'
|
|
28
|
+
* formatTransactionAmount('1000'); // returns '+$1,000.00'
|
|
29
|
+
*/
|
|
30
|
+
export declare const formatTransactionAmount: (amount: string | number) => string;
|
|
31
|
+
/**
|
|
32
|
+
* Get human-readable label for transaction type
|
|
33
|
+
*
|
|
34
|
+
* @param transactionType - Transaction type key
|
|
35
|
+
* @param labels - Optional custom transaction type labels (defaults to shared constants)
|
|
36
|
+
* @returns Human-readable transaction type label
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* getTransactionTypeLabel('DEPOSIT'); // returns transaction type label from constants
|
|
40
|
+
* getTransactionTypeLabel('WITHDRAWAL'); // returns transaction type label from constants
|
|
41
|
+
*/
|
|
42
|
+
export declare const getTransactionTypeLabel: <T extends string>(transactionType: T, labels?: Record<T, string>) => string;
|
|
43
|
+
//# sourceMappingURL=cash-account.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cash-account.d.ts","sourceRoot":"","sources":["../src/cash-account.ts"],"names":[],"mappings":"AAOA;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;CAChC;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,aAAa,GAAI,SAAS,MAAM,GAAG,MAAM,KAAG,MAMxD,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,uBAAuB,GAAI,QAAQ,MAAM,GAAG,MAAM,KAAG,MAMjE,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,uBAAuB,GAAI,CAAC,SAAS,MAAM,EACtD,iBAAiB,CAAC,EAClB,SAAQ,MAAM,CAAC,CAAC,EAAE,MAAM,CAA6D,KACpF,MAEF,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { LOCALE_AUSTRALIA, CURRENCY_AUD, CASH_ACCOUNT_TRANSACTION_TYPE_LABELS, } from '@cranberry-money/shared-constants';
|
|
2
|
+
import { NUMBER_FORMAT_OPTIONS_CURRENCY, NUMBER_FORMAT_OPTIONS_CURRENCY_SIGNED } from './currency';
|
|
3
|
+
/**
|
|
4
|
+
* Format cash account balance with AUD currency formatting
|
|
5
|
+
*
|
|
6
|
+
* @param balance - Balance value to format (string or number)
|
|
7
|
+
* @returns Formatted currency string using Australian locale and AUD currency
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* formatBalance(1234.56); // returns '$1,234.56'
|
|
11
|
+
* formatBalance('1000'); // returns '$1,000.00'
|
|
12
|
+
* formatBalance(0); // returns '$0.00'
|
|
13
|
+
*/
|
|
14
|
+
export const formatBalance = (balance) => {
|
|
15
|
+
const numBalance = typeof balance === 'string' ? parseFloat(balance) : balance;
|
|
16
|
+
return new Intl.NumberFormat(LOCALE_AUSTRALIA, {
|
|
17
|
+
...NUMBER_FORMAT_OPTIONS_CURRENCY,
|
|
18
|
+
currency: CURRENCY_AUD,
|
|
19
|
+
}).format(numBalance);
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Format transaction amount with signed currency formatting (shows + or -)
|
|
23
|
+
*
|
|
24
|
+
* @param amount - Transaction amount to format (string or number)
|
|
25
|
+
* @returns Formatted signed currency string using Australian locale and AUD currency
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* formatTransactionAmount(1234.56); // returns '+$1,234.56'
|
|
29
|
+
* formatTransactionAmount(-500); // returns '-$500.00'
|
|
30
|
+
* formatTransactionAmount('1000'); // returns '+$1,000.00'
|
|
31
|
+
*/
|
|
32
|
+
export const formatTransactionAmount = (amount) => {
|
|
33
|
+
const numAmount = typeof amount === 'string' ? parseFloat(amount) : amount;
|
|
34
|
+
return new Intl.NumberFormat(LOCALE_AUSTRALIA, {
|
|
35
|
+
...NUMBER_FORMAT_OPTIONS_CURRENCY_SIGNED,
|
|
36
|
+
currency: CURRENCY_AUD,
|
|
37
|
+
}).format(numAmount);
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Get human-readable label for transaction type
|
|
41
|
+
*
|
|
42
|
+
* @param transactionType - Transaction type key
|
|
43
|
+
* @param labels - Optional custom transaction type labels (defaults to shared constants)
|
|
44
|
+
* @returns Human-readable transaction type label
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* getTransactionTypeLabel('DEPOSIT'); // returns transaction type label from constants
|
|
48
|
+
* getTransactionTypeLabel('WITHDRAWAL'); // returns transaction type label from constants
|
|
49
|
+
*/
|
|
50
|
+
export const getTransactionTypeLabel = (transactionType, labels = CASH_ACCOUNT_TRANSACTION_TYPE_LABELS) => {
|
|
51
|
+
return labels[transactionType];
|
|
52
|
+
};
|
|
53
|
+
//# sourceMappingURL=cash-account.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cash-account.js","sourceRoot":"","sources":["../src/cash-account.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,oCAAoC,GACrC,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,8BAA8B,EAAE,qCAAqC,EAAE,MAAM,YAAY,CAAC;AASnG;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,OAAwB,EAAU,EAAE;IAChE,MAAM,UAAU,GAAG,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;IAC/E,OAAO,IAAI,IAAI,CAAC,YAAY,CAAC,gBAAgB,EAAE;QAC7C,GAAG,8BAA8B;QACjC,QAAQ,EAAE,YAAY;KACvB,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;AACxB,CAAC,CAAC;AAEF;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,MAAuB,EAAU,EAAE;IACzE,MAAM,SAAS,GAAG,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IAC3E,OAAO,IAAI,IAAI,CAAC,YAAY,CAAC,gBAAgB,EAAE;QAC7C,GAAG,qCAAqC;QACxC,QAAQ,EAAE,YAAY;KACvB,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;AACvB,CAAC,CAAC;AAEF;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CACrC,eAAkB,EAClB,SAA4B,oCAAyD,EAC7E,EAAE;IACV,OAAO,MAAM,CAAC,eAAe,CAAC,CAAC;AACjC,CAAC,CAAC"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Currency formatting utility functions and constants
|
|
3
|
+
*
|
|
4
|
+
* This module provides pure functions for formatting currency values,
|
|
5
|
+
* parsing currency inputs, and working with different currency formats.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Number formatting options for currency display
|
|
9
|
+
*/
|
|
10
|
+
export declare const NUMBER_FORMAT_OPTIONS_CURRENCY: {
|
|
11
|
+
readonly style: "currency";
|
|
12
|
+
readonly minimumFractionDigits: 2;
|
|
13
|
+
readonly maximumFractionDigits: 2;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Number formatting options for currency with explicit sign display
|
|
17
|
+
*/
|
|
18
|
+
export declare const NUMBER_FORMAT_OPTIONS_CURRENCY_SIGNED: {
|
|
19
|
+
readonly signDisplay: "always";
|
|
20
|
+
readonly style: "currency";
|
|
21
|
+
readonly minimumFractionDigits: 2;
|
|
22
|
+
readonly maximumFractionDigits: 2;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Formats a number as currency with commas and 2 decimal places
|
|
26
|
+
*
|
|
27
|
+
* @param value - Number or string value to format
|
|
28
|
+
* @returns Formatted currency string without currency symbol
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* formatCurrency(1234.5) // '1,234.50'
|
|
33
|
+
* formatCurrency('1234.5') // '1,234.50'
|
|
34
|
+
* formatCurrency(0) // '0.00'
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare function formatCurrency(value: number | string): string;
|
|
38
|
+
/**
|
|
39
|
+
* Parses a currency string input into a number
|
|
40
|
+
*
|
|
41
|
+
* @param value - Currency string to parse
|
|
42
|
+
* @returns Parsed number value (or 0 if invalid)
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* parseCurrencyInput('$1,234.56') // 1234.56
|
|
47
|
+
* parseCurrencyInput('1234.567') // 1234.56
|
|
48
|
+
* parseCurrencyInput('abc') // 0
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export declare function parseCurrencyInput(value: string): number;
|
|
52
|
+
/**
|
|
53
|
+
* Formats a number as currency with specific currency code and locale
|
|
54
|
+
*
|
|
55
|
+
* @param value - Number to format
|
|
56
|
+
* @param currencyCode - ISO 4217 currency code (default: DEFAULT_CURRENCY)
|
|
57
|
+
* @param locale - Locale for formatting (default: 'en-AU')
|
|
58
|
+
* @param minimumFractionDigits - Minimum decimal places (default: 0)
|
|
59
|
+
* @param maximumFractionDigits - Maximum decimal places (default: 0)
|
|
60
|
+
* @returns Formatted currency string
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* formatCurrencyWithCode(1234.5) // 'A$1,235'
|
|
65
|
+
* formatCurrencyWithCode(1234.5, 'USD', 'en-US') // '$1,235'
|
|
66
|
+
* formatCurrencyWithCode(1234.56, 'AUD', 'en-AU', 2, 2) // 'A$1,234.56'
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export declare function formatCurrencyWithCode(value: number, currencyCode?: string, locale?: string, minimumFractionDigits?: number, maximumFractionDigits?: number): string;
|
|
70
|
+
/**
|
|
71
|
+
* Convenience function to format currency with the default currency (AUD)
|
|
72
|
+
*
|
|
73
|
+
* @param value - Number to format
|
|
74
|
+
* @param minimumFractionDigits - Minimum decimal places (default: 0)
|
|
75
|
+
* @param maximumFractionDigits - Maximum decimal places (default: 0)
|
|
76
|
+
* @returns Formatted currency string with default currency
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```typescript
|
|
80
|
+
* formatDefaultCurrency(1234.5) // 'A$1,235'
|
|
81
|
+
* formatDefaultCurrency(1234.56, 2, 2) // 'A$1,234.56'
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
export declare function formatDefaultCurrency(value: number, minimumFractionDigits?: number, maximumFractionDigits?: number): string;
|
|
85
|
+
/**
|
|
86
|
+
* Formats a number for displaying share quantities (no decimals)
|
|
87
|
+
*
|
|
88
|
+
* @param shares - Number of shares to format
|
|
89
|
+
* @param locale - Locale for formatting (default: 'en-AU')
|
|
90
|
+
* @returns Formatted shares string with commas as thousands separators
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```typescript
|
|
94
|
+
* formatShares(1234) // '1,234'
|
|
95
|
+
* formatShares(1234567) // '1,234,567'
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
export declare function formatShares(shares: number, locale?: string): string;
|
|
99
|
+
//# sourceMappingURL=currency.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"currency.d.ts","sourceRoot":"","sources":["../src/currency.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH;;GAEG;AACH,eAAO,MAAM,8BAA8B;;;;CAIjC,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,qCAAqC;;;;;CAGxC,CAAC;AAEX;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAW7D;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAOxD;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,MAAM,EACb,YAAY,GAAE,MAAyB,EACvC,MAAM,GAAE,MAAgB,EACxB,qBAAqB,GAAE,MAAU,EACjC,qBAAqB,GAAE,MAAU,GAChC,MAAM,CASR;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,MAAM,EACb,qBAAqB,GAAE,MAAU,EACjC,qBAAqB,GAAE,MAAU,GAChC,MAAM,CAER;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,GAAE,MAAgB,GAAG,MAAM,CAK7E"}
|