@jdsalasc/solvejs-validators 1.0.3 → 1.2.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/README.md +10 -11
- package/dist/cjs/index.cjs +370 -60
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.d.ts +176 -15
- package/dist/esm/index.js +355 -60
- package/dist/esm/index.js.map +1 -1
- package/package.json +54 -52
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,67 +1,228 @@
|
|
|
1
|
+
export type ValidationResultCode = "VALID" | "EMPTY" | "INVALID_FORMAT" | "TOO_SHORT" | "TOO_LONG" | "INVALID_CHARACTERS" | "UNSUPPORTED_LOCALE" | "UNSUPPORTED_COUNTRY" | "CHECKSUM_FAILED";
|
|
2
|
+
export type ValidationResult = {
|
|
3
|
+
ok: boolean;
|
|
4
|
+
code: ValidationResultCode;
|
|
5
|
+
message: string;
|
|
6
|
+
};
|
|
7
|
+
export type SupportedCountry = "ANY" | "US" | "CO" | "MX" | "ES";
|
|
8
|
+
export type DirectionLocale = "en" | "es";
|
|
1
9
|
/**
|
|
2
|
-
*
|
|
10
|
+
* Validates cellphone numbers using regional presets.
|
|
3
11
|
*
|
|
4
12
|
* @param value - Input phone string.
|
|
5
13
|
* @param options - Validation options.
|
|
6
14
|
* @param options.allowInternational - Allows a leading `+`.
|
|
7
|
-
* @param options.
|
|
8
|
-
* @param options.
|
|
9
|
-
* @
|
|
15
|
+
* @param options.country - Country preset used for length constraints.
|
|
16
|
+
* @param options.minDigits - Override minimum digits.
|
|
17
|
+
* @param options.maxDigits - Override maximum digits.
|
|
18
|
+
* @returns Structured validation result.
|
|
19
|
+
*/
|
|
20
|
+
export declare function validateCellphoneNumber(value: string, options?: {
|
|
21
|
+
allowInternational?: boolean;
|
|
22
|
+
country?: SupportedCountry;
|
|
23
|
+
minDigits?: number;
|
|
24
|
+
maxDigits?: number;
|
|
25
|
+
}): ValidationResult;
|
|
26
|
+
/**
|
|
27
|
+
* Boolean wrapper for `validateCellphoneNumber`.
|
|
28
|
+
*
|
|
29
|
+
* @param value - Input phone string.
|
|
30
|
+
* @param options - Validation options.
|
|
31
|
+
* @returns `true` when the value is valid.
|
|
10
32
|
*/
|
|
11
33
|
export declare function isCellphoneNumber(value: string, options?: {
|
|
12
34
|
allowInternational?: boolean;
|
|
35
|
+
country?: SupportedCountry;
|
|
13
36
|
minDigits?: number;
|
|
14
37
|
maxDigits?: number;
|
|
15
38
|
}): boolean;
|
|
16
39
|
/**
|
|
17
|
-
* Validates
|
|
40
|
+
* Validates address direction using localized dictionaries.
|
|
41
|
+
*
|
|
42
|
+
* @param value - Direction text.
|
|
43
|
+
* @param options - Validation options.
|
|
44
|
+
* @param options.locale - Locale dictionary (`en`, `es`).
|
|
45
|
+
* @returns Structured validation result.
|
|
46
|
+
*/
|
|
47
|
+
export declare function validateAddressDirection(value: string, options?: {
|
|
48
|
+
locale?: DirectionLocale;
|
|
49
|
+
}): ValidationResult;
|
|
50
|
+
/**
|
|
51
|
+
* Boolean wrapper for `validateAddressDirection`.
|
|
52
|
+
*
|
|
53
|
+
* @param value - Direction text.
|
|
54
|
+
* @param options - Validation options.
|
|
55
|
+
* @returns `true` when the value is valid.
|
|
56
|
+
*/
|
|
57
|
+
export declare function isAddressDirection(value: string, options?: {
|
|
58
|
+
locale?: DirectionLocale;
|
|
59
|
+
}): boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Backward-compatible alias for users who typed the previous function with one missing `d`.
|
|
62
|
+
*
|
|
63
|
+
* @param value - Direction text.
|
|
64
|
+
* @param options - Validation options.
|
|
65
|
+
* @returns `true` when the direction is valid.
|
|
66
|
+
*/
|
|
67
|
+
export declare function isAddresDirection(value: string, options?: {
|
|
68
|
+
locale?: DirectionLocale;
|
|
69
|
+
}): boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Backward-compatible alias for users who typed the previous function with two spelling mistakes.
|
|
18
72
|
*
|
|
19
73
|
* @param value - Direction text.
|
|
20
|
-
* @
|
|
74
|
+
* @param options - Validation options.
|
|
75
|
+
* @returns `true` when the direction is valid.
|
|
21
76
|
*/
|
|
22
|
-
export declare function
|
|
77
|
+
export declare function isAddresDirrection(value: string, options?: {
|
|
78
|
+
locale?: DirectionLocale;
|
|
79
|
+
}): boolean;
|
|
23
80
|
/**
|
|
24
|
-
* Validates names
|
|
81
|
+
* Validates person names with practical production constraints.
|
|
25
82
|
*
|
|
26
83
|
* @param value - Name string.
|
|
27
84
|
* @param options - Validation options.
|
|
28
85
|
* @param options.minLength - Minimum total length.
|
|
29
86
|
* @param options.maxLength - Maximum total length.
|
|
30
|
-
* @returns
|
|
87
|
+
* @returns Structured validation result.
|
|
88
|
+
*/
|
|
89
|
+
export declare function validateName(value: string, options?: {
|
|
90
|
+
minLength?: number;
|
|
91
|
+
maxLength?: number;
|
|
92
|
+
}): ValidationResult;
|
|
93
|
+
/**
|
|
94
|
+
* Boolean wrapper for `validateName`.
|
|
95
|
+
*
|
|
96
|
+
* @param value - Name string.
|
|
97
|
+
* @param options - Validation options.
|
|
98
|
+
* @returns `true` when the value is valid.
|
|
31
99
|
*/
|
|
32
100
|
export declare function isValidName(value: string, options?: {
|
|
33
101
|
minLength?: number;
|
|
34
102
|
maxLength?: number;
|
|
35
103
|
}): boolean;
|
|
36
104
|
/**
|
|
37
|
-
* Validates
|
|
105
|
+
* Validates usernames used in sign-up forms.
|
|
106
|
+
*
|
|
107
|
+
* @param value - Username candidate.
|
|
108
|
+
* @param options - Validation options.
|
|
109
|
+
* @param options.minLength - Minimum length.
|
|
110
|
+
* @param options.maxLength - Maximum length.
|
|
111
|
+
* @returns Structured validation result.
|
|
112
|
+
*/
|
|
113
|
+
export declare function validateUsername(value: string, options?: {
|
|
114
|
+
minLength?: number;
|
|
115
|
+
maxLength?: number;
|
|
116
|
+
}): ValidationResult;
|
|
117
|
+
/**
|
|
118
|
+
* Boolean wrapper for `validateUsername`.
|
|
119
|
+
*
|
|
120
|
+
* @param value - Username candidate.
|
|
121
|
+
* @param options - Validation options.
|
|
122
|
+
* @returns `true` when the username is valid.
|
|
123
|
+
*/
|
|
124
|
+
export declare function isUsername(value: string, options?: {
|
|
125
|
+
minLength?: number;
|
|
126
|
+
maxLength?: number;
|
|
127
|
+
}): boolean;
|
|
128
|
+
/**
|
|
129
|
+
* Validates an email shape.
|
|
38
130
|
*
|
|
39
131
|
* @param value - Email string.
|
|
40
|
-
* @returns
|
|
132
|
+
* @returns Structured validation result.
|
|
133
|
+
*/
|
|
134
|
+
export declare function validateEmail(value: string): ValidationResult;
|
|
135
|
+
/**
|
|
136
|
+
* Boolean wrapper for `validateEmail`.
|
|
137
|
+
*
|
|
138
|
+
* @param value - Email string.
|
|
139
|
+
* @returns `true` when the value is valid.
|
|
41
140
|
*/
|
|
42
141
|
export declare function isEmail(value: string): boolean;
|
|
43
142
|
/**
|
|
44
143
|
* Validates an HTTP(S) URL.
|
|
45
144
|
*
|
|
46
145
|
* @param value - URL string.
|
|
47
|
-
* @returns
|
|
146
|
+
* @returns Structured validation result.
|
|
147
|
+
*/
|
|
148
|
+
export declare function validateHttpUrl(value: string): ValidationResult;
|
|
149
|
+
/**
|
|
150
|
+
* Boolean wrapper for `validateHttpUrl`.
|
|
151
|
+
*
|
|
152
|
+
* @param value - URL string.
|
|
153
|
+
* @returns `true` when the value is valid.
|
|
48
154
|
*/
|
|
49
155
|
export declare function isHttpUrl(value: string): boolean;
|
|
50
156
|
/**
|
|
51
157
|
* Validates US-style postal codes (`12345` or `12345-6789`).
|
|
52
158
|
*
|
|
53
159
|
* @param value - Postal code string.
|
|
54
|
-
* @returns
|
|
160
|
+
* @returns Structured validation result.
|
|
161
|
+
*/
|
|
162
|
+
export declare function validatePostalCode(value: string): ValidationResult;
|
|
163
|
+
/**
|
|
164
|
+
* Boolean wrapper for `validatePostalCode`.
|
|
165
|
+
*
|
|
166
|
+
* @param value - Postal code string.
|
|
167
|
+
* @returns `true` when the value is valid.
|
|
55
168
|
*/
|
|
56
169
|
export declare function isPostalCode(value: string): boolean;
|
|
57
170
|
/**
|
|
58
|
-
* Validates
|
|
171
|
+
* Validates address line input for common delivery/billing forms.
|
|
172
|
+
*
|
|
173
|
+
* @param value - Address line string.
|
|
174
|
+
* @param options - Validation options.
|
|
175
|
+
* @param options.minLength - Minimum length.
|
|
176
|
+
* @param options.maxLength - Maximum length.
|
|
177
|
+
* @returns Structured validation result.
|
|
178
|
+
*/
|
|
179
|
+
export declare function validateAddressLine(value: string, options?: {
|
|
180
|
+
minLength?: number;
|
|
181
|
+
maxLength?: number;
|
|
182
|
+
}): ValidationResult;
|
|
183
|
+
/**
|
|
184
|
+
* Boolean wrapper for `validateAddressLine`.
|
|
185
|
+
*
|
|
186
|
+
* @param value - Address line string.
|
|
187
|
+
* @param options - Validation options.
|
|
188
|
+
* @returns `true` when the address line is valid.
|
|
189
|
+
*/
|
|
190
|
+
export declare function isAddressLine(value: string, options?: {
|
|
191
|
+
minLength?: number;
|
|
192
|
+
maxLength?: number;
|
|
193
|
+
}): boolean;
|
|
194
|
+
/**
|
|
195
|
+
* Validates password strength using default security checks.
|
|
59
196
|
*
|
|
60
197
|
* @param value - Password candidate.
|
|
61
198
|
* @param options - Validation options.
|
|
62
199
|
* @param options.minLength - Minimum required length.
|
|
63
|
-
* @returns
|
|
200
|
+
* @returns Structured validation result.
|
|
201
|
+
*/
|
|
202
|
+
export declare function validateStrongPassword(value: string, options?: {
|
|
203
|
+
minLength?: number;
|
|
204
|
+
}): ValidationResult;
|
|
205
|
+
/**
|
|
206
|
+
* Boolean wrapper for `validateStrongPassword`.
|
|
207
|
+
*
|
|
208
|
+
* @param value - Password candidate.
|
|
209
|
+
* @param options - Validation options.
|
|
210
|
+
* @returns `true` when the value is valid.
|
|
64
211
|
*/
|
|
65
212
|
export declare function isStrongPassword(value: string, options?: {
|
|
66
213
|
minLength?: number;
|
|
67
214
|
}): boolean;
|
|
215
|
+
/**
|
|
216
|
+
* Validates card numbers using basic shape checks plus Luhn checksum.
|
|
217
|
+
*
|
|
218
|
+
* @param value - Card number candidate.
|
|
219
|
+
* @returns Structured validation result.
|
|
220
|
+
*/
|
|
221
|
+
export declare function validateCreditCardNumber(value: string): ValidationResult;
|
|
222
|
+
/**
|
|
223
|
+
* Boolean wrapper for `validateCreditCardNumber`.
|
|
224
|
+
*
|
|
225
|
+
* @param value - Card number candidate.
|
|
226
|
+
* @returns `true` when the card number is valid.
|
|
227
|
+
*/
|
|
228
|
+
export declare function isCreditCardNumber(value: string): boolean;
|