@cranberry-money/shared-utils 4.7.0 → 4.8.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 +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/validation.d.ts +156 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +199 -0
- package/dist/withdrawal.d.ts.map +1 -1
- package/dist/withdrawal.js +5 -5
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -14,4 +14,6 @@ export { getTradeStatusBadge, getWithdrawalStatusBadge, getLiquidationStatusBadg
|
|
|
14
14
|
export { formatPortfolioValue, calculateTotalValue, getMarketAllocation, getCashAllocation } from './portfolio';
|
|
15
15
|
export type { LiquidationProgress } from './withdrawal';
|
|
16
16
|
export { formatWithdrawalAmount, formatLiquidationValue, formatSharesQuantity, calculateLiquidationProgress, getTotalEstimatedValue, } from './withdrawal';
|
|
17
|
+
export type { PasswordValidation, EmailConfirmationValidation, ExtendedPasswordValidation } from './validation';
|
|
18
|
+
export { isNumericOnly, validatePassword, isValidTokenFormat, formatVerificationToken, validateEmailConfirmation, isValidEmail, hasUppercase, hasLowercase, hasSpecialCharacter, hasDigit, validatePasswordExtended, isValidPhoneNumber, isValidUrl, isValidDate, isEmptyOrWhitespace, meetsMinLength, meetsMaxLength, isInRange, isPositiveNumber, isNonNegativeNumber, } from './validation';
|
|
17
19
|
//# 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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AC;AAGnE,YAAY,EACV,gBAAgB,EAChB,WAAW,EACX,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,mBAAmB,EACnB,wBAAwB,EACxB,yBAAyB,EACzB,yBAAyB,GAC1B,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,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;AAGtB,YAAY,EAAE,kBAAkB,EAAE,2BAA2B,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAChH,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,kBAAkB,EAClB,uBAAuB,EACvB,yBAAyB,EACzB,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,mBAAmB,EACnB,QAAQ,EACR,wBAAwB,EACxB,kBAAkB,EAClB,UAAU,EACV,WAAW,EACX,mBAAmB,EACnB,cAAc,EACd,cAAc,EACd,SAAS,EACT,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,cAAc,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -15,3 +15,4 @@ export { getTradeStatusBadge, getWithdrawalStatusBadge, getLiquidationStatusBadg
|
|
|
15
15
|
// Portfolio utilities
|
|
16
16
|
export { formatPortfolioValue, calculateTotalValue, getMarketAllocation, getCashAllocation } from './portfolio';
|
|
17
17
|
export { formatWithdrawalAmount, formatLiquidationValue, formatSharesQuantity, calculateLiquidationProgress, getTotalEstimatedValue, } from './withdrawal';
|
|
18
|
+
export { isNumericOnly, validatePassword, isValidTokenFormat, formatVerificationToken, validateEmailConfirmation, isValidEmail, hasUppercase, hasLowercase, hasSpecialCharacter, hasDigit, validatePasswordExtended, isValidPhoneNumber, isValidUrl, isValidDate, isEmptyOrWhitespace, meetsMinLength, meetsMaxLength, isInRange, isPositiveNumber, isNonNegativeNumber, } from './validation';
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validation utility functions
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Checks if a string contains only numeric characters
|
|
6
|
+
* @param str - The string to validate
|
|
7
|
+
* @returns true if the string contains only digits, false otherwise
|
|
8
|
+
*/
|
|
9
|
+
export declare function isNumericOnly(str: string): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Password validation result interface
|
|
12
|
+
*/
|
|
13
|
+
export interface PasswordValidation {
|
|
14
|
+
lengthValid: boolean;
|
|
15
|
+
notNumeric: boolean;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Validates password strength based on minimum requirements
|
|
19
|
+
* @param password - The password to validate
|
|
20
|
+
* @param minLength - Minimum password length (default: 8)
|
|
21
|
+
* @returns An object containing validation results
|
|
22
|
+
*/
|
|
23
|
+
export declare function validatePassword(password: string, minLength?: number): PasswordValidation;
|
|
24
|
+
/**
|
|
25
|
+
* Validates if a verification token is in the expected format
|
|
26
|
+
* @param token - The verification token to validate
|
|
27
|
+
* @param minLength - Minimum token length (default: 6)
|
|
28
|
+
* @returns true if token appears to be valid format, false otherwise
|
|
29
|
+
*/
|
|
30
|
+
export declare function isValidTokenFormat(token: string, minLength?: number): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Formats a verification token by removing whitespace and converting to uppercase
|
|
33
|
+
* @param token - The token to format
|
|
34
|
+
* @returns The formatted token
|
|
35
|
+
*/
|
|
36
|
+
export declare function formatVerificationToken(token: string): string;
|
|
37
|
+
/**
|
|
38
|
+
* Email confirmation validation result interface
|
|
39
|
+
*/
|
|
40
|
+
export interface EmailConfirmationValidation {
|
|
41
|
+
isValid: boolean;
|
|
42
|
+
isEmpty: boolean;
|
|
43
|
+
isValidFormat: boolean;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Validates email confirmation form data
|
|
47
|
+
* @param token - The verification token
|
|
48
|
+
* @param minLength - Minimum token length (default: 6)
|
|
49
|
+
* @returns An object containing validation results
|
|
50
|
+
*/
|
|
51
|
+
export declare function validateEmailConfirmation(token: string, minLength?: number): EmailConfirmationValidation;
|
|
52
|
+
/**
|
|
53
|
+
* Validates if an email address is in a valid format
|
|
54
|
+
* @param email - The email address to validate
|
|
55
|
+
* @returns true if email format is valid, false otherwise
|
|
56
|
+
*/
|
|
57
|
+
export declare function isValidEmail(email: string): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Validates if a string contains at least one uppercase letter
|
|
60
|
+
* @param str - The string to validate
|
|
61
|
+
* @returns true if contains uppercase, false otherwise
|
|
62
|
+
*/
|
|
63
|
+
export declare function hasUppercase(str: string): boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Validates if a string contains at least one lowercase letter
|
|
66
|
+
* @param str - The string to validate
|
|
67
|
+
* @returns true if contains lowercase, false otherwise
|
|
68
|
+
*/
|
|
69
|
+
export declare function hasLowercase(str: string): boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Validates if a string contains at least one special character
|
|
72
|
+
* @param str - The string to validate
|
|
73
|
+
* @returns true if contains special character, false otherwise
|
|
74
|
+
*/
|
|
75
|
+
export declare function hasSpecialCharacter(str: string): boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Validates if a string contains at least one digit
|
|
78
|
+
* @param str - The string to validate
|
|
79
|
+
* @returns true if contains digit, false otherwise
|
|
80
|
+
*/
|
|
81
|
+
export declare function hasDigit(str: string): boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Extended password validation result interface
|
|
84
|
+
*/
|
|
85
|
+
export interface ExtendedPasswordValidation extends PasswordValidation {
|
|
86
|
+
hasUppercase: boolean;
|
|
87
|
+
hasLowercase: boolean;
|
|
88
|
+
hasSpecialCharacter: boolean;
|
|
89
|
+
hasDigit: boolean;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Performs extended password validation with additional strength checks
|
|
93
|
+
* @param password - The password to validate
|
|
94
|
+
* @param minLength - Minimum password length (default: 8)
|
|
95
|
+
* @returns An object containing detailed validation results
|
|
96
|
+
*/
|
|
97
|
+
export declare function validatePasswordExtended(password: string, minLength?: number): ExtendedPasswordValidation;
|
|
98
|
+
/**
|
|
99
|
+
* Validates if a phone number is in a valid format
|
|
100
|
+
* @param phoneNumber - The phone number to validate
|
|
101
|
+
* @returns true if phone number format is valid, false otherwise
|
|
102
|
+
*/
|
|
103
|
+
export declare function isValidPhoneNumber(phoneNumber: string): boolean;
|
|
104
|
+
/**
|
|
105
|
+
* Validates if a URL is in a valid format
|
|
106
|
+
* @param url - The URL to validate
|
|
107
|
+
* @returns true if URL format is valid, false otherwise
|
|
108
|
+
*/
|
|
109
|
+
export declare function isValidUrl(url: string): boolean;
|
|
110
|
+
/**
|
|
111
|
+
* Validates if a date string is in a valid format
|
|
112
|
+
* @param dateString - The date string to validate
|
|
113
|
+
* @returns true if date format is valid, false otherwise
|
|
114
|
+
*/
|
|
115
|
+
export declare function isValidDate(dateString: string): boolean;
|
|
116
|
+
/**
|
|
117
|
+
* Validates if a string is empty or contains only whitespace
|
|
118
|
+
* @param str - The string to validate
|
|
119
|
+
* @returns true if string is empty or whitespace only, false otherwise
|
|
120
|
+
*/
|
|
121
|
+
export declare function isEmptyOrWhitespace(str: string): boolean;
|
|
122
|
+
/**
|
|
123
|
+
* Validates if a string meets a minimum length requirement
|
|
124
|
+
* @param str - The string to validate
|
|
125
|
+
* @param minLength - The minimum length required
|
|
126
|
+
* @returns true if string meets minimum length, false otherwise
|
|
127
|
+
*/
|
|
128
|
+
export declare function meetsMinLength(str: string, minLength: number): boolean;
|
|
129
|
+
/**
|
|
130
|
+
* Validates if a string meets a maximum length requirement
|
|
131
|
+
* @param str - The string to validate
|
|
132
|
+
* @param maxLength - The maximum length allowed
|
|
133
|
+
* @returns true if string meets maximum length, false otherwise
|
|
134
|
+
*/
|
|
135
|
+
export declare function meetsMaxLength(str: string, maxLength: number): boolean;
|
|
136
|
+
/**
|
|
137
|
+
* Validates if a number is within a specified range
|
|
138
|
+
* @param value - The number to validate
|
|
139
|
+
* @param min - The minimum value (inclusive)
|
|
140
|
+
* @param max - The maximum value (inclusive)
|
|
141
|
+
* @returns true if number is within range, false otherwise
|
|
142
|
+
*/
|
|
143
|
+
export declare function isInRange(value: number, min: number, max: number): boolean;
|
|
144
|
+
/**
|
|
145
|
+
* Validates if a value is a positive number
|
|
146
|
+
* @param value - The value to validate
|
|
147
|
+
* @returns true if value is a positive number, false otherwise
|
|
148
|
+
*/
|
|
149
|
+
export declare function isPositiveNumber(value: number): boolean;
|
|
150
|
+
/**
|
|
151
|
+
* Validates if a value is a non-negative number
|
|
152
|
+
* @param value - The value to validate
|
|
153
|
+
* @returns true if value is a non-negative number, false otherwise
|
|
154
|
+
*/
|
|
155
|
+
export declare function isNonNegativeNumber(value: number): boolean;
|
|
156
|
+
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAElD;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,WAAW,EAAE,OAAO,CAAC;IACrB,UAAU,EAAE,OAAO,CAAC;CACrB;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,SAAI,GAAG,kBAAkB,CAKpF;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,SAAI,GAAG,OAAO,CAIxE;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE7D;AAED;;G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H,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAEtE;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAEtE;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAE1E;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEvD;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAE1D"}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validation utility functions
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Checks if a string contains only numeric characters
|
|
6
|
+
* @param str - The string to validate
|
|
7
|
+
* @returns true if the string contains only digits, false otherwise
|
|
8
|
+
*/
|
|
9
|
+
export function isNumericOnly(str) {
|
|
10
|
+
return /^\d+$/.test(str);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Validates password strength based on minimum requirements
|
|
14
|
+
* @param password - The password to validate
|
|
15
|
+
* @param minLength - Minimum password length (default: 8)
|
|
16
|
+
* @returns An object containing validation results
|
|
17
|
+
*/
|
|
18
|
+
export function validatePassword(password, minLength = 8) {
|
|
19
|
+
return {
|
|
20
|
+
lengthValid: password.length >= minLength,
|
|
21
|
+
notNumeric: !isNumericOnly(password),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Validates if a verification token is in the expected format
|
|
26
|
+
* @param token - The verification token to validate
|
|
27
|
+
* @param minLength - Minimum token length (default: 6)
|
|
28
|
+
* @returns true if token appears to be valid format, false otherwise
|
|
29
|
+
*/
|
|
30
|
+
export function isValidTokenFormat(token, minLength = 6) {
|
|
31
|
+
const trimmedToken = token.trim();
|
|
32
|
+
// Assuming tokens are alphanumeric and meet minimum length
|
|
33
|
+
return trimmedToken.length >= minLength && /^[a-zA-Z0-9]+$/.test(trimmedToken);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Formats a verification token by removing whitespace and converting to uppercase
|
|
37
|
+
* @param token - The token to format
|
|
38
|
+
* @returns The formatted token
|
|
39
|
+
*/
|
|
40
|
+
export function formatVerificationToken(token) {
|
|
41
|
+
return token.trim().toUpperCase();
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Validates email confirmation form data
|
|
45
|
+
* @param token - The verification token
|
|
46
|
+
* @param minLength - Minimum token length (default: 6)
|
|
47
|
+
* @returns An object containing validation results
|
|
48
|
+
*/
|
|
49
|
+
export function validateEmailConfirmation(token, minLength = 6) {
|
|
50
|
+
const formattedToken = formatVerificationToken(token);
|
|
51
|
+
return {
|
|
52
|
+
isValid: formattedToken.length > 0 && isValidTokenFormat(formattedToken, minLength),
|
|
53
|
+
isEmpty: formattedToken.length === 0,
|
|
54
|
+
isValidFormat: isValidTokenFormat(formattedToken, minLength),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Validates if an email address is in a valid format
|
|
59
|
+
* @param email - The email address to validate
|
|
60
|
+
* @returns true if email format is valid, false otherwise
|
|
61
|
+
*/
|
|
62
|
+
export function isValidEmail(email) {
|
|
63
|
+
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
64
|
+
return emailRegex.test(email.trim());
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Validates if a string contains at least one uppercase letter
|
|
68
|
+
* @param str - The string to validate
|
|
69
|
+
* @returns true if contains uppercase, false otherwise
|
|
70
|
+
*/
|
|
71
|
+
export function hasUppercase(str) {
|
|
72
|
+
return /[A-Z]/.test(str);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Validates if a string contains at least one lowercase letter
|
|
76
|
+
* @param str - The string to validate
|
|
77
|
+
* @returns true if contains lowercase, false otherwise
|
|
78
|
+
*/
|
|
79
|
+
export function hasLowercase(str) {
|
|
80
|
+
return /[a-z]/.test(str);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Validates if a string contains at least one special character
|
|
84
|
+
* @param str - The string to validate
|
|
85
|
+
* @returns true if contains special character, false otherwise
|
|
86
|
+
*/
|
|
87
|
+
export function hasSpecialCharacter(str) {
|
|
88
|
+
return /[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]/.test(str);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Validates if a string contains at least one digit
|
|
92
|
+
* @param str - The string to validate
|
|
93
|
+
* @returns true if contains digit, false otherwise
|
|
94
|
+
*/
|
|
95
|
+
export function hasDigit(str) {
|
|
96
|
+
return /\d/.test(str);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Performs extended password validation with additional strength checks
|
|
100
|
+
* @param password - The password to validate
|
|
101
|
+
* @param minLength - Minimum password length (default: 8)
|
|
102
|
+
* @returns An object containing detailed validation results
|
|
103
|
+
*/
|
|
104
|
+
export function validatePasswordExtended(password, minLength = 8) {
|
|
105
|
+
const basicValidation = validatePassword(password, minLength);
|
|
106
|
+
return {
|
|
107
|
+
...basicValidation,
|
|
108
|
+
hasUppercase: hasUppercase(password),
|
|
109
|
+
hasLowercase: hasLowercase(password),
|
|
110
|
+
hasSpecialCharacter: hasSpecialCharacter(password),
|
|
111
|
+
hasDigit: hasDigit(password),
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Validates if a phone number is in a valid format
|
|
116
|
+
* @param phoneNumber - The phone number to validate
|
|
117
|
+
* @returns true if phone number format is valid, false otherwise
|
|
118
|
+
*/
|
|
119
|
+
export function isValidPhoneNumber(phoneNumber) {
|
|
120
|
+
// Remove common formatting characters
|
|
121
|
+
const cleaned = phoneNumber.replace(/[\s\-\(\)\.]/g, '');
|
|
122
|
+
// Check if it's a valid phone number (digits only, 10-15 digits)
|
|
123
|
+
return /^\+?\d{10,15}$/.test(cleaned);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Validates if a URL is in a valid format
|
|
127
|
+
* @param url - The URL to validate
|
|
128
|
+
* @returns true if URL format is valid, false otherwise
|
|
129
|
+
*/
|
|
130
|
+
export function isValidUrl(url) {
|
|
131
|
+
try {
|
|
132
|
+
new URL(url);
|
|
133
|
+
return true;
|
|
134
|
+
}
|
|
135
|
+
catch {
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Validates if a date string is in a valid format
|
|
141
|
+
* @param dateString - The date string to validate
|
|
142
|
+
* @returns true if date format is valid, false otherwise
|
|
143
|
+
*/
|
|
144
|
+
export function isValidDate(dateString) {
|
|
145
|
+
const date = new Date(dateString);
|
|
146
|
+
return !isNaN(date.getTime());
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Validates if a string is empty or contains only whitespace
|
|
150
|
+
* @param str - The string to validate
|
|
151
|
+
* @returns true if string is empty or whitespace only, false otherwise
|
|
152
|
+
*/
|
|
153
|
+
export function isEmptyOrWhitespace(str) {
|
|
154
|
+
return str.trim().length === 0;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Validates if a string meets a minimum length requirement
|
|
158
|
+
* @param str - The string to validate
|
|
159
|
+
* @param minLength - The minimum length required
|
|
160
|
+
* @returns true if string meets minimum length, false otherwise
|
|
161
|
+
*/
|
|
162
|
+
export function meetsMinLength(str, minLength) {
|
|
163
|
+
return str.length >= minLength;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Validates if a string meets a maximum length requirement
|
|
167
|
+
* @param str - The string to validate
|
|
168
|
+
* @param maxLength - The maximum length allowed
|
|
169
|
+
* @returns true if string meets maximum length, false otherwise
|
|
170
|
+
*/
|
|
171
|
+
export function meetsMaxLength(str, maxLength) {
|
|
172
|
+
return str.length <= maxLength;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Validates if a number is within a specified range
|
|
176
|
+
* @param value - The number to validate
|
|
177
|
+
* @param min - The minimum value (inclusive)
|
|
178
|
+
* @param max - The maximum value (inclusive)
|
|
179
|
+
* @returns true if number is within range, false otherwise
|
|
180
|
+
*/
|
|
181
|
+
export function isInRange(value, min, max) {
|
|
182
|
+
return value >= min && value <= max;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Validates if a value is a positive number
|
|
186
|
+
* @param value - The value to validate
|
|
187
|
+
* @returns true if value is a positive number, false otherwise
|
|
188
|
+
*/
|
|
189
|
+
export function isPositiveNumber(value) {
|
|
190
|
+
return typeof value === 'number' && value > 0 && isFinite(value);
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Validates if a value is a non-negative number
|
|
194
|
+
* @param value - The value to validate
|
|
195
|
+
* @returns true if value is a non-negative number, false otherwise
|
|
196
|
+
*/
|
|
197
|
+
export function isNonNegativeNumber(value) {
|
|
198
|
+
return typeof value === 'number' && value >= 0 && isFinite(value);
|
|
199
|
+
}
|
package/dist/withdrawal.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withdrawal.d.ts","sourceRoot":"","sources":["../src/withdrawal.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;
|
|
1
|
+
{"version":3,"file":"withdrawal.d.ts","sourceRoot":"","sources":["../src/withdrawal.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAaH;;;;;;;;;;;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,EAAE,YAAY,EAAE,CAAC,EAAE,GAAG,MAAM,CAI9G"}
|
package/dist/withdrawal.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* calculating liquidation progress, and other withdrawal-related operations.
|
|
6
6
|
* Functions are designed to work with generic types to maintain flexibility.
|
|
7
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';
|
|
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
9
|
import { NUMBER_FORMAT_OPTIONS_CURRENCY } from './currency';
|
|
10
10
|
/**
|
|
11
11
|
* Formats a withdrawal amount as currency
|
|
@@ -82,10 +82,10 @@ export function formatSharesQuantity(shares) {
|
|
|
82
82
|
*/
|
|
83
83
|
export function calculateLiquidationProgress(liquidations) {
|
|
84
84
|
const total = liquidations.length;
|
|
85
|
-
const pending = liquidations.filter(
|
|
86
|
-
const inProgress = liquidations.filter(
|
|
87
|
-
const completed = liquidations.filter(
|
|
88
|
-
const failed = liquidations.filter(
|
|
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
89
|
const completionRate = total > 0 ? (completed / total) * 100 : 0;
|
|
90
90
|
return {
|
|
91
91
|
total,
|