@cranberry-money/shared-utils 5.0.1 → 8.0.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/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 +1 -1
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validation utility functions
|
|
3
|
+
*/
|
|
4
|
+
import type { PasswordValidation, EmailConfirmationValidation, ExtendedPasswordValidation } from '@cranberry-money/shared-types';
|
|
5
|
+
/**
|
|
6
|
+
* Checks if a string contains only numeric characters
|
|
7
|
+
* @param str - The string to validate
|
|
8
|
+
* @returns true if the string contains only digits, false otherwise
|
|
9
|
+
*/
|
|
10
|
+
export declare function isNumericOnly(str: string): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Validates password strength based on minimum requirements
|
|
13
|
+
* @param password - The password to validate
|
|
14
|
+
* @param minLength - Minimum password length (default: 8)
|
|
15
|
+
* @returns An object containing validation results
|
|
16
|
+
*/
|
|
17
|
+
export declare function validatePassword(password: string, minLength?: number): PasswordValidation;
|
|
18
|
+
/**
|
|
19
|
+
* Validates if a verification token is in the expected format
|
|
20
|
+
* @param token - The verification token to validate
|
|
21
|
+
* @param minLength - Minimum token length (default: 6)
|
|
22
|
+
* @returns true if token appears to be valid format, false otherwise
|
|
23
|
+
*/
|
|
24
|
+
export declare function isValidTokenFormat(token: string, minLength?: number): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Formats a verification token by removing whitespace and converting to uppercase
|
|
27
|
+
* @param token - The token to format
|
|
28
|
+
* @returns The formatted token
|
|
29
|
+
*/
|
|
30
|
+
export declare function formatVerificationToken(token: string): string;
|
|
31
|
+
/**
|
|
32
|
+
* Validates email confirmation form data
|
|
33
|
+
* @param token - The verification token
|
|
34
|
+
* @param minLength - Minimum token length (default: 6)
|
|
35
|
+
* @returns An object containing validation results
|
|
36
|
+
*/
|
|
37
|
+
export declare function validateEmailConfirmation(token: string, minLength?: number): EmailConfirmationValidation;
|
|
38
|
+
/**
|
|
39
|
+
* Validates if an email address is in a valid format
|
|
40
|
+
* @param email - The email address to validate
|
|
41
|
+
* @returns true if email format is valid, false otherwise
|
|
42
|
+
*/
|
|
43
|
+
export declare function isValidEmail(email: string): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Validates if a string contains at least one uppercase letter
|
|
46
|
+
* @param str - The string to validate
|
|
47
|
+
* @returns true if contains uppercase, false otherwise
|
|
48
|
+
*/
|
|
49
|
+
export declare function hasUppercase(str: string): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Validates if a string contains at least one lowercase letter
|
|
52
|
+
* @param str - The string to validate
|
|
53
|
+
* @returns true if contains lowercase, false otherwise
|
|
54
|
+
*/
|
|
55
|
+
export declare function hasLowercase(str: string): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Validates if a string contains at least one special character
|
|
58
|
+
* @param str - The string to validate
|
|
59
|
+
* @returns true if contains special character, false otherwise
|
|
60
|
+
*/
|
|
61
|
+
export declare function hasSpecialCharacter(str: string): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Validates if a string contains at least one digit
|
|
64
|
+
* @param str - The string to validate
|
|
65
|
+
* @returns true if contains digit, false otherwise
|
|
66
|
+
*/
|
|
67
|
+
export declare function hasDigit(str: string): boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Performs extended password validation with additional strength checks
|
|
70
|
+
* @param password - The password to validate
|
|
71
|
+
* @param minLength - Minimum password length (default: 8)
|
|
72
|
+
* @returns An object containing detailed validation results
|
|
73
|
+
*/
|
|
74
|
+
export declare function validatePasswordExtended(password: string, minLength?: number): ExtendedPasswordValidation;
|
|
75
|
+
/**
|
|
76
|
+
* Validates if a phone number is in a valid format
|
|
77
|
+
* @param phoneNumber - The phone number to validate
|
|
78
|
+
* @returns true if phone number format is valid, false otherwise
|
|
79
|
+
*/
|
|
80
|
+
export declare function isValidPhoneNumber(phoneNumber: string): boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Validates if a phone number appears to be in a valid format (less strict)
|
|
83
|
+
* @param phoneNumber - The phone number to validate
|
|
84
|
+
* @param minLength - Minimum length for the phone number (default: 8)
|
|
85
|
+
* @returns true if phone number appears valid, false otherwise
|
|
86
|
+
*/
|
|
87
|
+
export declare function isValidPhoneFormat(phoneNumber: string, minLength?: number): boolean;
|
|
88
|
+
/**
|
|
89
|
+
* Validates if a URL is in a valid format
|
|
90
|
+
* @param url - The URL to validate
|
|
91
|
+
* @returns true if URL format is valid, false otherwise
|
|
92
|
+
*/
|
|
93
|
+
export declare function isValidUrl(url: string): boolean;
|
|
94
|
+
/**
|
|
95
|
+
* Validates if a date string is in a valid format
|
|
96
|
+
* @param dateString - The date string to validate
|
|
97
|
+
* @returns true if date format is valid, false otherwise
|
|
98
|
+
*/
|
|
99
|
+
export declare function isValidDate(dateString: string): boolean;
|
|
100
|
+
/**
|
|
101
|
+
* Validates if a string is empty or contains only whitespace
|
|
102
|
+
* @param str - The string to validate
|
|
103
|
+
* @returns true if string is empty or whitespace only, false otherwise
|
|
104
|
+
*/
|
|
105
|
+
export declare function isEmptyOrWhitespace(str: string): boolean;
|
|
106
|
+
/**
|
|
107
|
+
* Validates if a string meets a minimum length requirement
|
|
108
|
+
* @param str - The string to validate
|
|
109
|
+
* @param minLength - The minimum length required
|
|
110
|
+
* @returns true if string meets minimum length, false otherwise
|
|
111
|
+
*/
|
|
112
|
+
export declare function meetsMinLength(str: string, minLength: number): boolean;
|
|
113
|
+
/**
|
|
114
|
+
* Validates if a string meets a maximum length requirement
|
|
115
|
+
* @param str - The string to validate
|
|
116
|
+
* @param maxLength - The maximum length allowed
|
|
117
|
+
* @returns true if string meets maximum length, false otherwise
|
|
118
|
+
*/
|
|
119
|
+
export declare function meetsMaxLength(str: string, maxLength: number): boolean;
|
|
120
|
+
/**
|
|
121
|
+
* Validates if a number is within a specified range
|
|
122
|
+
* @param value - The number to validate
|
|
123
|
+
* @param min - The minimum value (inclusive)
|
|
124
|
+
* @param max - The maximum value (inclusive)
|
|
125
|
+
* @returns true if number is within range, false otherwise
|
|
126
|
+
*/
|
|
127
|
+
export declare function isInRange(value: number, min: number, max: number): boolean;
|
|
128
|
+
/**
|
|
129
|
+
* Validates if a value is a positive number
|
|
130
|
+
* @param value - The value to validate
|
|
131
|
+
* @returns true if value is a positive number, false otherwise
|
|
132
|
+
*/
|
|
133
|
+
export declare function isPositiveNumber(value: number): boolean;
|
|
134
|
+
/**
|
|
135
|
+
* Validates if a value is a non-negative number
|
|
136
|
+
* @param value - The value to validate
|
|
137
|
+
* @returns true if value is a non-negative number, false otherwise
|
|
138
|
+
*/
|
|
139
|
+
export declare function isNonNegativeNumber(value: number): boolean;
|
|
140
|
+
/**
|
|
141
|
+
* Validates if a full name contains at least first and last name
|
|
142
|
+
* @param fullName - The full name to validate
|
|
143
|
+
* @param minParts - Minimum number of name parts required (default: 2)
|
|
144
|
+
* @returns true if appears to contain required name parts, false otherwise
|
|
145
|
+
*/
|
|
146
|
+
export declare function isValidFullName(fullName: string, minParts?: number): boolean;
|
|
147
|
+
/**
|
|
148
|
+
* Validates if a date is a valid date of birth (not in future, reasonable age range)
|
|
149
|
+
* @param dateOfBirth - The date string in YYYY-MM-DD format
|
|
150
|
+
* @param minAge - Minimum age requirement (default: 13)
|
|
151
|
+
* @param maxAge - Maximum reasonable age (default: 120)
|
|
152
|
+
* @returns true if valid date of birth, false otherwise
|
|
153
|
+
*/
|
|
154
|
+
export declare function isValidDateOfBirth(dateOfBirth: string, minAge?: number, maxAge?: number): boolean;
|
|
155
|
+
/**
|
|
156
|
+
* Formats a phone number by removing extra spaces and standardizing format
|
|
157
|
+
* @param phoneNumber - The phone number to format
|
|
158
|
+
* @returns The formatted phone number
|
|
159
|
+
*/
|
|
160
|
+
export declare function formatPhoneNumber(phoneNumber: string): string;
|
|
161
|
+
/**
|
|
162
|
+
* Validates if investment amount is within acceptable range
|
|
163
|
+
* @param amount - The investment amount to validate
|
|
164
|
+
* @param minAmount - Minimum investment amount (default: 100)
|
|
165
|
+
* @param maxAmount - Maximum investment amount (default: 10000000)
|
|
166
|
+
* @returns true if amount is within range, false otherwise
|
|
167
|
+
*/
|
|
168
|
+
export declare function isValidInvestmentAmount(amount: number, minAmount?: number, maxAmount?: number): boolean;
|
|
169
|
+
/**
|
|
170
|
+
* Validates if at least minimum number of items are selected
|
|
171
|
+
* @param items - Array of selected items
|
|
172
|
+
* @param minItems - Minimum number of items required (default: 1)
|
|
173
|
+
* @returns true if minimum items are selected, false otherwise
|
|
174
|
+
*/
|
|
175
|
+
export declare function hasMinimumSelection<T>(items: T[], minItems?: number): boolean;
|
|
176
|
+
/**
|
|
177
|
+
* Validates if a value is selected (not null, undefined, or empty string)
|
|
178
|
+
* @param value - The value to check
|
|
179
|
+
* @returns true if value is selected, false otherwise
|
|
180
|
+
*/
|
|
181
|
+
export declare function isSelected(value: unknown): boolean;
|
|
182
|
+
/**
|
|
183
|
+
* Validates that percentage values sum to a target value (default 100)
|
|
184
|
+
* @param values - Array of percentage values
|
|
185
|
+
* @param target - Target sum value (default: 100)
|
|
186
|
+
* @param tolerance - Allowed tolerance for floating point differences (default: 0.01)
|
|
187
|
+
* @returns true if sum equals target within tolerance, false otherwise
|
|
188
|
+
* @example
|
|
189
|
+
* validatePercentageSum([25, 25, 50]) // true (sums to 100)
|
|
190
|
+
* validatePercentageSum([33.33, 33.33, 33.34]) // true (within tolerance)
|
|
191
|
+
* validatePercentageSum([50, 30, 15]) // false (sums to 95)
|
|
192
|
+
*/
|
|
193
|
+
export declare function validatePercentageSum(values: number[], target?: number, tolerance?: number): boolean;
|
|
194
|
+
/**
|
|
195
|
+
* Validates that allocation objects with percentage properties sum to 100%
|
|
196
|
+
* @param allocations - Array of objects with percentage property
|
|
197
|
+
* @param percentageField - Name of the percentage field (default: 'percentage')
|
|
198
|
+
* @param tolerance - Allowed tolerance for floating point differences (default: 0.01)
|
|
199
|
+
* @returns true if sum equals 100 within tolerance, false otherwise
|
|
200
|
+
* @example
|
|
201
|
+
* validateAllocationSum([{percentage: 50}, {percentage: 50}]) // true
|
|
202
|
+
* validateAllocationSum([{percentage: '33.33'}, {percentage: '66.67'}]) // true
|
|
203
|
+
*/
|
|
204
|
+
export declare function validateAllocationSum<T extends Record<string, unknown>>(allocations: T[], percentageField?: keyof T, tolerance?: number): boolean;
|
|
205
|
+
/**
|
|
206
|
+
* Validates that a number is within a specified range (inclusive)
|
|
207
|
+
* @param value - The number to validate
|
|
208
|
+
* @param min - Minimum allowed value
|
|
209
|
+
* @param max - Maximum allowed value
|
|
210
|
+
* @returns true if number is within range, false otherwise
|
|
211
|
+
* @example
|
|
212
|
+
* isInNumberRange(50, 0, 100) // true
|
|
213
|
+
* isInNumberRange(150, 0, 100) // false
|
|
214
|
+
*/
|
|
215
|
+
export declare function isInNumberRange(value: number, min: number, max: number): boolean;
|
|
216
|
+
/**
|
|
217
|
+
* Validates that a percentage is between 0 and 100
|
|
218
|
+
* @param percentage - The percentage to validate
|
|
219
|
+
* @returns true if valid percentage, false otherwise
|
|
220
|
+
* @example
|
|
221
|
+
* isValidPercentage(50) // true
|
|
222
|
+
* isValidPercentage(150) // false
|
|
223
|
+
* isValidPercentage(-10) // false
|
|
224
|
+
*/
|
|
225
|
+
export declare function isValidPercentage(percentage: number): boolean;
|
|
226
|
+
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EACV,kBAAkB,EAClB,2BAA2B,EAC3B,0BAA0B,EAC3B,MAAM,+BAA+B,CAAC;AAEvC;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAElD;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;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,K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G,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAEhF;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAE7D"}
|
|
@@ -0,0 +1,337 @@
|
|
|
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 phone number appears to be in a valid format (less strict)
|
|
127
|
+
* @param phoneNumber - The phone number to validate
|
|
128
|
+
* @param minLength - Minimum length for the phone number (default: 8)
|
|
129
|
+
* @returns true if phone number appears valid, false otherwise
|
|
130
|
+
*/
|
|
131
|
+
export function isValidPhoneFormat(phoneNumber, minLength = 8) {
|
|
132
|
+
const trimmedPhone = phoneNumber.trim();
|
|
133
|
+
// Basic validation: must contain digits and common phone number characters
|
|
134
|
+
return trimmedPhone.length >= minLength && /^[+\-\s\d()]+$/.test(trimmedPhone);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Validates if a URL is in a valid format
|
|
138
|
+
* @param url - The URL to validate
|
|
139
|
+
* @returns true if URL format is valid, false otherwise
|
|
140
|
+
*/
|
|
141
|
+
export function isValidUrl(url) {
|
|
142
|
+
try {
|
|
143
|
+
new URL(url);
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
catch {
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Validates if a date string is in a valid format
|
|
152
|
+
* @param dateString - The date string to validate
|
|
153
|
+
* @returns true if date format is valid, false otherwise
|
|
154
|
+
*/
|
|
155
|
+
export function isValidDate(dateString) {
|
|
156
|
+
const date = new Date(dateString);
|
|
157
|
+
return !isNaN(date.getTime());
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Validates if a string is empty or contains only whitespace
|
|
161
|
+
* @param str - The string to validate
|
|
162
|
+
* @returns true if string is empty or whitespace only, false otherwise
|
|
163
|
+
*/
|
|
164
|
+
export function isEmptyOrWhitespace(str) {
|
|
165
|
+
return str.trim().length === 0;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Validates if a string meets a minimum length requirement
|
|
169
|
+
* @param str - The string to validate
|
|
170
|
+
* @param minLength - The minimum length required
|
|
171
|
+
* @returns true if string meets minimum length, false otherwise
|
|
172
|
+
*/
|
|
173
|
+
export function meetsMinLength(str, minLength) {
|
|
174
|
+
return str.length >= minLength;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Validates if a string meets a maximum length requirement
|
|
178
|
+
* @param str - The string to validate
|
|
179
|
+
* @param maxLength - The maximum length allowed
|
|
180
|
+
* @returns true if string meets maximum length, false otherwise
|
|
181
|
+
*/
|
|
182
|
+
export function meetsMaxLength(str, maxLength) {
|
|
183
|
+
return str.length <= maxLength;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Validates if a number is within a specified range
|
|
187
|
+
* @param value - The number to validate
|
|
188
|
+
* @param min - The minimum value (inclusive)
|
|
189
|
+
* @param max - The maximum value (inclusive)
|
|
190
|
+
* @returns true if number is within range, false otherwise
|
|
191
|
+
*/
|
|
192
|
+
export function isInRange(value, min, max) {
|
|
193
|
+
return value >= min && value <= max;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Validates if a value is a positive number
|
|
197
|
+
* @param value - The value to validate
|
|
198
|
+
* @returns true if value is a positive number, false otherwise
|
|
199
|
+
*/
|
|
200
|
+
export function isPositiveNumber(value) {
|
|
201
|
+
return typeof value === 'number' && value > 0 && isFinite(value);
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Validates if a value is a non-negative number
|
|
205
|
+
* @param value - The value to validate
|
|
206
|
+
* @returns true if value is a non-negative number, false otherwise
|
|
207
|
+
*/
|
|
208
|
+
export function isNonNegativeNumber(value) {
|
|
209
|
+
return typeof value === 'number' && value >= 0 && isFinite(value);
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Validates if a full name contains at least first and last name
|
|
213
|
+
* @param fullName - The full name to validate
|
|
214
|
+
* @param minParts - Minimum number of name parts required (default: 2)
|
|
215
|
+
* @returns true if appears to contain required name parts, false otherwise
|
|
216
|
+
*/
|
|
217
|
+
export function isValidFullName(fullName, minParts = 2) {
|
|
218
|
+
const trimmedName = fullName.trim();
|
|
219
|
+
const nameParts = trimmedName.split(/\s+/);
|
|
220
|
+
return nameParts.length >= minParts && nameParts.every(part => part.length > 0);
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Validates if a date is a valid date of birth (not in future, reasonable age range)
|
|
224
|
+
* @param dateOfBirth - The date string in YYYY-MM-DD format
|
|
225
|
+
* @param minAge - Minimum age requirement (default: 13)
|
|
226
|
+
* @param maxAge - Maximum reasonable age (default: 120)
|
|
227
|
+
* @returns true if valid date of birth, false otherwise
|
|
228
|
+
*/
|
|
229
|
+
export function isValidDateOfBirth(dateOfBirth, minAge = 13, maxAge = 120) {
|
|
230
|
+
if (!dateOfBirth)
|
|
231
|
+
return false;
|
|
232
|
+
const birthDate = new Date(dateOfBirth);
|
|
233
|
+
const today = new Date();
|
|
234
|
+
const age = today.getFullYear() - birthDate.getFullYear();
|
|
235
|
+
const monthDiff = today.getMonth() - birthDate.getMonth();
|
|
236
|
+
const dayDiff = today.getDate() - birthDate.getDate();
|
|
237
|
+
// Adjust age if birthday hasn't occurred this year
|
|
238
|
+
const actualAge = monthDiff < 0 || (monthDiff === 0 && dayDiff < 0) ? age - 1 : age;
|
|
239
|
+
return actualAge >= minAge && actualAge <= maxAge && birthDate <= today;
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Formats a phone number by removing extra spaces and standardizing format
|
|
243
|
+
* @param phoneNumber - The phone number to format
|
|
244
|
+
* @returns The formatted phone number
|
|
245
|
+
*/
|
|
246
|
+
export function formatPhoneNumber(phoneNumber) {
|
|
247
|
+
return phoneNumber.trim();
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Validates if investment amount is within acceptable range
|
|
251
|
+
* @param amount - The investment amount to validate
|
|
252
|
+
* @param minAmount - Minimum investment amount (default: 100)
|
|
253
|
+
* @param maxAmount - Maximum investment amount (default: 10000000)
|
|
254
|
+
* @returns true if amount is within range, false otherwise
|
|
255
|
+
*/
|
|
256
|
+
export function isValidInvestmentAmount(amount, minAmount = 100, maxAmount = 10000000) {
|
|
257
|
+
return amount >= minAmount && amount <= maxAmount;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Validates if at least minimum number of items are selected
|
|
261
|
+
* @param items - Array of selected items
|
|
262
|
+
* @param minItems - Minimum number of items required (default: 1)
|
|
263
|
+
* @returns true if minimum items are selected, false otherwise
|
|
264
|
+
*/
|
|
265
|
+
export function hasMinimumSelection(items, minItems = 1) {
|
|
266
|
+
return items && items.length >= minItems;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Validates if a value is selected (not null, undefined, or empty string)
|
|
270
|
+
* @param value - The value to check
|
|
271
|
+
* @returns true if value is selected, false otherwise
|
|
272
|
+
*/
|
|
273
|
+
export function isSelected(value) {
|
|
274
|
+
return value !== null && value !== undefined && value !== '';
|
|
275
|
+
}
|
|
276
|
+
// ENHANCED VALIDATION UTILITIES (Phase 14)
|
|
277
|
+
/**
|
|
278
|
+
* Validates that percentage values sum to a target value (default 100)
|
|
279
|
+
* @param values - Array of percentage values
|
|
280
|
+
* @param target - Target sum value (default: 100)
|
|
281
|
+
* @param tolerance - Allowed tolerance for floating point differences (default: 0.01)
|
|
282
|
+
* @returns true if sum equals target within tolerance, false otherwise
|
|
283
|
+
* @example
|
|
284
|
+
* validatePercentageSum([25, 25, 50]) // true (sums to 100)
|
|
285
|
+
* validatePercentageSum([33.33, 33.33, 33.34]) // true (within tolerance)
|
|
286
|
+
* validatePercentageSum([50, 30, 15]) // false (sums to 95)
|
|
287
|
+
*/
|
|
288
|
+
export function validatePercentageSum(values, target = 100, tolerance = 0.01) {
|
|
289
|
+
if (!Array.isArray(values) || values.length === 0)
|
|
290
|
+
return false;
|
|
291
|
+
const sum = values.reduce((total, value) => total + (value || 0), 0);
|
|
292
|
+
return Math.abs(sum - target) <= tolerance;
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Validates that allocation objects with percentage properties sum to 100%
|
|
296
|
+
* @param allocations - Array of objects with percentage property
|
|
297
|
+
* @param percentageField - Name of the percentage field (default: 'percentage')
|
|
298
|
+
* @param tolerance - Allowed tolerance for floating point differences (default: 0.01)
|
|
299
|
+
* @returns true if sum equals 100 within tolerance, false otherwise
|
|
300
|
+
* @example
|
|
301
|
+
* validateAllocationSum([{percentage: 50}, {percentage: 50}]) // true
|
|
302
|
+
* validateAllocationSum([{percentage: '33.33'}, {percentage: '66.67'}]) // true
|
|
303
|
+
*/
|
|
304
|
+
export function validateAllocationSum(allocations, percentageField = 'percentage', tolerance = 0.01) {
|
|
305
|
+
if (!Array.isArray(allocations) || allocations.length === 0)
|
|
306
|
+
return false;
|
|
307
|
+
const values = allocations.map(allocation => {
|
|
308
|
+
const value = allocation[percentageField];
|
|
309
|
+
return typeof value === 'string' ? parseFloat(value) || 0 : Number(value) || 0;
|
|
310
|
+
});
|
|
311
|
+
return validatePercentageSum(values, 100, tolerance);
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Validates that a number is within a specified range (inclusive)
|
|
315
|
+
* @param value - The number to validate
|
|
316
|
+
* @param min - Minimum allowed value
|
|
317
|
+
* @param max - Maximum allowed value
|
|
318
|
+
* @returns true if number is within range, false otherwise
|
|
319
|
+
* @example
|
|
320
|
+
* isInNumberRange(50, 0, 100) // true
|
|
321
|
+
* isInNumberRange(150, 0, 100) // false
|
|
322
|
+
*/
|
|
323
|
+
export function isInNumberRange(value, min, max) {
|
|
324
|
+
return typeof value === 'number' && !isNaN(value) && value >= min && value <= max;
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Validates that a percentage is between 0 and 100
|
|
328
|
+
* @param percentage - The percentage to validate
|
|
329
|
+
* @returns true if valid percentage, false otherwise
|
|
330
|
+
* @example
|
|
331
|
+
* isValidPercentage(50) // true
|
|
332
|
+
* isValidPercentage(150) // false
|
|
333
|
+
* isValidPercentage(-10) // false
|
|
334
|
+
*/
|
|
335
|
+
export function isValidPercentage(percentage) {
|
|
336
|
+
return isInNumberRange(percentage, 0, 100);
|
|
337
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Withdrawal-related utility functions
|
|
3
|
+
*
|
|
4
|
+
* This module provides pure functions for formatting withdrawal amounts,
|
|
5
|
+
* calculating liquidation progress, and other withdrawal-related operations.
|
|
6
|
+
* Functions are designed to work with generic types to maintain flexibility.
|
|
7
|
+
*/
|
|
8
|
+
import type { LiquidationProgress } from '@cranberry-money/shared-types';
|
|
9
|
+
/**
|
|
10
|
+
* Formats a withdrawal amount as currency
|
|
11
|
+
*
|
|
12
|
+
* @param amount - Withdrawal amount as string or number
|
|
13
|
+
* @returns Formatted currency string with AUD symbol
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* formatWithdrawalAmount(5000) // 'A$5,000.00'
|
|
18
|
+
* formatWithdrawalAmount('5000.50') // 'A$5,000.50'
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare function formatWithdrawalAmount(amount: string | number): string;
|
|
22
|
+
/**
|
|
23
|
+
* Formats a liquidation value as currency
|
|
24
|
+
*
|
|
25
|
+
* @param value - Liquidation value as string or number
|
|
26
|
+
* @returns Formatted currency string with AUD symbol
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* formatLiquidationValue(10000) // 'A$10,000.00'
|
|
31
|
+
* formatLiquidationValue('10000.50') // 'A$10,000.50'
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare function formatLiquidationValue(value: string | number): string;
|
|
35
|
+
/**
|
|
36
|
+
* Formats share quantity without decimal places
|
|
37
|
+
*
|
|
38
|
+
* @param shares - Number of shares
|
|
39
|
+
* @returns Formatted number string with thousands separators
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* formatSharesQuantity(1234) // '1,234'
|
|
44
|
+
* formatSharesQuantity(1234567) // '1,234,567'
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare function formatSharesQuantity(shares: number): string;
|
|
48
|
+
/**
|
|
49
|
+
* Calculates liquidation progress statistics
|
|
50
|
+
*
|
|
51
|
+
* @param liquidations - Array of liquidation objects with liquidationStatus property
|
|
52
|
+
* @returns Progress statistics including counts and completion rate
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* const liquidations = [
|
|
57
|
+
* { liquidationStatus: 'PENDING' },
|
|
58
|
+
* { liquidationStatus: 'SETTLED' },
|
|
59
|
+
* { liquidationStatus: 'FAILED' }
|
|
60
|
+
* ];
|
|
61
|
+
* calculateLiquidationProgress(liquidations)
|
|
62
|
+
* // Returns: { total: 3, pending: 1, inProgress: 0, completed: 1, failed: 1, completionRate: 33.33 }
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
export declare function calculateLiquidationProgress<T extends {
|
|
66
|
+
liquidationStatus: string;
|
|
67
|
+
}>(liquidations: T[]): LiquidationProgress;
|
|
68
|
+
/**
|
|
69
|
+
* Calculates total estimated value from liquidations
|
|
70
|
+
*
|
|
71
|
+
* @param liquidations - Array of liquidation objects with estimatedValue property
|
|
72
|
+
* @returns Total estimated value as number
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* const liquidations = [
|
|
77
|
+
* { estimatedValue: '1000.50' },
|
|
78
|
+
* { estimatedValue: '2000' },
|
|
79
|
+
* { estimatedValue: null }
|
|
80
|
+
* ];
|
|
81
|
+
* getTotalEstimatedValue(liquidations) // 3000.50
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
export declare function getTotalEstimatedValue<T extends {
|
|
85
|
+
estimatedValue?: string | null;
|
|
86
|
+
}>(liquidations: T[]): number;
|
|
87
|
+
//# sourceMappingURL=withdrawal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withdrawal.d.ts","sourceRoot":"","sources":["../src/withdrawal.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AAazE;;;;;;;;;;;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;;;;;;;;;;;;;;;;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"}
|