@cranberry-money/shared-utils 5.0.0 → 5.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.
Files changed (49) hide show
  1. package/package.json +1 -1
  2. package/dist/auth.d.ts +0 -55
  3. package/dist/auth.d.ts.map +0 -1
  4. package/dist/auth.js +0 -135
  5. package/dist/badge-status.d.ts +0 -65
  6. package/dist/badge-status.d.ts.map +0 -1
  7. package/dist/badge-status.js +0 -170
  8. package/dist/badge.d.ts +0 -41
  9. package/dist/badge.d.ts.map +0 -1
  10. package/dist/badge.js +0 -72
  11. package/dist/collections.d.ts +0 -81
  12. package/dist/collections.d.ts.map +0 -1
  13. package/dist/collections.js +0 -127
  14. package/dist/currency.d.ts +0 -99
  15. package/dist/currency.d.ts.map +0 -1
  16. package/dist/currency.js +0 -128
  17. package/dist/date.d.ts +0 -64
  18. package/dist/date.d.ts.map +0 -1
  19. package/dist/date.js +0 -91
  20. package/dist/downloads.d.ts +0 -46
  21. package/dist/downloads.d.ts.map +0 -1
  22. package/dist/downloads.js +0 -91
  23. package/dist/filters.d.ts +0 -121
  24. package/dist/filters.d.ts.map +0 -1
  25. package/dist/filters.js +0 -206
  26. package/dist/formatting.d.ts +0 -59
  27. package/dist/formatting.d.ts.map +0 -1
  28. package/dist/formatting.js +0 -81
  29. package/dist/index.d.ts +0 -22
  30. package/dist/index.d.ts.map +0 -1
  31. package/dist/index.js +0 -40
  32. package/dist/instruments.d.ts +0 -66
  33. package/dist/instruments.d.ts.map +0 -1
  34. package/dist/instruments.js +0 -135
  35. package/dist/numbers.d.ts +0 -72
  36. package/dist/numbers.d.ts.map +0 -1
  37. package/dist/numbers.js +0 -101
  38. package/dist/portfolio.d.ts +0 -68
  39. package/dist/portfolio.d.ts.map +0 -1
  40. package/dist/portfolio.js +0 -87
  41. package/dist/text.d.ts +0 -22
  42. package/dist/text.d.ts.map +0 -1
  43. package/dist/text.js +0 -25
  44. package/dist/validation.d.ts +0 -226
  45. package/dist/validation.d.ts.map +0 -1
  46. package/dist/validation.js +0 -337
  47. package/dist/withdrawal.d.ts +0 -87
  48. package/dist/withdrawal.d.ts.map +0 -1
  49. package/dist/withdrawal.js +0 -119
@@ -1,119 +0,0 @@
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
- }