@cranberry-money/shared-utils 4.6.0 → 4.7.0
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.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/portfolio.d.ts.map +1 -1
- package/dist/portfolio.js +1 -1
- package/dist/withdrawal.d.ts +97 -0
- package/dist/withdrawal.d.ts.map +1 -0
- package/dist/withdrawal.js +119 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -11,5 +11,7 @@ export type { BadgeVariant, BadgeSize, BadgeConfig, BadgeStyle } from './badge';
|
|
|
11
11
|
export { createBadge, BADGE_VARIANTS, BADGE_SIZES } from './badge';
|
|
12
12
|
export type { StatusBadgeStyle, TradeStatus, WithdrawalStatus, LiquidationStatus, TargetTradeStatus, } from './badge-status';
|
|
13
13
|
export { getTradeStatusBadge, getWithdrawalStatusBadge, getLiquidationStatusBadge, getTargetTradeStatusBadge, } from './badge-status';
|
|
14
|
-
export { formatPortfolioValue, calculateTotalValue, getMarketAllocation, getCashAllocation
|
|
14
|
+
export { formatPortfolioValue, calculateTotalValue, getMarketAllocation, getCashAllocation } from './portfolio';
|
|
15
|
+
export type { LiquidationProgress } from './withdrawal';
|
|
16
|
+
export { formatWithdrawalAmount, formatLiquidationValue, formatSharesQuantity, calculateLiquidationProgress, getTotalEstimatedValue, } from './withdrawal';
|
|
15
17
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAGtC,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAGjF,OAAO,EACL,8BAA8B,E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AAmB,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAGhH,YAAY,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,EACL,sBAAsB,EACtB,sBAAsB,EACtB,oBAAoB,EACpB,4BAA4B,EAC5B,sBAAsB,GACvB,MAAM,cAAc,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -13,4 +13,5 @@ export { NUMBER_FORMAT_OPTIONS_CURRENCY, NUMBER_FORMAT_OPTIONS_CURRENCY_SIGNED,
|
|
|
13
13
|
export { createBadge, BADGE_VARIANTS, BADGE_SIZES } from './badge';
|
|
14
14
|
export { getTradeStatusBadge, getWithdrawalStatusBadge, getLiquidationStatusBadge, getTargetTradeStatusBadge, } from './badge-status';
|
|
15
15
|
// Portfolio utilities
|
|
16
|
-
export { formatPortfolioValue, calculateTotalValue, getMarketAllocation, getCashAllocation
|
|
16
|
+
export { formatPortfolioValue, calculateTotalValue, getMarketAllocation, getCashAllocation } from './portfolio';
|
|
17
|
+
export { formatWithdrawalAmount, formatLiquidationValue, formatSharesQuantity, calculateLiquidationProgress, getTotalEstimatedValue, } from './withdrawal';
|
package/dist/portfolio.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"portfolio.d.ts","sourceRoot":"","sources":["../src/portfolio.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;
|
|
1
|
+
{"version":3,"file":"portfolio.d.ts","sourceRoot":"","sources":["../src/portfolio.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAUH;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAMnE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAItG;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAIrG;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAInG"}
|
package/dist/portfolio.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* allocations, and formatting. All functions handle string or number inputs
|
|
6
6
|
* for flexibility with API responses.
|
|
7
7
|
*/
|
|
8
|
-
import { LOCALE_AUSTRALIA, DEFAULT_NUMERIC_ZERO, DEFAULT_EMPTY_STRING, CURRENCY_AUD } from '@cranberry-money/shared-constants';
|
|
8
|
+
import { LOCALE_AUSTRALIA, DEFAULT_NUMERIC_ZERO, DEFAULT_EMPTY_STRING, CURRENCY_AUD, } from '@cranberry-money/shared-constants';
|
|
9
9
|
import { NUMBER_FORMAT_OPTIONS_CURRENCY } from './currency';
|
|
10
10
|
/**
|
|
11
11
|
* Formats a portfolio value as currency with AUD
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Withdrawal-related utility functions
|
|
3
|
+
*
|
|
4
|
+
* This module provides pure functions for formatting withdrawal amounts,
|
|
5
|
+
* calculating liquidation progress, and other withdrawal-related operations.
|
|
6
|
+
* Functions are designed to work with generic types to maintain flexibility.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Formats a withdrawal amount as currency
|
|
10
|
+
*
|
|
11
|
+
* @param amount - Withdrawal amount as string or number
|
|
12
|
+
* @returns Formatted currency string with AUD symbol
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* formatWithdrawalAmount(5000) // 'A$5,000.00'
|
|
17
|
+
* formatWithdrawalAmount('5000.50') // 'A$5,000.50'
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare function formatWithdrawalAmount(amount: string | number): string;
|
|
21
|
+
/**
|
|
22
|
+
* Formats a liquidation value as currency
|
|
23
|
+
*
|
|
24
|
+
* @param value - Liquidation value as string or number
|
|
25
|
+
* @returns Formatted currency string with AUD symbol
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* formatLiquidationValue(10000) // 'A$10,000.00'
|
|
30
|
+
* formatLiquidationValue('10000.50') // 'A$10,000.50'
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare function formatLiquidationValue(value: string | number): string;
|
|
34
|
+
/**
|
|
35
|
+
* Formats share quantity without decimal places
|
|
36
|
+
*
|
|
37
|
+
* @param shares - Number of shares
|
|
38
|
+
* @returns Formatted number string with thousands separators
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* formatSharesQuantity(1234) // '1,234'
|
|
43
|
+
* formatSharesQuantity(1234567) // '1,234,567'
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare function formatSharesQuantity(shares: number): string;
|
|
47
|
+
/**
|
|
48
|
+
* Progress calculation result for liquidations
|
|
49
|
+
*/
|
|
50
|
+
export interface LiquidationProgress {
|
|
51
|
+
total: number;
|
|
52
|
+
pending: number;
|
|
53
|
+
inProgress: number;
|
|
54
|
+
completed: number;
|
|
55
|
+
failed: number;
|
|
56
|
+
completionRate: number;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Calculates liquidation progress statistics
|
|
60
|
+
*
|
|
61
|
+
* @param liquidations - Array of liquidation objects with liquidationStatus property
|
|
62
|
+
* @returns Progress statistics including counts and completion rate
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* const liquidations = [
|
|
67
|
+
* { liquidationStatus: 'PENDING' },
|
|
68
|
+
* { liquidationStatus: 'SETTLED' },
|
|
69
|
+
* { liquidationStatus: 'FAILED' }
|
|
70
|
+
* ];
|
|
71
|
+
* calculateLiquidationProgress(liquidations)
|
|
72
|
+
* // Returns: { total: 3, pending: 1, inProgress: 0, completed: 1, failed: 1, completionRate: 33.33 }
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
export declare function calculateLiquidationProgress<T extends {
|
|
76
|
+
liquidationStatus: string;
|
|
77
|
+
}>(liquidations: T[]): LiquidationProgress;
|
|
78
|
+
/**
|
|
79
|
+
* Calculates total estimated value from liquidations
|
|
80
|
+
*
|
|
81
|
+
* @param liquidations - Array of liquidation objects with estimatedValue property
|
|
82
|
+
* @returns Total estimated value as number
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```typescript
|
|
86
|
+
* const liquidations = [
|
|
87
|
+
* { estimatedValue: '1000.50' },
|
|
88
|
+
* { estimatedValue: '2000' },
|
|
89
|
+
* { estimatedValue: null }
|
|
90
|
+
* ];
|
|
91
|
+
* getTotalEstimatedValue(liquidations) // 3000.50
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
export declare function getTotalEstimatedValue<T extends {
|
|
95
|
+
estimatedValue?: string | null;
|
|
96
|
+
}>(liquidations: T[]): number;
|
|
97
|
+
//# sourceMappingURL=withdrawal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withdrawal.d.ts","sourceRoot":"","sources":["../src/withdrawal.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAWH;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAMtE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAMrE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAK3D;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,MAAM,CAAC;CACxB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,4BAA4B,CAAC,CAAC,SAAS;IAAE,iBAAiB,EAAE,MAAM,CAAA;CAAE,EAClF,YAAY,EAAE,CAAC,EAAE,GAChB,mBAAmB,CAkBrB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,SAAS;IAAE,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,EACjF,YAAY,EAAE,CAAC,EAAE,GAChB,MAAM,CAIR"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Withdrawal-related utility functions
|
|
3
|
+
*
|
|
4
|
+
* This module provides pure functions for formatting withdrawal amounts,
|
|
5
|
+
* calculating liquidation progress, and other withdrawal-related operations.
|
|
6
|
+
* Functions are designed to work with generic types to maintain flexibility.
|
|
7
|
+
*/
|
|
8
|
+
import { LOCALE_AUSTRALIA, CURRENCY_AUD, LIQUIDATION_STATUS_PENDING, LIQUIDATION_STATUS_TRADES_CREATED, LIQUIDATION_STATUS_EXECUTED, LIQUIDATION_STATUS_SETTLED, LIQUIDATION_STATUS_FAILED } from '@cranberry-money/shared-constants';
|
|
9
|
+
import { NUMBER_FORMAT_OPTIONS_CURRENCY } from './currency';
|
|
10
|
+
/**
|
|
11
|
+
* Formats a withdrawal amount as currency
|
|
12
|
+
*
|
|
13
|
+
* @param amount - Withdrawal amount as string or number
|
|
14
|
+
* @returns Formatted currency string with AUD symbol
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* formatWithdrawalAmount(5000) // 'A$5,000.00'
|
|
19
|
+
* formatWithdrawalAmount('5000.50') // 'A$5,000.50'
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export function formatWithdrawalAmount(amount) {
|
|
23
|
+
const numValue = typeof amount === 'string' ? parseFloat(amount) : amount;
|
|
24
|
+
return new Intl.NumberFormat(LOCALE_AUSTRALIA, {
|
|
25
|
+
...NUMBER_FORMAT_OPTIONS_CURRENCY,
|
|
26
|
+
currency: CURRENCY_AUD,
|
|
27
|
+
}).format(numValue);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Formats a liquidation value as currency
|
|
31
|
+
*
|
|
32
|
+
* @param value - Liquidation value as string or number
|
|
33
|
+
* @returns Formatted currency string with AUD symbol
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* formatLiquidationValue(10000) // 'A$10,000.00'
|
|
38
|
+
* formatLiquidationValue('10000.50') // 'A$10,000.50'
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export function formatLiquidationValue(value) {
|
|
42
|
+
const numValue = typeof value === 'string' ? parseFloat(value) : value;
|
|
43
|
+
return new Intl.NumberFormat(LOCALE_AUSTRALIA, {
|
|
44
|
+
...NUMBER_FORMAT_OPTIONS_CURRENCY,
|
|
45
|
+
currency: CURRENCY_AUD,
|
|
46
|
+
}).format(numValue);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Formats share quantity without decimal places
|
|
50
|
+
*
|
|
51
|
+
* @param shares - Number of shares
|
|
52
|
+
* @returns Formatted number string with thousands separators
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* formatSharesQuantity(1234) // '1,234'
|
|
57
|
+
* formatSharesQuantity(1234567) // '1,234,567'
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export function formatSharesQuantity(shares) {
|
|
61
|
+
return new Intl.NumberFormat(LOCALE_AUSTRALIA, {
|
|
62
|
+
minimumFractionDigits: 0,
|
|
63
|
+
maximumFractionDigits: 0,
|
|
64
|
+
}).format(shares);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Calculates liquidation progress statistics
|
|
68
|
+
*
|
|
69
|
+
* @param liquidations - Array of liquidation objects with liquidationStatus property
|
|
70
|
+
* @returns Progress statistics including counts and completion rate
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* const liquidations = [
|
|
75
|
+
* { liquidationStatus: 'PENDING' },
|
|
76
|
+
* { liquidationStatus: 'SETTLED' },
|
|
77
|
+
* { liquidationStatus: 'FAILED' }
|
|
78
|
+
* ];
|
|
79
|
+
* calculateLiquidationProgress(liquidations)
|
|
80
|
+
* // Returns: { total: 3, pending: 1, inProgress: 0, completed: 1, failed: 1, completionRate: 33.33 }
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
export function calculateLiquidationProgress(liquidations) {
|
|
84
|
+
const total = liquidations.length;
|
|
85
|
+
const pending = liquidations.filter((l) => l.liquidationStatus === LIQUIDATION_STATUS_PENDING).length;
|
|
86
|
+
const inProgress = liquidations.filter((l) => [LIQUIDATION_STATUS_TRADES_CREATED, LIQUIDATION_STATUS_EXECUTED].includes(l.liquidationStatus)).length;
|
|
87
|
+
const completed = liquidations.filter((l) => l.liquidationStatus === LIQUIDATION_STATUS_SETTLED).length;
|
|
88
|
+
const failed = liquidations.filter((l) => l.liquidationStatus === LIQUIDATION_STATUS_FAILED).length;
|
|
89
|
+
const completionRate = total > 0 ? (completed / total) * 100 : 0;
|
|
90
|
+
return {
|
|
91
|
+
total,
|
|
92
|
+
pending,
|
|
93
|
+
inProgress,
|
|
94
|
+
completed,
|
|
95
|
+
failed,
|
|
96
|
+
completionRate,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Calculates total estimated value from liquidations
|
|
101
|
+
*
|
|
102
|
+
* @param liquidations - Array of liquidation objects with estimatedValue property
|
|
103
|
+
* @returns Total estimated value as number
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```typescript
|
|
107
|
+
* const liquidations = [
|
|
108
|
+
* { estimatedValue: '1000.50' },
|
|
109
|
+
* { estimatedValue: '2000' },
|
|
110
|
+
* { estimatedValue: null }
|
|
111
|
+
* ];
|
|
112
|
+
* getTotalEstimatedValue(liquidations) // 3000.50
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
export function getTotalEstimatedValue(liquidations) {
|
|
116
|
+
return liquidations.reduce((total, liquidation) => {
|
|
117
|
+
return total + parseFloat(liquidation.estimatedValue || '0');
|
|
118
|
+
}, 0);
|
|
119
|
+
}
|