@cranberry-money/shared-utils 3.0.5 → 4.1.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 +5 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -6
- package/dist/text.d.ts +22 -0
- package/dist/text.d.ts.map +1 -0
- package/dist/text.js +25 -0
- package/package.json +4 -4
- package/dist/badge/badgeSystem.d.ts +0 -12
- package/dist/badge/badgeSystem.d.ts.map +0 -1
- package/dist/badge/badgeSystem.js +0 -153
- package/dist/badge/index.d.ts +0 -4
- package/dist/badge/index.d.ts.map +0 -1
- package/dist/badge/index.js +0 -2
- package/dist/formatters/currency.d.ts +0 -29
- package/dist/formatters/currency.d.ts.map +0 -1
- package/dist/formatters/currency.js +0 -55
- package/dist/formatters/dates.d.ts +0 -23
- package/dist/formatters/dates.d.ts.map +0 -1
- package/dist/formatters/dates.js +0 -51
- package/dist/formatters/index.d.ts +0 -7
- package/dist/formatters/index.d.ts.map +0 -1
- package/dist/formatters/index.js +0 -6
- package/dist/formatters/numbers.d.ts +0 -8
- package/dist/formatters/numbers.d.ts.map +0 -1
- package/dist/formatters/numbers.js +0 -13
- package/dist/helpers/filters.d.ts +0 -25
- package/dist/helpers/filters.d.ts.map +0 -1
- package/dist/helpers/filters.js +0 -41
- package/dist/helpers/index.d.ts +0 -7
- package/dist/helpers/index.d.ts.map +0 -1
- package/dist/helpers/index.js +0 -6
- package/dist/helpers/portfolio.d.ts +0 -20
- package/dist/helpers/portfolio.d.ts.map +0 -1
- package/dist/helpers/portfolio.js +0 -28
- package/dist/helpers/text.d.ts +0 -8
- package/dist/helpers/text.d.ts.map +0 -1
- package/dist/helpers/text.js +0 -11
- package/dist/portfolio/index.d.ts +0 -16
- package/dist/portfolio/index.d.ts.map +0 -1
- package/dist/portfolio/index.js +0 -44
- package/dist/validation/index.d.ts +0 -48
- package/dist/validation/index.d.ts.map +0 -1
- package/dist/validation/index.js +0 -77
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* @cranberry-money/shared-utils
|
|
3
|
+
*
|
|
4
|
+
* Shared utility functions for the MyPortfolio platform.
|
|
5
|
+
* All utilities are pure functions with no side effects.
|
|
3
6
|
*/
|
|
4
|
-
export
|
|
5
|
-
export * from './helpers';
|
|
6
|
-
export * from './portfolio';
|
|
7
|
-
export * from './validation';
|
|
8
|
-
export * from './badge';
|
|
7
|
+
export { truncateText } from './text';
|
|
9
8
|
//# 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
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* @cranberry-money/shared-utils
|
|
3
|
+
*
|
|
4
|
+
* Shared utility functions for the MyPortfolio platform.
|
|
5
|
+
* All utilities are pure functions with no side effects.
|
|
3
6
|
*/
|
|
4
|
-
|
|
5
|
-
export
|
|
6
|
-
export * from './portfolio';
|
|
7
|
-
export * from './validation';
|
|
8
|
-
export * from './badge';
|
|
7
|
+
// Text manipulation utilities
|
|
8
|
+
export { truncateText } from './text';
|
package/dist/text.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Text manipulation utility functions
|
|
3
|
+
*
|
|
4
|
+
* This module provides pure functions for common text operations
|
|
5
|
+
* such as truncation, formatting, and manipulation.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Truncates text to a specified maximum length and adds ellipsis if needed
|
|
9
|
+
*
|
|
10
|
+
* @param text - The text to truncate
|
|
11
|
+
* @param maxLength - The maximum length of the text (default: 30)
|
|
12
|
+
* @returns The truncated text with ellipsis if it exceeds maxLength
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* truncateText('This is a very long text', 10) // 'This is a...'
|
|
17
|
+
* truncateText('Short', 10) // 'Short'
|
|
18
|
+
* truncateText('', 10) // ''
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare function truncateText(text: string, maxLength?: number): string;
|
|
22
|
+
//# sourceMappingURL=text.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../src/text.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;;;;;;;;;GAaG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,GAAE,MAAW,GAAG,MAAM,CAGzE"}
|
package/dist/text.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Text manipulation utility functions
|
|
3
|
+
*
|
|
4
|
+
* This module provides pure functions for common text operations
|
|
5
|
+
* such as truncation, formatting, and manipulation.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Truncates text to a specified maximum length and adds ellipsis if needed
|
|
9
|
+
*
|
|
10
|
+
* @param text - The text to truncate
|
|
11
|
+
* @param maxLength - The maximum length of the text (default: 30)
|
|
12
|
+
* @returns The truncated text with ellipsis if it exceeds maxLength
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* truncateText('This is a very long text', 10) // 'This is a...'
|
|
17
|
+
* truncateText('Short', 10) // 'Short'
|
|
18
|
+
* truncateText('', 10) // ''
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export function truncateText(text, maxLength = 30) {
|
|
22
|
+
if (text.length <= maxLength)
|
|
23
|
+
return text;
|
|
24
|
+
return `${text.substring(0, maxLength)}...`;
|
|
25
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cranberry-money/shared-utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"description": "Shared utility functions for MyPortfolio platform",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -21,9 +21,9 @@
|
|
|
21
21
|
"dev": "tsc --watch"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@cranberry-money/shared-constants": "^
|
|
25
|
-
"@cranberry-money/shared-services": "^
|
|
26
|
-
"@cranberry-money/shared-types": "^
|
|
24
|
+
"@cranberry-money/shared-constants": "^4.0.0",
|
|
25
|
+
"@cranberry-money/shared-services": "^4.0.0",
|
|
26
|
+
"@cranberry-money/shared-types": "^4.0.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"typescript": "^5.0.0"
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { BadgeSize, BadgeConfig, BadgeStyle, BadgeStyleWithText } from '@cranberry-money/shared-types';
|
|
2
|
-
import { type TradeStatus as TradeStatusType, type TargetTradeStatus as TargetTradeStatusType, type WithdrawalStatus as WithdrawalStatusType, type LiquidationStatus as LiquidationStatusType } from '@cranberry-money/shared-constants';
|
|
3
|
-
export declare const createBadge: ({ variant, size, className }: BadgeConfig) => BadgeStyle;
|
|
4
|
-
export type TradeStatus = TradeStatusType | TargetTradeStatusType;
|
|
5
|
-
export declare const getTradeStatusBadge: (status: TradeStatus, size?: BadgeSize) => BadgeStyleWithText;
|
|
6
|
-
export type WithdrawalStatus = WithdrawalStatusType;
|
|
7
|
-
export declare const getWithdrawalStatusBadge: (status: WithdrawalStatus, size?: BadgeSize) => BadgeStyleWithText;
|
|
8
|
-
export type LiquidationStatus = LiquidationStatusType;
|
|
9
|
-
export declare const getLiquidationStatusBadge: (status: LiquidationStatus, size?: BadgeSize) => BadgeStyleWithText;
|
|
10
|
-
export type TargetTradeStatus = TargetTradeStatusType;
|
|
11
|
-
export declare const getTargetTradeStatusBadge: (status: TargetTradeStatus, size?: BadgeSize) => BadgeStyleWithText;
|
|
12
|
-
//# sourceMappingURL=badgeSystem.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"badgeSystem.d.ts","sourceRoot":"","sources":["../../src/badge/badgeSystem.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,SAAS,EACT,WAAW,EACX,UAAU,EACV,kBAAkB,EACnB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EASL,KAAK,WAAW,IAAI,eAAe,EACnC,KAAK,iBAAiB,IAAI,qBAAqB,EAC/C,KAAK,gBAAgB,IAAI,oBAAoB,EAC7C,KAAK,iBAAiB,IAAI,qBAAqB,EAChD,MAAM,mCAAmC,CAAC;AAkC3C,eAAO,MAAM,WAAW,GAAI,8BAA0C,WAAW,KAAG,UAQnF,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG,eAAe,GAAG,qBAAqB,CAAC;AA8BlE,eAAO,MAAM,mBAAmB,GAAI,QAAQ,WAAW,EAAE,OAAM,SAAgB,KAAG,kBAUjF,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,oBAAoB,CAAC;AA0BpD,eAAO,MAAM,wBAAwB,GAAI,QAAQ,gBAAgB,EAAE,OAAM,SAAgB,KAAG,kBAU3F,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG,qBAAqB,CAAC;AAkBtD,eAAO,MAAM,yBAAyB,GAAI,QAAQ,iBAAiB,EAAE,OAAM,SAAgB,KAAG,kBAU7F,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG,qBAAqB,CAAC;AAkBtD,eAAO,MAAM,yBAAyB,GAAI,QAAQ,iBAAiB,EAAE,OAAM,SAAgB,KAAG,kBAU7F,CAAC"}
|
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
import { TRADE_STATUS, TRADE_STATUS_LABELS, TARGET_TRADE_STATUS, TARGET_TRADE_STATUS_LABELS, WITHDRAWAL_STATUS, WITHDRAWAL_STATUS_LABELS, LIQUIDATION_STATUS, LIQUIDATION_STATUS_LABELS, } from '@cranberry-money/shared-constants';
|
|
2
|
-
/**
|
|
3
|
-
* Centralized Badge System
|
|
4
|
-
*
|
|
5
|
-
* This module provides a standardized way to create and style badges across the application.
|
|
6
|
-
* It ensures consistency in colors, typography, and semantic meaning while maintaining
|
|
7
|
-
* accessibility standards.
|
|
8
|
-
*/
|
|
9
|
-
/**
|
|
10
|
-
* Core badge styling configuration using custom color system
|
|
11
|
-
*/
|
|
12
|
-
const BADGE_VARIANTS = {
|
|
13
|
-
primary: 'bg-surface-tertiary text-content-secondary',
|
|
14
|
-
secondary: 'bg-surface-secondary text-content-body',
|
|
15
|
-
success: 'bg-success-900/80 text-success-300',
|
|
16
|
-
warning: 'bg-warning-900/80 text-warning-300',
|
|
17
|
-
error: 'bg-error-900/80 text-error-300',
|
|
18
|
-
info: 'bg-surface-tertiary text-content-body',
|
|
19
|
-
neutral: 'bg-surface-secondary text-content-muted',
|
|
20
|
-
};
|
|
21
|
-
const BADGE_SIZES = {
|
|
22
|
-
sm: 'text-xs px-1.5 py-0.5',
|
|
23
|
-
md: 'text-xs px-2 py-1',
|
|
24
|
-
lg: 'text-sm px-3 py-1.5',
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* Base badge styles that apply to all badges
|
|
28
|
-
*/
|
|
29
|
-
const BASE_BADGE_STYLES = 'inline-flex items-center rounded-md font-medium whitespace-nowrap transition-colors';
|
|
30
|
-
export const createBadge = ({ variant, size = 'md', className = '' }) => {
|
|
31
|
-
const variantClasses = BADGE_VARIANTS[variant];
|
|
32
|
-
const sizeClasses = BADGE_SIZES[size];
|
|
33
|
-
return {
|
|
34
|
-
className: `${BASE_BADGE_STYLES} ${variantClasses} ${sizeClasses} ${className}`.trim(),
|
|
35
|
-
ariaLabel: `${variant} status`,
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
const TRADE_STATUS_MAPPING = {
|
|
39
|
-
// Executed Trade Statuses
|
|
40
|
-
[TRADE_STATUS.EXECUTED]: 'primary',
|
|
41
|
-
[TRADE_STATUS.SETTLED]: 'success',
|
|
42
|
-
[TRADE_STATUS.CANCELLED]: 'error',
|
|
43
|
-
[TRADE_STATUS.FAILED]: 'error',
|
|
44
|
-
// Target Trade Statuses
|
|
45
|
-
[TARGET_TRADE_STATUS.PENDING]: 'warning',
|
|
46
|
-
[TARGET_TRADE_STATUS.APPROVED]: 'success',
|
|
47
|
-
[TARGET_TRADE_STATUS.SUBMITTED]: 'primary',
|
|
48
|
-
[TARGET_TRADE_STATUS.EXPIRED]: 'neutral',
|
|
49
|
-
// Note: TARGET_TRADE_STATUS.CANCELLED has same value as TRADE_STATUS.CANCELLED
|
|
50
|
-
};
|
|
51
|
-
const TRADE_STATUS_LABELS_MAP = {
|
|
52
|
-
// Executed Trade Status Labels
|
|
53
|
-
[TRADE_STATUS.EXECUTED]: TRADE_STATUS_LABELS.EXECUTED,
|
|
54
|
-
[TRADE_STATUS.SETTLED]: TRADE_STATUS_LABELS.SETTLED,
|
|
55
|
-
[TRADE_STATUS.CANCELLED]: TRADE_STATUS_LABELS.CANCELLED,
|
|
56
|
-
[TRADE_STATUS.FAILED]: TRADE_STATUS_LABELS.FAILED,
|
|
57
|
-
// Target Trade Status Labels
|
|
58
|
-
[TARGET_TRADE_STATUS.PENDING]: TARGET_TRADE_STATUS_LABELS.PENDING,
|
|
59
|
-
[TARGET_TRADE_STATUS.APPROVED]: TARGET_TRADE_STATUS_LABELS.APPROVED,
|
|
60
|
-
[TARGET_TRADE_STATUS.SUBMITTED]: TARGET_TRADE_STATUS_LABELS.SUBMITTED,
|
|
61
|
-
[TARGET_TRADE_STATUS.EXPIRED]: TARGET_TRADE_STATUS_LABELS.EXPIRED,
|
|
62
|
-
// Note: TARGET_TRADE_STATUS.CANCELLED has same value as TRADE_STATUS.CANCELLED
|
|
63
|
-
};
|
|
64
|
-
export const getTradeStatusBadge = (status, size = 'md') => {
|
|
65
|
-
const variant = TRADE_STATUS_MAPPING[status] || 'neutral';
|
|
66
|
-
const badge = createBadge({ variant, size });
|
|
67
|
-
const displayText = TRADE_STATUS_LABELS_MAP[status] || status.charAt(0) + status.slice(1).toLowerCase();
|
|
68
|
-
return {
|
|
69
|
-
...badge,
|
|
70
|
-
displayText,
|
|
71
|
-
ariaLabel: `Trade status: ${displayText}`,
|
|
72
|
-
};
|
|
73
|
-
};
|
|
74
|
-
const WITHDRAWAL_STATUS_MAPPING = {
|
|
75
|
-
[WITHDRAWAL_STATUS.PENDING_REVIEW]: 'warning',
|
|
76
|
-
[WITHDRAWAL_STATUS.APPROVED]: 'success',
|
|
77
|
-
[WITHDRAWAL_STATUS.REJECTED]: 'error',
|
|
78
|
-
[WITHDRAWAL_STATUS.PROCESSING]: 'primary',
|
|
79
|
-
[WITHDRAWAL_STATUS.AWAITING_LIQUIDATION]: 'warning',
|
|
80
|
-
[WITHDRAWAL_STATUS.LIQUIDATION_IN_PROGRESS]: 'primary',
|
|
81
|
-
[WITHDRAWAL_STATUS.COMPLETED]: 'success',
|
|
82
|
-
[WITHDRAWAL_STATUS.CANCELLED]: 'neutral',
|
|
83
|
-
[WITHDRAWAL_STATUS.FAILED]: 'error',
|
|
84
|
-
};
|
|
85
|
-
const WITHDRAWAL_STATUS_LABELS_MAP = {
|
|
86
|
-
[WITHDRAWAL_STATUS.PENDING_REVIEW]: WITHDRAWAL_STATUS_LABELS.PENDING_REVIEW,
|
|
87
|
-
[WITHDRAWAL_STATUS.APPROVED]: WITHDRAWAL_STATUS_LABELS.APPROVED,
|
|
88
|
-
[WITHDRAWAL_STATUS.REJECTED]: WITHDRAWAL_STATUS_LABELS.REJECTED,
|
|
89
|
-
[WITHDRAWAL_STATUS.PROCESSING]: WITHDRAWAL_STATUS_LABELS.PROCESSING,
|
|
90
|
-
[WITHDRAWAL_STATUS.AWAITING_LIQUIDATION]: WITHDRAWAL_STATUS_LABELS.AWAITING_LIQUIDATION,
|
|
91
|
-
[WITHDRAWAL_STATUS.LIQUIDATION_IN_PROGRESS]: WITHDRAWAL_STATUS_LABELS.LIQUIDATION_IN_PROGRESS,
|
|
92
|
-
[WITHDRAWAL_STATUS.COMPLETED]: WITHDRAWAL_STATUS_LABELS.COMPLETED,
|
|
93
|
-
[WITHDRAWAL_STATUS.CANCELLED]: WITHDRAWAL_STATUS_LABELS.CANCELLED,
|
|
94
|
-
[WITHDRAWAL_STATUS.FAILED]: WITHDRAWAL_STATUS_LABELS.FAILED,
|
|
95
|
-
};
|
|
96
|
-
export const getWithdrawalStatusBadge = (status, size = 'md') => {
|
|
97
|
-
const variant = WITHDRAWAL_STATUS_MAPPING[status] || 'neutral';
|
|
98
|
-
const badge = createBadge({ variant, size });
|
|
99
|
-
const displayText = WITHDRAWAL_STATUS_LABELS_MAP[status] || status;
|
|
100
|
-
return {
|
|
101
|
-
...badge,
|
|
102
|
-
displayText,
|
|
103
|
-
ariaLabel: `Withdrawal status: ${displayText}`,
|
|
104
|
-
};
|
|
105
|
-
};
|
|
106
|
-
const LIQUIDATION_STATUS_MAPPING = {
|
|
107
|
-
[LIQUIDATION_STATUS.PENDING]: 'warning',
|
|
108
|
-
[LIQUIDATION_STATUS.TRADES_CREATED]: 'primary',
|
|
109
|
-
[LIQUIDATION_STATUS.EXECUTED]: 'primary',
|
|
110
|
-
[LIQUIDATION_STATUS.SETTLED]: 'success',
|
|
111
|
-
[LIQUIDATION_STATUS.FAILED]: 'error',
|
|
112
|
-
};
|
|
113
|
-
const LIQUIDATION_STATUS_LABELS_MAP = {
|
|
114
|
-
[LIQUIDATION_STATUS.PENDING]: LIQUIDATION_STATUS_LABELS.PENDING,
|
|
115
|
-
[LIQUIDATION_STATUS.TRADES_CREATED]: LIQUIDATION_STATUS_LABELS.TRADES_CREATED,
|
|
116
|
-
[LIQUIDATION_STATUS.EXECUTED]: LIQUIDATION_STATUS_LABELS.EXECUTED,
|
|
117
|
-
[LIQUIDATION_STATUS.SETTLED]: LIQUIDATION_STATUS_LABELS.SETTLED,
|
|
118
|
-
[LIQUIDATION_STATUS.FAILED]: LIQUIDATION_STATUS_LABELS.FAILED,
|
|
119
|
-
};
|
|
120
|
-
export const getLiquidationStatusBadge = (status, size = 'md') => {
|
|
121
|
-
const variant = LIQUIDATION_STATUS_MAPPING[status] || 'neutral';
|
|
122
|
-
const badge = createBadge({ variant, size });
|
|
123
|
-
const displayText = LIQUIDATION_STATUS_LABELS_MAP[status] || status;
|
|
124
|
-
return {
|
|
125
|
-
...badge,
|
|
126
|
-
displayText,
|
|
127
|
-
ariaLabel: `Liquidation status: ${displayText}`,
|
|
128
|
-
};
|
|
129
|
-
};
|
|
130
|
-
const TARGET_TRADE_STATUS_MAPPING = {
|
|
131
|
-
[TARGET_TRADE_STATUS.PENDING]: 'warning',
|
|
132
|
-
[TARGET_TRADE_STATUS.APPROVED]: 'success',
|
|
133
|
-
[TARGET_TRADE_STATUS.SUBMITTED]: 'primary',
|
|
134
|
-
[TARGET_TRADE_STATUS.CANCELLED]: 'error',
|
|
135
|
-
[TARGET_TRADE_STATUS.EXPIRED]: 'neutral',
|
|
136
|
-
};
|
|
137
|
-
const TARGET_TRADE_STATUS_LABELS_MAP = {
|
|
138
|
-
[TARGET_TRADE_STATUS.PENDING]: TARGET_TRADE_STATUS_LABELS.PENDING,
|
|
139
|
-
[TARGET_TRADE_STATUS.APPROVED]: TARGET_TRADE_STATUS_LABELS.APPROVED,
|
|
140
|
-
[TARGET_TRADE_STATUS.SUBMITTED]: TARGET_TRADE_STATUS_LABELS.SUBMITTED,
|
|
141
|
-
[TARGET_TRADE_STATUS.CANCELLED]: TARGET_TRADE_STATUS_LABELS.CANCELLED,
|
|
142
|
-
[TARGET_TRADE_STATUS.EXPIRED]: TARGET_TRADE_STATUS_LABELS.EXPIRED,
|
|
143
|
-
};
|
|
144
|
-
export const getTargetTradeStatusBadge = (status, size = 'md') => {
|
|
145
|
-
const variant = TARGET_TRADE_STATUS_MAPPING[status] || 'neutral';
|
|
146
|
-
const badge = createBadge({ variant, size });
|
|
147
|
-
const displayText = TARGET_TRADE_STATUS_LABELS_MAP[status] || status;
|
|
148
|
-
return {
|
|
149
|
-
...badge,
|
|
150
|
-
displayText,
|
|
151
|
-
ariaLabel: `Target trade status: ${displayText}`,
|
|
152
|
-
};
|
|
153
|
-
};
|
package/dist/badge/index.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export type { BadgeVariant, BadgeSize, BadgeConfig, BadgeStyle, BadgeStyleWithText, } from '@cranberry-money/shared-types';
|
|
2
|
-
export type { TradeStatus, WithdrawalStatus, LiquidationStatus, TargetTradeStatus, } from './badgeSystem';
|
|
3
|
-
export { createBadge, getTradeStatusBadge, getWithdrawalStatusBadge, getLiquidationStatusBadge, getTargetTradeStatusBadge, } from './badgeSystem';
|
|
4
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/badge/index.ts"],"names":[],"mappings":"AACA,YAAY,EACV,YAAY,EACZ,SAAS,EACT,WAAW,EACX,UAAU,EACV,kBAAkB,GACnB,MAAM,+BAA+B,CAAC;AAGvC,YAAY,EACV,WAAW,EACX,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,eAAe,CAAC;AAGvB,OAAO,EACL,WAAW,EACX,mBAAmB,EACnB,wBAAwB,EACxB,yBAAyB,EACzB,yBAAyB,GAC1B,MAAM,eAAe,CAAC"}
|
package/dist/badge/index.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Formats a number as currency with commas and 2 decimal places
|
|
3
|
-
*/
|
|
4
|
-
export declare const formatCurrency: (value: number | string) => string;
|
|
5
|
-
/**
|
|
6
|
-
* Parses a currency string input into a number
|
|
7
|
-
* @param value - Currency string to parse
|
|
8
|
-
* @returns Parsed number value (or 0 if invalid)
|
|
9
|
-
*/
|
|
10
|
-
export declare const parseCurrencyInput: (value: string) => number;
|
|
11
|
-
/**
|
|
12
|
-
* Formats a number as currency with specific currency code and locale
|
|
13
|
-
* @param value - Number to format
|
|
14
|
-
* @param currencyCode - ISO 4217 currency code (default: DEFAULT_CURRENCY)
|
|
15
|
-
* @param locale - Locale for formatting (default: LOCALE_AUSTRALIA)
|
|
16
|
-
* @param minimumFractionDigits - Minimum decimal places (default: 0)
|
|
17
|
-
* @param maximumFractionDigits - Maximum decimal places (default: 0)
|
|
18
|
-
* @returns Formatted currency string
|
|
19
|
-
*/
|
|
20
|
-
export declare const formatCurrencyWithCode: (value: number, currencyCode?: string, locale?: string, minimumFractionDigits?: number, maximumFractionDigits?: number) => string;
|
|
21
|
-
/**
|
|
22
|
-
* Convenience function to format currency with the default currency (AUD)
|
|
23
|
-
* @param value - Number to format
|
|
24
|
-
* @param minimumFractionDigits - Minimum decimal places (default: 0)
|
|
25
|
-
* @param maximumFractionDigits - Maximum decimal places (default: 0)
|
|
26
|
-
* @returns Formatted currency string with default currency
|
|
27
|
-
*/
|
|
28
|
-
export declare const formatDefaultCurrency: (value: number, minimumFractionDigits?: number, maximumFractionDigits?: number) => string;
|
|
29
|
-
//# sourceMappingURL=currency.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"currency.d.ts","sourceRoot":"","sources":["../../src/formatters/currency.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,cAAc,GAAI,OAAO,MAAM,GAAG,MAAM,KAAG,MAWvD,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,GAAI,OAAO,MAAM,KAAG,MAOlD,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,sBAAsB,GACjC,OAAO,MAAM,EACb,eAAc,MAAyB,EACvC,SAAQ,MAAyB,EACjC,wBAAuB,MAAU,EACjC,wBAAuB,MAAU,KAChC,MASF,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB,GAChC,OAAO,MAAM,EACb,wBAAuB,MAAU,EACjC,wBAAuB,MAAU,KAChC,MAEF,CAAC"}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { DEFAULT_CURRENCY, LOCALE_AUSTRALIA } from '@cranberry-money/shared-constants';
|
|
2
|
-
/**
|
|
3
|
-
* Formats a number as currency with commas and 2 decimal places
|
|
4
|
-
*/
|
|
5
|
-
export const formatCurrency = (value) => {
|
|
6
|
-
if (!value && value !== 0)
|
|
7
|
-
return '';
|
|
8
|
-
const numValue = typeof value === 'string' ? parseFloat(value) : value;
|
|
9
|
-
if (isNaN(numValue))
|
|
10
|
-
return '';
|
|
11
|
-
return numValue.toLocaleString(LOCALE_AUSTRALIA, {
|
|
12
|
-
minimumFractionDigits: 2,
|
|
13
|
-
maximumFractionDigits: 2,
|
|
14
|
-
});
|
|
15
|
-
};
|
|
16
|
-
/**
|
|
17
|
-
* Parses a currency string input into a number
|
|
18
|
-
* @param value - Currency string to parse
|
|
19
|
-
* @returns Parsed number value (or 0 if invalid)
|
|
20
|
-
*/
|
|
21
|
-
export const parseCurrencyInput = (value) => {
|
|
22
|
-
const cleanValue = value.replace(/[^0-9.]/g, '');
|
|
23
|
-
const parts = cleanValue.split('.');
|
|
24
|
-
const formattedValue = parts[0] + (parts.length > 1 ? '.' + parts[1].slice(0, 2) : '');
|
|
25
|
-
return parseFloat(formattedValue) || 0;
|
|
26
|
-
};
|
|
27
|
-
/**
|
|
28
|
-
* Formats a number as currency with specific currency code and locale
|
|
29
|
-
* @param value - Number to format
|
|
30
|
-
* @param currencyCode - ISO 4217 currency code (default: DEFAULT_CURRENCY)
|
|
31
|
-
* @param locale - Locale for formatting (default: LOCALE_AUSTRALIA)
|
|
32
|
-
* @param minimumFractionDigits - Minimum decimal places (default: 0)
|
|
33
|
-
* @param maximumFractionDigits - Maximum decimal places (default: 0)
|
|
34
|
-
* @returns Formatted currency string
|
|
35
|
-
*/
|
|
36
|
-
export const formatCurrencyWithCode = (value, currencyCode = DEFAULT_CURRENCY, locale = LOCALE_AUSTRALIA, minimumFractionDigits = 0, maximumFractionDigits = 0) => {
|
|
37
|
-
if (value == null || isNaN(value))
|
|
38
|
-
return '';
|
|
39
|
-
return new Intl.NumberFormat(locale, {
|
|
40
|
-
style: 'currency',
|
|
41
|
-
currency: currencyCode,
|
|
42
|
-
minimumFractionDigits,
|
|
43
|
-
maximumFractionDigits,
|
|
44
|
-
}).format(value);
|
|
45
|
-
};
|
|
46
|
-
/**
|
|
47
|
-
* Convenience function to format currency with the default currency (AUD)
|
|
48
|
-
* @param value - Number to format
|
|
49
|
-
* @param minimumFractionDigits - Minimum decimal places (default: 0)
|
|
50
|
-
* @param maximumFractionDigits - Maximum decimal places (default: 0)
|
|
51
|
-
* @returns Formatted currency string with default currency
|
|
52
|
-
*/
|
|
53
|
-
export const formatDefaultCurrency = (value, minimumFractionDigits = 0, maximumFractionDigits = 0) => {
|
|
54
|
-
return formatCurrencyWithCode(value, DEFAULT_CURRENCY, LOCALE_AUSTRALIA, minimumFractionDigits, maximumFractionDigits);
|
|
55
|
-
};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Formats a date string to a localized date
|
|
3
|
-
* @param dateString - ISO date string or null
|
|
4
|
-
* @param fallback - Fallback text when date is null (default: 'No expiry')
|
|
5
|
-
* @returns Formatted date string
|
|
6
|
-
*/
|
|
7
|
-
export declare const formatDate: (dateString: string | null, fallback?: string) => string;
|
|
8
|
-
/**
|
|
9
|
-
* Formats a date string to a short date format (e.g., "Jan 15")
|
|
10
|
-
*/
|
|
11
|
-
export declare const formatShortDate: (dateString: string, locale?: string) => string;
|
|
12
|
-
/**
|
|
13
|
-
* Formats a date string to a time format (24-hour)
|
|
14
|
-
*/
|
|
15
|
-
export declare const formatTime: (dateString: string, locale?: string) => string;
|
|
16
|
-
/**
|
|
17
|
-
* Formats a date string to a combined short date and time format
|
|
18
|
-
* @param dateString - ISO date string
|
|
19
|
-
* @param locale - Locale for formatting (default: LOCALE_AUSTRALIA)
|
|
20
|
-
* @returns Formatted string like "Jan 15 14:30"
|
|
21
|
-
*/
|
|
22
|
-
export declare const formatDateTime: (dateString: string, locale?: string) => string;
|
|
23
|
-
//# sourceMappingURL=dates.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dates.d.ts","sourceRoot":"","sources":["../../src/formatters/dates.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,eAAO,MAAM,UAAU,GAAI,YAAY,MAAM,GAAG,IAAI,EAAE,WAAU,MAAoB,KAAG,MAGtF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,eAAe,GAAI,YAAY,MAAM,EAAE,SAAQ,MAAyB,KAAG,MAMvF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,UAAU,GAAI,YAAY,MAAM,EAAE,SAAQ,MAAyB,KAAG,MAMlF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,cAAc,GAAI,YAAY,MAAM,EAAE,SAAQ,MAAyB,KAAG,MAYtF,CAAC"}
|
package/dist/formatters/dates.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { LOCALE_AUSTRALIA } from '@cranberry-money/shared-constants';
|
|
2
|
-
/**
|
|
3
|
-
* Formats a date string to a localized date
|
|
4
|
-
* @param dateString - ISO date string or null
|
|
5
|
-
* @param fallback - Fallback text when date is null (default: 'No expiry')
|
|
6
|
-
* @returns Formatted date string
|
|
7
|
-
*/
|
|
8
|
-
export const formatDate = (dateString, fallback = 'No expiry') => {
|
|
9
|
-
if (!dateString)
|
|
10
|
-
return fallback;
|
|
11
|
-
return new Date(dateString).toLocaleDateString();
|
|
12
|
-
};
|
|
13
|
-
/**
|
|
14
|
-
* Formats a date string to a short date format (e.g., "Jan 15")
|
|
15
|
-
*/
|
|
16
|
-
export const formatShortDate = (dateString, locale = LOCALE_AUSTRALIA) => {
|
|
17
|
-
const date = new Date(dateString);
|
|
18
|
-
return date.toLocaleDateString(locale, {
|
|
19
|
-
month: 'short',
|
|
20
|
-
day: 'numeric',
|
|
21
|
-
});
|
|
22
|
-
};
|
|
23
|
-
/**
|
|
24
|
-
* Formats a date string to a time format (24-hour)
|
|
25
|
-
*/
|
|
26
|
-
export const formatTime = (dateString, locale = LOCALE_AUSTRALIA) => {
|
|
27
|
-
return new Date(dateString).toLocaleTimeString(locale, {
|
|
28
|
-
hour: '2-digit',
|
|
29
|
-
minute: '2-digit',
|
|
30
|
-
hour12: false,
|
|
31
|
-
});
|
|
32
|
-
};
|
|
33
|
-
/**
|
|
34
|
-
* Formats a date string to a combined short date and time format
|
|
35
|
-
* @param dateString - ISO date string
|
|
36
|
-
* @param locale - Locale for formatting (default: LOCALE_AUSTRALIA)
|
|
37
|
-
* @returns Formatted string like "Jan 15 14:30"
|
|
38
|
-
*/
|
|
39
|
-
export const formatDateTime = (dateString, locale = LOCALE_AUSTRALIA) => {
|
|
40
|
-
const date = new Date(dateString);
|
|
41
|
-
const shortDate = date.toLocaleDateString(locale, {
|
|
42
|
-
month: 'short',
|
|
43
|
-
day: 'numeric',
|
|
44
|
-
});
|
|
45
|
-
const time = date.toLocaleTimeString(locale, {
|
|
46
|
-
hour: '2-digit',
|
|
47
|
-
minute: '2-digit',
|
|
48
|
-
hour12: false,
|
|
49
|
-
});
|
|
50
|
-
return `${shortDate} ${time}`;
|
|
51
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/formatters/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC"}
|
package/dist/formatters/index.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Formats a number for displaying share quantities (no decimals)
|
|
3
|
-
* @param shares - Number of shares to format
|
|
4
|
-
* @param locale - Locale for formatting (default: LOCALE_AUSTRALIA)
|
|
5
|
-
* @returns Formatted shares string with commas as thousands separators
|
|
6
|
-
*/
|
|
7
|
-
export declare const formatShares: (shares: number, locale?: string) => string;
|
|
8
|
-
//# sourceMappingURL=numbers.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"numbers.d.ts","sourceRoot":"","sources":["../../src/formatters/numbers.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,eAAO,MAAM,YAAY,GAAI,QAAQ,MAAM,EAAE,SAAQ,MAAyB,KAAG,MAKhF,CAAC"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { LOCALE_AUSTRALIA } from '@cranberry-money/shared-constants';
|
|
2
|
-
/**
|
|
3
|
-
* Formats a number for displaying share quantities (no decimals)
|
|
4
|
-
* @param shares - Number of shares to format
|
|
5
|
-
* @param locale - Locale for formatting (default: LOCALE_AUSTRALIA)
|
|
6
|
-
* @returns Formatted shares string with commas as thousands separators
|
|
7
|
-
*/
|
|
8
|
-
export const formatShares = (shares, locale = LOCALE_AUSTRALIA) => {
|
|
9
|
-
return new Intl.NumberFormat(locale, {
|
|
10
|
-
minimumFractionDigits: 0,
|
|
11
|
-
maximumFractionDigits: 0,
|
|
12
|
-
}).format(shares);
|
|
13
|
-
};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared utility functions for trading filter operations
|
|
3
|
-
* Addresses filter utility logic duplications across trading pages
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Generic function to check if any filters are active
|
|
7
|
-
* Replaces hasActiveTradeFilters, hasActiveTransactionFilters, hasActiveInstrumentFilters
|
|
8
|
-
*/
|
|
9
|
-
export declare function hasActiveFilters<T extends Record<string, unknown>>(filters: T, excludeFields?: (keyof T)[]): boolean;
|
|
10
|
-
/**
|
|
11
|
-
* Generic function to count active filters
|
|
12
|
-
* Replaces countActiveTradeFilters, countActiveTransactionFilters, countActiveInstrumentFilters
|
|
13
|
-
*/
|
|
14
|
-
export declare function countActiveFilters<T extends Record<string, unknown>>(filters: T, excludeFields?: (keyof T)[]): number;
|
|
15
|
-
/**
|
|
16
|
-
* Generic function to clear all filters
|
|
17
|
-
* Maintains type safety while resetting filter state
|
|
18
|
-
*/
|
|
19
|
-
export declare function clearAllFilters<T extends Record<string, unknown>>(filters: T, preserveFields?: (keyof T)[]): Partial<T>;
|
|
20
|
-
/**
|
|
21
|
-
* Type-safe filter update helper
|
|
22
|
-
* Ensures only valid filter fields can be updated
|
|
23
|
-
*/
|
|
24
|
-
export declare function updateFilters<T extends Record<string, unknown>>(currentFilters: T, updates: Partial<T>): T;
|
|
25
|
-
//# sourceMappingURL=filters.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"filters.d.ts","sourceRoot":"","sources":["../../src/helpers/filters.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChE,OAAO,EAAE,CAAC,EACV,aAAa,GAAE,CAAC,MAAM,CAAC,CAAC,EAAoB,GAC3C,OAAO,CAOT;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAClE,OAAO,EAAE,CAAC,EACV,aAAa,GAAE,CAAC,MAAM,CAAC,CAAC,EAAoB,GAC3C,MAAM,CAOR;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/D,OAAO,EAAE,CAAC,EACV,cAAc,GAAE,CAAC,MAAM,CAAC,CAAC,EAAO,GAC/B,OAAO,CAAC,CAAC,CAAC,CAWZ;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,EAAE,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAE1G"}
|
package/dist/helpers/filters.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared utility functions for trading filter operations
|
|
3
|
-
* Addresses filter utility logic duplications across trading pages
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Generic function to check if any filters are active
|
|
7
|
-
* Replaces hasActiveTradeFilters, hasActiveTransactionFilters, hasActiveInstrumentFilters
|
|
8
|
-
*/
|
|
9
|
-
export function hasActiveFilters(filters, excludeFields = ['searchQuery']) {
|
|
10
|
-
const relevantEntries = Object.entries(filters).filter(([key]) => !excludeFields.includes(key));
|
|
11
|
-
return relevantEntries.some(([, value]) => value !== undefined && value !== null && value !== '' && !(Array.isArray(value) && value.length === 0));
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Generic function to count active filters
|
|
15
|
-
* Replaces countActiveTradeFilters, countActiveTransactionFilters, countActiveInstrumentFilters
|
|
16
|
-
*/
|
|
17
|
-
export function countActiveFilters(filters, excludeFields = ['searchQuery']) {
|
|
18
|
-
const relevantEntries = Object.entries(filters).filter(([key]) => !excludeFields.includes(key));
|
|
19
|
-
return relevantEntries.filter(([, value]) => value !== undefined && value !== null && value !== '' && !(Array.isArray(value) && value.length === 0)).length;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Generic function to clear all filters
|
|
23
|
-
* Maintains type safety while resetting filter state
|
|
24
|
-
*/
|
|
25
|
-
export function clearAllFilters(filters, preserveFields = []) {
|
|
26
|
-
const clearedFilters = {};
|
|
27
|
-
// Preserve specified fields
|
|
28
|
-
preserveFields.forEach((field) => {
|
|
29
|
-
if (field in filters) {
|
|
30
|
-
clearedFilters[field] = filters[field];
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
return clearedFilters;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Type-safe filter update helper
|
|
37
|
-
* Ensures only valid filter fields can be updated
|
|
38
|
-
*/
|
|
39
|
-
export function updateFilters(currentFilters, updates) {
|
|
40
|
-
return { ...currentFilters, ...updates };
|
|
41
|
-
}
|
package/dist/helpers/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,aAAa,CAAC"}
|
package/dist/helpers/index.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Portfolio-related helper functions
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Calculate total portfolio value
|
|
6
|
-
*/
|
|
7
|
-
export declare const calculateTotalValue: (marketValue: number, cashBalance: number) => number;
|
|
8
|
-
/**
|
|
9
|
-
* Calculate market allocation percentage
|
|
10
|
-
*/
|
|
11
|
-
export declare const getMarketAllocation: (marketValue: number, totalValue: number) => number;
|
|
12
|
-
/**
|
|
13
|
-
* Calculate cash allocation percentage
|
|
14
|
-
*/
|
|
15
|
-
export declare const getCashAllocation: (cashBalance: number, totalValue: number) => number;
|
|
16
|
-
/**
|
|
17
|
-
* Format portfolio value with default currency
|
|
18
|
-
*/
|
|
19
|
-
export declare const formatPortfolioValue: (value: number) => string;
|
|
20
|
-
//# sourceMappingURL=portfolio.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"portfolio.d.ts","sourceRoot":"","sources":["../../src/helpers/portfolio.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;GAEG;AACH,eAAO,MAAM,mBAAmB,GAAI,aAAa,MAAM,EAAE,aAAa,MAAM,KAAG,MAE9E,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,mBAAmB,GAAI,aAAa,MAAM,EAAE,YAAY,MAAM,KAAG,MAE7E,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,iBAAiB,GAAI,aAAa,MAAM,EAAE,YAAY,MAAM,KAAG,MAE3E,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,oBAAoB,GAAI,OAAO,MAAM,KAAG,MAEpD,CAAC"}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Portfolio-related helper functions
|
|
3
|
-
*/
|
|
4
|
-
import { formatCurrency } from '../formatters/currency';
|
|
5
|
-
/**
|
|
6
|
-
* Calculate total portfolio value
|
|
7
|
-
*/
|
|
8
|
-
export const calculateTotalValue = (marketValue, cashBalance) => {
|
|
9
|
-
return marketValue + cashBalance;
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* Calculate market allocation percentage
|
|
13
|
-
*/
|
|
14
|
-
export const getMarketAllocation = (marketValue, totalValue) => {
|
|
15
|
-
return totalValue > 0 ? (marketValue / totalValue) * 100 : 0;
|
|
16
|
-
};
|
|
17
|
-
/**
|
|
18
|
-
* Calculate cash allocation percentage
|
|
19
|
-
*/
|
|
20
|
-
export const getCashAllocation = (cashBalance, totalValue) => {
|
|
21
|
-
return totalValue > 0 ? (cashBalance / totalValue) * 100 : 0;
|
|
22
|
-
};
|
|
23
|
-
/**
|
|
24
|
-
* Format portfolio value with default currency
|
|
25
|
-
*/
|
|
26
|
-
export const formatPortfolioValue = (value) => {
|
|
27
|
-
return formatCurrency(value);
|
|
28
|
-
};
|
package/dist/helpers/text.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Truncates text to a specified maximum length and adds ellipsis if needed
|
|
3
|
-
* @param text - The text to truncate
|
|
4
|
-
* @param maxLength - The maximum length of the text (default: 30)
|
|
5
|
-
* @returns The truncated text with ellipsis if it exceeds maxLength
|
|
6
|
-
*/
|
|
7
|
-
export declare const truncateText: (text: string, maxLength?: number) => string;
|
|
8
|
-
//# sourceMappingURL=text.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../../src/helpers/text.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,eAAO,MAAM,YAAY,GAAI,MAAM,MAAM,EAAE,YAAW,MAAW,KAAG,MAGnE,CAAC"}
|
package/dist/helpers/text.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Truncates text to a specified maximum length and adds ellipsis if needed
|
|
3
|
-
* @param text - The text to truncate
|
|
4
|
-
* @param maxLength - The maximum length of the text (default: 30)
|
|
5
|
-
* @returns The truncated text with ellipsis if it exceeds maxLength
|
|
6
|
-
*/
|
|
7
|
-
export const truncateText = (text, maxLength = 30) => {
|
|
8
|
-
if (text.length <= maxLength)
|
|
9
|
-
return text;
|
|
10
|
-
return `${text.substring(0, maxLength)}...`;
|
|
11
|
-
};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Portfolio utility functions
|
|
3
|
-
* Calculations and processing for portfolio data
|
|
4
|
-
*/
|
|
5
|
-
import type { PortfolioServices } from '@cranberry-money/shared-services';
|
|
6
|
-
/**
|
|
7
|
-
* Calculate the actual percentage allocations based on holdings
|
|
8
|
-
* Returns a map of instrument UUID to percentage
|
|
9
|
-
*/
|
|
10
|
-
export declare const calculateHoldingAllocations: (holdings: PortfolioServices.AssetHolding[]) => Record<string, number>;
|
|
11
|
-
/**
|
|
12
|
-
* Format quantity for display
|
|
13
|
-
* Handles fractional shares and whole numbers appropriately
|
|
14
|
-
*/
|
|
15
|
-
export declare const formatQuantity: (quantity?: number) => string;
|
|
16
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/portfolio/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAE1E;;;GAGG;AACH,eAAO,MAAM,2BAA2B,GAAI,UAAU,iBAAiB,CAAC,YAAY,EAAE,KAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAwB7G,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,cAAc,GAAI,WAAW,MAAM,KAAG,MAWlD,CAAC"}
|
package/dist/portfolio/index.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Portfolio utility functions
|
|
3
|
-
* Calculations and processing for portfolio data
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Calculate the actual percentage allocations based on holdings
|
|
7
|
-
* Returns a map of instrument UUID to percentage
|
|
8
|
-
*/
|
|
9
|
-
export const calculateHoldingAllocations = (holdings) => {
|
|
10
|
-
// Calculate total portfolio value
|
|
11
|
-
const totalValue = holdings.reduce((sum, holding) => {
|
|
12
|
-
const price = parseFloat(holding.instrument.currentPrice || '0');
|
|
13
|
-
const value = holding.quantity * price;
|
|
14
|
-
return sum + value;
|
|
15
|
-
}, 0);
|
|
16
|
-
// If no value, return empty allocations
|
|
17
|
-
if (totalValue === 0) {
|
|
18
|
-
return {};
|
|
19
|
-
}
|
|
20
|
-
// Calculate percentage for each holding
|
|
21
|
-
const allocations = {};
|
|
22
|
-
holdings.forEach((holding) => {
|
|
23
|
-
const price = parseFloat(holding.instrument.currentPrice || '0');
|
|
24
|
-
const value = holding.quantity * price;
|
|
25
|
-
const percentage = (value / totalValue) * 100;
|
|
26
|
-
allocations[holding.instrument.uuid] = percentage;
|
|
27
|
-
});
|
|
28
|
-
return allocations;
|
|
29
|
-
};
|
|
30
|
-
/**
|
|
31
|
-
* Format quantity for display
|
|
32
|
-
* Handles fractional shares and whole numbers appropriately
|
|
33
|
-
*/
|
|
34
|
-
export const formatQuantity = (quantity) => {
|
|
35
|
-
if (quantity === undefined || quantity === null)
|
|
36
|
-
return '0';
|
|
37
|
-
// For whole numbers, show without decimals
|
|
38
|
-
if (Number.isInteger(quantity)) {
|
|
39
|
-
return quantity.toString();
|
|
40
|
-
}
|
|
41
|
-
// For fractional shares, show up to 6 decimal places
|
|
42
|
-
// Remove trailing zeros
|
|
43
|
-
return quantity.toFixed(6).replace(/\.?0+$/, '');
|
|
44
|
-
};
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Validation utility functions
|
|
3
|
-
* Common validation logic for forms and data
|
|
4
|
-
*/
|
|
5
|
-
import type { PasswordValidation, TokenValidation } from '@cranberry-money/shared-types';
|
|
6
|
-
/**
|
|
7
|
-
* Checks if a string contains only numeric characters
|
|
8
|
-
* @param str - The string to validate
|
|
9
|
-
* @returns true if the string contains only digits, false otherwise
|
|
10
|
-
*/
|
|
11
|
-
export declare const isNumericOnly: (str: string) => boolean;
|
|
12
|
-
/**
|
|
13
|
-
* Validates password strength based on application requirements
|
|
14
|
-
* @param password - The password to validate
|
|
15
|
-
* @returns An object containing validation results
|
|
16
|
-
*/
|
|
17
|
-
export declare const validatePassword: (password: string) => PasswordValidation;
|
|
18
|
-
/**
|
|
19
|
-
* Validates if a verification token is in the expected format
|
|
20
|
-
* @param token - The verification token to validate
|
|
21
|
-
* @returns true if token appears to be valid format, false otherwise
|
|
22
|
-
*/
|
|
23
|
-
export declare const isValidTokenFormat: (token: string) => boolean;
|
|
24
|
-
/**
|
|
25
|
-
* Formats a verification token by removing whitespace and converting to uppercase
|
|
26
|
-
* @param token - The token to format
|
|
27
|
-
* @returns The formatted token
|
|
28
|
-
*/
|
|
29
|
-
export declare const formatVerificationToken: (token: string) => string;
|
|
30
|
-
/**
|
|
31
|
-
* Validates email confirmation form data
|
|
32
|
-
* @param token - The verification token
|
|
33
|
-
* @returns An object containing validation results
|
|
34
|
-
*/
|
|
35
|
-
export declare const validateEmailConfirmation: (token: string) => TokenValidation;
|
|
36
|
-
/**
|
|
37
|
-
* Validates email format
|
|
38
|
-
* @param email - The email to validate
|
|
39
|
-
* @returns true if email format is valid
|
|
40
|
-
*/
|
|
41
|
-
export declare const isValidEmail: (email: string) => boolean;
|
|
42
|
-
/**
|
|
43
|
-
* Validates phone number format (basic validation)
|
|
44
|
-
* @param phone - The phone number to validate
|
|
45
|
-
* @returns true if phone format is valid
|
|
46
|
-
*/
|
|
47
|
-
export declare const isValidPhone: (phone: string) => boolean;
|
|
48
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/validation/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAGzF;;;;GAIG;AACH,eAAO,MAAM,aAAa,GAAI,KAAK,MAAM,KAAG,OAE3C,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,GAAI,UAAU,MAAM,KAAG,kBAKnD,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,GAAI,OAAO,MAAM,KAAG,OAQlD,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,GAAI,OAAO,MAAM,KAAG,MAEvD,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,GAAI,OAAO,MAAM,KAAG,eAQzD,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,YAAY,GAAI,OAAO,MAAM,KAAG,OAG5C,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,YAAY,GAAI,OAAO,MAAM,KAAG,OAK5C,CAAC"}
|
package/dist/validation/index.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Validation utility functions
|
|
3
|
-
* Common validation logic for forms and data
|
|
4
|
-
*/
|
|
5
|
-
import { PASSWORD_MIN_LENGTH, TOKEN_MIN_LENGTH, TOKEN_MAX_LENGTH } from '@cranberry-money/shared-constants';
|
|
6
|
-
/**
|
|
7
|
-
* Checks if a string contains only numeric characters
|
|
8
|
-
* @param str - The string to validate
|
|
9
|
-
* @returns true if the string contains only digits, false otherwise
|
|
10
|
-
*/
|
|
11
|
-
export const isNumericOnly = (str) => {
|
|
12
|
-
return /^\d+$/.test(str);
|
|
13
|
-
};
|
|
14
|
-
/**
|
|
15
|
-
* Validates password strength based on application requirements
|
|
16
|
-
* @param password - The password to validate
|
|
17
|
-
* @returns An object containing validation results
|
|
18
|
-
*/
|
|
19
|
-
export const validatePassword = (password) => {
|
|
20
|
-
return {
|
|
21
|
-
lengthValid: password.length >= PASSWORD_MIN_LENGTH,
|
|
22
|
-
notNumeric: !isNumericOnly(password),
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
/**
|
|
26
|
-
* Validates if a verification token is in the expected format
|
|
27
|
-
* @param token - The verification token to validate
|
|
28
|
-
* @returns true if token appears to be valid format, false otherwise
|
|
29
|
-
*/
|
|
30
|
-
export const isValidTokenFormat = (token) => {
|
|
31
|
-
const trimmedToken = token.trim();
|
|
32
|
-
// Tokens are alphanumeric and within length limits
|
|
33
|
-
return (trimmedToken.length >= TOKEN_MIN_LENGTH &&
|
|
34
|
-
trimmedToken.length <= TOKEN_MAX_LENGTH &&
|
|
35
|
-
/^[a-zA-Z0-9]+$/.test(trimmedToken));
|
|
36
|
-
};
|
|
37
|
-
/**
|
|
38
|
-
* Formats a verification token by removing whitespace and converting to uppercase
|
|
39
|
-
* @param token - The token to format
|
|
40
|
-
* @returns The formatted token
|
|
41
|
-
*/
|
|
42
|
-
export const formatVerificationToken = (token) => {
|
|
43
|
-
return token.trim().toUpperCase();
|
|
44
|
-
};
|
|
45
|
-
/**
|
|
46
|
-
* Validates email confirmation form data
|
|
47
|
-
* @param token - The verification token
|
|
48
|
-
* @returns An object containing validation results
|
|
49
|
-
*/
|
|
50
|
-
export const validateEmailConfirmation = (token) => {
|
|
51
|
-
const formattedToken = formatVerificationToken(token);
|
|
52
|
-
return {
|
|
53
|
-
isValid: formattedToken.length > 0 && isValidTokenFormat(formattedToken),
|
|
54
|
-
isEmpty: formattedToken.length === 0,
|
|
55
|
-
isValidFormat: isValidTokenFormat(formattedToken),
|
|
56
|
-
};
|
|
57
|
-
};
|
|
58
|
-
/**
|
|
59
|
-
* Validates email format
|
|
60
|
-
* @param email - The email to validate
|
|
61
|
-
* @returns true if email format is valid
|
|
62
|
-
*/
|
|
63
|
-
export const isValidEmail = (email) => {
|
|
64
|
-
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
65
|
-
return emailRegex.test(email);
|
|
66
|
-
};
|
|
67
|
-
/**
|
|
68
|
-
* Validates phone number format (basic validation)
|
|
69
|
-
* @param phone - The phone number to validate
|
|
70
|
-
* @returns true if phone format is valid
|
|
71
|
-
*/
|
|
72
|
-
export const isValidPhone = (phone) => {
|
|
73
|
-
// Remove common formatting characters
|
|
74
|
-
const cleaned = phone.replace(/[\s\-\(\)]/g, '');
|
|
75
|
-
// Check if it's numeric and reasonable length
|
|
76
|
-
return /^\+?\d{10,15}$/.test(cleaned);
|
|
77
|
-
};
|