@cranberry-money/shared-utils 5.0.1 → 8.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auth.d.ts +55 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +135 -0
- package/dist/badge-status.d.ts +65 -0
- package/dist/badge-status.d.ts.map +1 -0
- package/dist/badge-status.js +170 -0
- package/dist/badge.d.ts +41 -0
- package/dist/badge.d.ts.map +1 -0
- package/dist/badge.js +72 -0
- package/dist/collections.d.ts +81 -0
- package/dist/collections.d.ts.map +1 -0
- package/dist/collections.js +127 -0
- package/dist/currency.d.ts +99 -0
- package/dist/currency.d.ts.map +1 -0
- package/dist/currency.js +128 -0
- package/dist/date.d.ts.map +1 -0
- package/dist/date.js +91 -0
- package/dist/downloads.d.ts +46 -0
- package/dist/downloads.d.ts.map +1 -0
- package/dist/downloads.js +91 -0
- package/dist/filters.d.ts +121 -0
- package/dist/filters.d.ts.map +1 -0
- package/dist/filters.js +206 -0
- package/dist/formatting.d.ts +59 -0
- package/dist/formatting.d.ts.map +1 -0
- package/dist/formatting.js +81 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +40 -0
- package/dist/instruments.d.ts +66 -0
- package/dist/instruments.d.ts.map +1 -0
- package/dist/instruments.js +135 -0
- package/dist/numbers.d.ts +72 -0
- package/dist/numbers.d.ts.map +1 -0
- package/dist/numbers.js +101 -0
- package/dist/portfolio.d.ts +68 -0
- package/dist/portfolio.d.ts.map +1 -0
- package/dist/portfolio.js +87 -0
- package/dist/text.d.ts.map +1 -0
- package/dist/text.js +25 -0
- package/dist/validation.d.ts +226 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +337 -0
- package/dist/withdrawal.d.ts +87 -0
- package/dist/withdrawal.d.ts.map +1 -0
- package/dist/withdrawal.js +119 -0
- package/package.json +4 -4
package/dist/auth.d.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Authentication and token management utilities
|
|
3
|
+
*/
|
|
4
|
+
import type { DeviceInfo, TokenRefreshResponse, TokenRefreshError, AutoRefreshHandler } from '@cranberry-money/shared-types';
|
|
5
|
+
/**
|
|
6
|
+
* Check if a token has expired based on its expiration timestamp
|
|
7
|
+
* @param expiresAt - The expiration timestamp
|
|
8
|
+
* @returns true if token is expired, false otherwise
|
|
9
|
+
*/
|
|
10
|
+
export declare function isTokenExpired(expiresAt: string): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Check if a token will expire within a specified number of minutes
|
|
13
|
+
* @param expiresAt - The expiration timestamp
|
|
14
|
+
* @param minutesBeforeExpiry - Minutes before expiry to consider as "expiring soon"
|
|
15
|
+
* @returns true if token is expiring soon, false otherwise
|
|
16
|
+
*/
|
|
17
|
+
export declare function isTokenExpiringSoon(expiresAt: string, minutesBeforeExpiry?: number): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Get the remaining time until token expiry in minutes
|
|
20
|
+
* @param expiresAt - The expiration timestamp
|
|
21
|
+
* @returns Number of minutes until expiry
|
|
22
|
+
*/
|
|
23
|
+
export declare function getTimeUntilExpiry(expiresAt: string): number;
|
|
24
|
+
/**
|
|
25
|
+
* Format the time until expiry in a human-readable format
|
|
26
|
+
* @param expiresAt - The expiration timestamp
|
|
27
|
+
* @returns Formatted time string
|
|
28
|
+
*/
|
|
29
|
+
export declare function formatTimeUntilExpiry(expiresAt: string): string;
|
|
30
|
+
/**
|
|
31
|
+
* Parse device information from user agent string
|
|
32
|
+
* @param userAgent - The user agent string
|
|
33
|
+
* @returns Parsed device info
|
|
34
|
+
*/
|
|
35
|
+
export declare function parseDeviceInfo(userAgent: string): DeviceInfo;
|
|
36
|
+
/**
|
|
37
|
+
* Check if token refresh was successful
|
|
38
|
+
* @param response - The refresh response
|
|
39
|
+
* @returns true if refresh was successful, false otherwise
|
|
40
|
+
*/
|
|
41
|
+
export declare function isRefreshSuccess(response: TokenRefreshResponse): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Get error message from token refresh error
|
|
44
|
+
* @param error - The refresh error
|
|
45
|
+
* @returns Error message string
|
|
46
|
+
*/
|
|
47
|
+
export declare function getRefreshErrorMessage(error: TokenRefreshError): string;
|
|
48
|
+
/**
|
|
49
|
+
* Create an auto-refresh handler for tokens
|
|
50
|
+
* @param refreshCallback - Callback function to refresh token
|
|
51
|
+
* @param checkInterval - Interval in milliseconds to check for refresh
|
|
52
|
+
* @returns Auto refresh handler with start/stop methods
|
|
53
|
+
*/
|
|
54
|
+
export declare function createAutoRefreshHandler(refreshCallback: () => Promise<void>, checkInterval?: number): AutoRefreshHandler;
|
|
55
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EACV,UAAU,EACV,oBAAoB,EACpB,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,+BAA+B,CAAC;AAkBvC;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAIzD;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,SAAS,EAAE,MAAM,EACjB,mBAAmB,GAAE,MAA6C,GACjE,OAAO,CAMT;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAU5D;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAkB/D;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,UAAU,CAwB7D;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,oBAAoB,GAAG,OAAO,CAExE;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,iBAAiB,GAAG,MAAM,CAWvE;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACtC,eAAe,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,EACpC,aAAa,GAAE,MAAc,GAC5B,kBAAkB,CAiBpB"}
|
package/dist/auth.js
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Authentication and token management utilities
|
|
3
|
+
*/
|
|
4
|
+
import { DEFAULT_TOKEN_REFRESH_BUFFER_MINUTES, MILLISECONDS_PER_MINUTE, MINUTES_PER_HOUR, HOURS_PER_DAY, TIME_LABEL_EXPIRED, TIME_LABEL_MINUTE, TIME_LABEL_MINUTES, TIME_LABEL_HOUR, TIME_LABEL_HOURS, TIME_LABEL_DAY, TIME_LABEL_DAYS, DEFAULT_UNKNOWN_VALUE, DEFAULT_ERROR_MESSAGE, } from '@cranberry-money/shared-constants';
|
|
5
|
+
/**
|
|
6
|
+
* Check if a token has expired based on its expiration timestamp
|
|
7
|
+
* @param expiresAt - The expiration timestamp
|
|
8
|
+
* @returns true if token is expired, false otherwise
|
|
9
|
+
*/
|
|
10
|
+
export function isTokenExpired(expiresAt) {
|
|
11
|
+
const expirationTime = new Date(expiresAt).getTime();
|
|
12
|
+
const currentTime = Date.now();
|
|
13
|
+
return currentTime >= expirationTime;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Check if a token will expire within a specified number of minutes
|
|
17
|
+
* @param expiresAt - The expiration timestamp
|
|
18
|
+
* @param minutesBeforeExpiry - Minutes before expiry to consider as "expiring soon"
|
|
19
|
+
* @returns true if token is expiring soon, false otherwise
|
|
20
|
+
*/
|
|
21
|
+
export function isTokenExpiringSoon(expiresAt, minutesBeforeExpiry = DEFAULT_TOKEN_REFRESH_BUFFER_MINUTES) {
|
|
22
|
+
const expirationTime = new Date(expiresAt).getTime();
|
|
23
|
+
const currentTime = Date.now();
|
|
24
|
+
const bufferTime = minutesBeforeExpiry * MILLISECONDS_PER_MINUTE;
|
|
25
|
+
return currentTime + bufferTime >= expirationTime;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Get the remaining time until token expiry in minutes
|
|
29
|
+
* @param expiresAt - The expiration timestamp
|
|
30
|
+
* @returns Number of minutes until expiry
|
|
31
|
+
*/
|
|
32
|
+
export function getTimeUntilExpiry(expiresAt) {
|
|
33
|
+
const expirationTime = new Date(expiresAt).getTime();
|
|
34
|
+
const currentTime = Date.now();
|
|
35
|
+
const remainingTime = expirationTime - currentTime;
|
|
36
|
+
if (remainingTime <= 0) {
|
|
37
|
+
return 0;
|
|
38
|
+
}
|
|
39
|
+
return Math.floor(remainingTime / MILLISECONDS_PER_MINUTE);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Format the time until expiry in a human-readable format
|
|
43
|
+
* @param expiresAt - The expiration timestamp
|
|
44
|
+
* @returns Formatted time string
|
|
45
|
+
*/
|
|
46
|
+
export function formatTimeUntilExpiry(expiresAt) {
|
|
47
|
+
const minutesRemaining = getTimeUntilExpiry(expiresAt);
|
|
48
|
+
if (minutesRemaining <= 0) {
|
|
49
|
+
return TIME_LABEL_EXPIRED;
|
|
50
|
+
}
|
|
51
|
+
if (minutesRemaining < MINUTES_PER_HOUR) {
|
|
52
|
+
return minutesRemaining === 1 ? `1 ${TIME_LABEL_MINUTE}` : `${minutesRemaining} ${TIME_LABEL_MINUTES}`;
|
|
53
|
+
}
|
|
54
|
+
const hoursRemaining = Math.floor(minutesRemaining / MINUTES_PER_HOUR);
|
|
55
|
+
if (hoursRemaining < HOURS_PER_DAY) {
|
|
56
|
+
return hoursRemaining === 1 ? `1 ${TIME_LABEL_HOUR}` : `${hoursRemaining} ${TIME_LABEL_HOURS}`;
|
|
57
|
+
}
|
|
58
|
+
const daysRemaining = Math.floor(hoursRemaining / HOURS_PER_DAY);
|
|
59
|
+
return daysRemaining === 1 ? `1 ${TIME_LABEL_DAY}` : `${daysRemaining} ${TIME_LABEL_DAYS}`;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Parse device information from user agent string
|
|
63
|
+
* @param userAgent - The user agent string
|
|
64
|
+
* @returns Parsed device info
|
|
65
|
+
*/
|
|
66
|
+
export function parseDeviceInfo(userAgent) {
|
|
67
|
+
const browser = userAgent.includes('Chrome')
|
|
68
|
+
? 'Chrome'
|
|
69
|
+
: userAgent.includes('Firefox')
|
|
70
|
+
? 'Firefox'
|
|
71
|
+
: userAgent.includes('Safari')
|
|
72
|
+
? 'Safari'
|
|
73
|
+
: userAgent.includes('Edge')
|
|
74
|
+
? 'Edge'
|
|
75
|
+
: DEFAULT_UNKNOWN_VALUE;
|
|
76
|
+
const os = userAgent.includes('Windows')
|
|
77
|
+
? 'Windows'
|
|
78
|
+
: userAgent.includes('Mac')
|
|
79
|
+
? 'macOS'
|
|
80
|
+
: userAgent.includes('Linux')
|
|
81
|
+
? 'Linux'
|
|
82
|
+
: userAgent.includes('Android')
|
|
83
|
+
? 'Android'
|
|
84
|
+
: userAgent.includes('iOS')
|
|
85
|
+
? 'iOS'
|
|
86
|
+
: DEFAULT_UNKNOWN_VALUE;
|
|
87
|
+
return { browser, os };
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Check if token refresh was successful
|
|
91
|
+
* @param response - The refresh response
|
|
92
|
+
* @returns true if refresh was successful, false otherwise
|
|
93
|
+
*/
|
|
94
|
+
export function isRefreshSuccess(response) {
|
|
95
|
+
return !!(response?.status === 200 && response?.data?.access && response?.data?.refresh);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Get error message from token refresh error
|
|
99
|
+
* @param error - The refresh error
|
|
100
|
+
* @returns Error message string
|
|
101
|
+
*/
|
|
102
|
+
export function getRefreshErrorMessage(error) {
|
|
103
|
+
if (error.response?.data?.detail) {
|
|
104
|
+
return error.response.data.detail;
|
|
105
|
+
}
|
|
106
|
+
if (error.response?.data?.message) {
|
|
107
|
+
return error.response.data.message;
|
|
108
|
+
}
|
|
109
|
+
if (error.message) {
|
|
110
|
+
return error.message;
|
|
111
|
+
}
|
|
112
|
+
return DEFAULT_ERROR_MESSAGE;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Create an auto-refresh handler for tokens
|
|
116
|
+
* @param refreshCallback - Callback function to refresh token
|
|
117
|
+
* @param checkInterval - Interval in milliseconds to check for refresh
|
|
118
|
+
* @returns Auto refresh handler with start/stop methods
|
|
119
|
+
*/
|
|
120
|
+
export function createAutoRefreshHandler(refreshCallback, checkInterval = 60000 // 1 minute
|
|
121
|
+
) {
|
|
122
|
+
let intervalId = null;
|
|
123
|
+
const start = () => {
|
|
124
|
+
if (intervalId)
|
|
125
|
+
return;
|
|
126
|
+
intervalId = setInterval(refreshCallback, checkInterval);
|
|
127
|
+
};
|
|
128
|
+
const stop = () => {
|
|
129
|
+
if (intervalId) {
|
|
130
|
+
clearInterval(intervalId);
|
|
131
|
+
intervalId = null;
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
return { start, stop };
|
|
135
|
+
}
|
|
@@ -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 MyPortfolio 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,170 @@
|
|
|
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 MyPortfolio 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
|
+
}
|
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,72 @@
|
|
|
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;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic collection and array utilities
|
|
3
|
+
* Pure functions for common array operations with type safety
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Sort array of objects by a string field
|
|
7
|
+
* @param items - Array of objects to sort
|
|
8
|
+
* @param fieldName - Name of the field to sort by
|
|
9
|
+
* @returns New sorted array
|
|
10
|
+
*/
|
|
11
|
+
export declare function sortByStringField<T>(items: T[], fieldName: keyof T): T[];
|
|
12
|
+
/**
|
|
13
|
+
* Filter array by text search in a specific field (case-insensitive)
|
|
14
|
+
* @param items - Array of objects to filter
|
|
15
|
+
* @param fieldName - Name of the field to search in
|
|
16
|
+
* @param searchTerm - Search term
|
|
17
|
+
* @returns Filtered array
|
|
18
|
+
*/
|
|
19
|
+
export declare function filterByTextSearch<T>(items: T[], fieldName: keyof T, searchTerm: string): T[];
|
|
20
|
+
/**
|
|
21
|
+
* Filter array by boolean field
|
|
22
|
+
* @param items - Array of objects to filter
|
|
23
|
+
* @param fieldName - Name of the boolean field
|
|
24
|
+
* @param value - Boolean value to filter by
|
|
25
|
+
* @returns Filtered array
|
|
26
|
+
*/
|
|
27
|
+
export declare function filterByBooleanField<T>(items: T[], fieldName: keyof T, value: boolean): T[];
|
|
28
|
+
/**
|
|
29
|
+
* Find item by exact field match
|
|
30
|
+
* @param items - Array of objects to search
|
|
31
|
+
* @param fieldName - Name of the field to match
|
|
32
|
+
* @param value - Value to match
|
|
33
|
+
* @returns Found item or undefined
|
|
34
|
+
*/
|
|
35
|
+
export declare function findByField<T>(items: T[], fieldName: keyof T, value: unknown): T | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* Find item by case-insensitive string field match
|
|
38
|
+
* @param items - Array of objects to search
|
|
39
|
+
* @param fieldName - Name of the string field to match
|
|
40
|
+
* @param value - String value to match (case-insensitive)
|
|
41
|
+
* @returns Found item or undefined
|
|
42
|
+
*/
|
|
43
|
+
export declare function findByStringField<T>(items: T[], fieldName: keyof T, value: string): T | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Extract values from a specific field and sort them
|
|
46
|
+
* @param items - Array of objects
|
|
47
|
+
* @param fieldName - Name of the field to extract
|
|
48
|
+
* @returns Sorted array of extracted values
|
|
49
|
+
*/
|
|
50
|
+
export declare function extractAndSortField<T, K extends keyof T>(items: T[], fieldName: K): T[K][];
|
|
51
|
+
/**
|
|
52
|
+
* Group array items by the first character of a string field
|
|
53
|
+
* @param items - Array of objects to group
|
|
54
|
+
* @param fieldName - Name of the string field to group by
|
|
55
|
+
* @returns Object with first letters as keys and arrays of items as values
|
|
56
|
+
*/
|
|
57
|
+
export declare function groupByFirstLetter<T>(items: T[], fieldName: keyof T): Record<string, T[]>;
|
|
58
|
+
/**
|
|
59
|
+
* Group array items by a field value
|
|
60
|
+
* @param items - Array of objects to group
|
|
61
|
+
* @param fieldName - Name of the field to group by
|
|
62
|
+
* @returns Object with field values as keys and arrays of items as values
|
|
63
|
+
*/
|
|
64
|
+
export declare function groupByField<T, K extends keyof T>(items: T[], fieldName: K): Record<string, T[]>;
|
|
65
|
+
/**
|
|
66
|
+
* Check if any item in array has a specific boolean field value
|
|
67
|
+
* @param items - Array of objects to check
|
|
68
|
+
* @param fieldName - Name of the boolean field
|
|
69
|
+
* @param value - Boolean value to check for
|
|
70
|
+
* @returns true if any item matches, false otherwise
|
|
71
|
+
*/
|
|
72
|
+
export declare function hasItemWithFieldValue<T>(items: T[], fieldName: keyof T, value: unknown): boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Count items that match a field value
|
|
75
|
+
* @param items - Array of objects to count
|
|
76
|
+
* @param fieldName - Name of the field to check
|
|
77
|
+
* @param value - Value to count
|
|
78
|
+
* @returns Number of matching items
|
|
79
|
+
*/
|
|
80
|
+
export declare function countByFieldValue<T>(items: T[], fieldName: keyof T, value: unknown): number;
|
|
81
|
+
//# sourceMappingURL=collections.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collections.d.ts","sourceRoot":"","sources":["../src/collections.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,SAAS,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,CAMxE;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,SAAS,EAAE,MAAM,CAAC,EAAE,UAAU,EAAE,MAAM,GAAG,CAAC,EAAE,CAM7F;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,SAAS,EAAE,MAAM,CAAC,EAAE,KAAK,EAAE,OAAO,GAAG,CAAC,EAAE,CAE3F;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,SAAS,EAAE,MAAM,CAAC,EAAE,KAAK,EAAE,OAAO,GAAG,CAAC,GAAG,SAAS,CAE5F;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,SAAS,EAAE,MAAM,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS,CAMjG;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,SAAS,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAE1F;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,SAAS,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,CAazF;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,SAAS,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,CAYhG;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,SAAS,EAAE,MAAM,CAAC,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAEhG;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,SAAS,EAAE,MAAM,CAAC,EAAE,KAAK,EAAE,OAAO,GAAG,MAAM,CAE3F"}
|