1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | declare namespace Express {
|
11 | interface Request extends ExpressValidator.RequestValidation {}
|
12 | }
|
13 |
|
14 |
|
15 | declare module "express-validator" {
|
16 | import express = require('express');
|
17 |
|
18 | |
19 |
|
20 |
|
21 |
|
22 | function ExpressValidator(options?: ExpressValidator.Options.ExpressValidatorOptions): express.RequestHandler;
|
23 |
|
24 | export = ExpressValidator;
|
25 | }
|
26 |
|
27 |
|
28 | declare namespace ExpressValidator {
|
29 |
|
30 | export type URLProtocol = 'http' | 'https' | 'ftp'
|
31 | export type UUIDVersion = 3 | 4 | 5 | 'all'
|
32 | export type IPVersion = 4 | 6
|
33 | export type AlphaLocale = 'ar' | 'ar-AE' | 'ar-BH' | 'ar-DZ' | 'ar-EG' | 'ar-IQ' | 'ar-JO' | 'ar-KW' | 'ar-LB' | 'ar-LY' | 'ar-MA' | 'ar-QA' | 'ar-QM' | 'ar-SA' | 'ar-SD' | 'ar-SY' | 'ar-TN' | 'ar-YE' | 'cs-CZ' | 'da-DK' | 'de-DE' | 'en-AU' | 'en-GB' | 'en-HK' | 'en-IN' | 'en-NZ' | 'en-US' | 'en-ZA' | 'en-ZM' | 'es-ES' | 'fr-FR' | 'hu-HU' | 'nl-NL' | 'pl-PL' | 'pt-BR' | 'pt-PT' | 'ru-RU' | 'sr-RS' | 'sr-RS@latin' | 'tr-TR' | 'uk-UA'
|
34 | export type AlphanumericLocale = 'ar' | 'ar-AE' | 'ar-BH' | 'ar-DZ' | 'ar-EG' | 'ar-IQ' | 'ar-JO' | 'ar-KW' | 'ar-LB' | 'ar-LY' | 'ar-MA' | 'ar-QA' | 'ar-QM' | 'ar-SA' | 'ar-SD' | 'ar-SY' | 'ar-TN' | 'ar-YE' | 'cs-CZ' | 'da-DK' | 'de-DE' | 'en-AU' | 'en-GB' | 'en-HK' | 'en-IN' | 'en-NZ' | 'en-US' | 'en-ZA' | 'en-ZM' | 'es-ES' | 'fr-FR' | 'fr-BE' | 'hu-HU' | 'nl-BE' | 'nl-NL' | 'pl-PL' | 'pt-BR' | 'pt-PT' | 'ru-RU' | 'sr-RS' | 'sr-RS@latin' | 'tr-TR' | 'uk-UA'
|
35 | export type MobilePhoneLocal = 'ar-DZ' | 'ar-SA' | 'ar-SY' | 'cs-CZ' | 'de-DE' | 'da-DK' | 'el-GR' | 'en-AU' | 'en-GB' | 'en-HK' | 'en-IN' | 'en-NZ' | 'en-US' | 'en-CA' | 'en-ZA' | 'en-ZM' | 'es-ES' | 'fi-FI' | 'fr-FR' | 'hu-HU' | 'it-IT' | 'ja-JP' | 'ms-MY' | 'nb-NO' | 'nn-NO' | 'pl-PL' | 'pt-PT' | 'ru-RU' | 'sr-RS' | 'tr-TR' | 'vi-VN' | 'zh-CN' | 'zh-TW'
|
36 | export type Location = 'body' | 'params' | 'query' | 'headers'
|
37 |
|
38 | export type ValidationSchema = {
|
39 | [param: string]:
|
40 | ExpressValidator.Options.ValidationSchemaParamOptions
|
41 | |
|
42 | { [customValidator: string]: ExpressValidator.Options.ValidatorSchemaOptions }
|
43 | }
|
44 |
|
45 | interface ValidatorFunction {
|
46 | (item: string | string[], message?: string): Validator;
|
47 | (schema: {}): Validator;
|
48 | }
|
49 | |
50 |
|
51 |
|
52 |
|
53 | interface ValidatorFunctionRegExp extends ValidatorFunction { (matchIndex: number, message?: string): Validator; }
|
54 | interface SanitizerFunction { (item: string): Sanitizer; }
|
55 | interface Dictionary<T> { [key: string]: T; }
|
56 | interface Result {
|
57 | |
58 |
|
59 |
|
60 | isEmpty(): boolean
|
61 | |
62 |
|
63 |
|
64 |
|
65 | array(): MappedError[]
|
66 | |
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 | mapped(): Dictionary<MappedError>
|
73 | |
74 |
|
75 |
|
76 |
|
77 | useFirstErrorOnly(): Result
|
78 | |
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 | throw(): Result
|
85 | }
|
86 |
|
87 | export interface RequestValidation {
|
88 | assert: ValidatorFunctionRegExp;
|
89 | validate: ValidatorFunctionRegExp;
|
90 | check: ValidatorFunctionRegExp;
|
91 | checkBody: ValidatorFunction;
|
92 | checkCookies: ValidatorFunction;
|
93 | checkHeaders: ValidatorFunction;
|
94 | checkParams: ValidatorFunction;
|
95 | checkQuery: ValidatorFunction;
|
96 |
|
97 | filter: SanitizerFunction;
|
98 | sanitize: SanitizerFunction;
|
99 | sanitizeBody: SanitizerFunction;
|
100 | sanitizeQuery: SanitizerFunction;
|
101 | sanitizeParams: SanitizerFunction;
|
102 | sanitizeHeaders: SanitizerFunction;
|
103 | sanitizeCookies: SanitizerFunction;
|
104 |
|
105 | |
106 |
|
107 |
|
108 |
|
109 |
|
110 | validationErrors(mapped?: boolean): Dictionary<MappedError> | MappedError[];
|
111 | |
112 |
|
113 |
|
114 |
|
115 |
|
116 | validationErrors<T>(mapped?: boolean): Dictionary<T> | T[];
|
117 | |
118 |
|
119 |
|
120 |
|
121 | asyncValidationErrors(mapped?: boolean): Promise<MappedError[] | Dictionary<MappedError>>;
|
122 | |
123 |
|
124 |
|
125 |
|
126 | asyncValidationErrors<T>(mapped?: boolean): Promise<T[] | Dictionary<T>>;
|
127 | |
128 |
|
129 |
|
130 | getValidationResult(): Promise<Result>
|
131 | }
|
132 |
|
133 | export interface Validator {
|
134 |
|
135 | |
136 |
|
137 |
|
138 |
|
139 |
|
140 |
|
141 | isEmail(options?: ExpressValidator.Options.IsEmailOptions): Validator;
|
142 | isURL(options?: ExpressValidator.Options.IsURLOptions): Validator;
|
143 | isMACAddress(): Validator;
|
144 | |
145 |
|
146 |
|
147 |
|
148 | isIP(version?: IPVersion): Validator;
|
149 | isFQDN(options?: ExpressValidator.Options.IsFQDNOptions): Validator;
|
150 | isBoolean(): Validator;
|
151 | |
152 |
|
153 |
|
154 | isAlpha(locale?: AlphaLocale): Validator;
|
155 | |
156 |
|
157 |
|
158 | isAlphanumeric(locale?: AlphanumericLocale): Validator;
|
159 | isNumeric(): Validator;
|
160 | isLowercase(): Validator;
|
161 | isUppercase(): Validator;
|
162 | isAscii(): Validator;
|
163 | isFullWidth(): Validator;
|
164 | isHalfWidth(): Validator;
|
165 | isVariableWidth(): Validator;
|
166 | isMultibyte(): Validator;
|
167 | isSurrogatePair(): Validator;
|
168 | isInt(options?: ExpressValidator.Options.IsIntOptions): Validator;
|
169 | isFloat(options?: ExpressValidator.Options.MinMaxExtendedOptions): Validator;
|
170 | isDecimal(): Validator;
|
171 | isHexadecimal(): Validator;
|
172 | isDivisibleBy(num: number): Validator;
|
173 | isHexColor(): Validator;
|
174 | isMD5(): Validator;
|
175 | isJSON(): Validator;
|
176 | isEmpty(): Validator;
|
177 | isLength(options: ExpressValidator.Options.MinMaxOptions): Validator;
|
178 | isByteLength(options: ExpressValidator.Options.MinMaxOptions): Validator;
|
179 | |
180 |
|
181 |
|
182 |
|
183 | isUUID(version?: UUIDVersion): Validator;
|
184 | |
185 |
|
186 |
|
187 | isMongoId(): Validator;
|
188 | isDate(): Validator;
|
189 | |
190 |
|
191 |
|
192 | isAfter(date?: Date): Validator;
|
193 | |
194 |
|
195 |
|
196 | isBefore(date?: Date): Validator;
|
197 | isIn(options: string | string[]): Validator;
|
198 | isCreditCard(): Validator;
|
199 | isISIN(): Validator;
|
200 | |
201 |
|
202 |
|
203 |
|
204 | isISBN(version?: number): Validator;
|
205 | |
206 |
|
207 |
|
208 |
|
209 | isISSN(options?: ExpressValidator.Options.IsISSNOptions): Validator
|
210 | isMobilePhone(locale: MobilePhoneLocal): Validator;
|
211 | isCurrency(options: ExpressValidator.Options.IsCurrencyOptions): Validator;
|
212 | |
213 |
|
214 |
|
215 | isISO8601(): Validator;
|
216 | |
217 |
|
218 |
|
219 | isBase64(): Validator;
|
220 | |
221 |
|
222 |
|
223 | isDataURI(): Validator;
|
224 | isWhitelisted(chars: string | string[]): Validator;
|
225 |
|
226 |
|
227 |
|
228 |
|
229 | equals(equals: any): Validator;
|
230 | contains(str: string): Validator;
|
231 | matches(pattern: RegExp | string, modifiers?: string): Validator;
|
232 |
|
233 |
|
234 |
|
235 |
|
236 | notEmpty(): Validator;
|
237 | len(options: ExpressValidator.Options.MinMaxOptions): Validator;
|
238 | optional(options?: ExpressValidator.Options.OptionalOptions): Validator;
|
239 | withMessage(message: string): Validator;
|
240 | }
|
241 |
|
242 | interface Sanitizer {
|
243 | |
244 |
|
245 |
|
246 | toDate(): Sanitizer;
|
247 | |
248 |
|
249 |
|
250 | toFloat(): Sanitizer;
|
251 | |
252 |
|
253 |
|
254 | toInt(radix?: number): Sanitizer;
|
255 | |
256 |
|
257 |
|
258 |
|
259 |
|
260 | toBoolean(strict?: boolean): Sanitizer;
|
261 | |
262 |
|
263 |
|
264 |
|
265 | trim(chars: string): Sanitizer;
|
266 | ltrim(chars: string): Sanitizer;
|
267 | rtrim(chars: string): Sanitizer;
|
268 | |
269 |
|
270 |
|
271 |
|
272 |
|
273 | stripLow(keep_new_lines?: boolean): Sanitizer;
|
274 | |
275 |
|
276 |
|
277 | escape(): Sanitizer;
|
278 | |
279 |
|
280 |
|
281 | unescape(): Sanitizer;
|
282 | blacklist(chars: string): Sanitizer;
|
283 | whitelist(chars: string): Sanitizer;
|
284 |
|
285 | normalizeEmail(options?: ExpressValidator.Options.NormalizeEmailOptions): Sanitizer;
|
286 | }
|
287 |
|
288 | interface MappedError {
|
289 | param: string;
|
290 | msg: string;
|
291 | value: string;
|
292 | }
|
293 | }
|
294 |
|
295 | declare namespace ExpressValidator.Options {
|
296 |
|
297 | export interface ExpressValidatorOptions {
|
298 | customValidators?: { [validatorName: string]: (...value: any[]) => boolean }
|
299 | customSanitizers?: { [sanitizername: string]: (value: any) => any }
|
300 | errorFormatter?: (param: string, msg: string, value: any) => {param: string, msg: string, value: any}
|
301 | }
|
302 |
|
303 |
|
304 | interface ValidatorSchemaOptions {
|
305 | options?: any[]
|
306 | errorMessage?: string
|
307 | }
|
308 |
|
309 | interface ValidationSchemaParamOptions {
|
310 | in?: Location
|
311 | errorMessage?: string
|
312 |
|
313 |
|
314 | optional?: boolean | { checkFalsy: boolean }
|
315 | notEmpty?: boolean | { errorMessage: string }
|
316 | len?: ValidatorSchemaOptions
|
317 |
|
318 |
|
319 | isEmail?: ValidatorSchemaOptions
|
320 | isURL?: ValidatorSchemaOptions
|
321 | isMACAddress?: ValidatorSchemaOptions
|
322 | isIP?: ValidatorSchemaOptions
|
323 | isFQDN?: ValidatorSchemaOptions
|
324 | isBoolean?: ValidatorSchemaOptions
|
325 | isAlpha?: ValidatorSchemaOptions
|
326 | isAlphanumeric?: ValidatorSchemaOptions
|
327 | isNumeric?: ValidatorSchemaOptions
|
328 | isLowercase?: ValidatorSchemaOptions
|
329 | isUppercase?: ValidatorSchemaOptions
|
330 | isAscii?: ValidatorSchemaOptions
|
331 | isFullWidth?: ValidatorSchemaOptions
|
332 | isHalfWidth?: ValidatorSchemaOptions
|
333 | isVariableWidth?: ValidatorSchemaOptions
|
334 | isMultibyte?: ValidatorSchemaOptions
|
335 | isSurrogatePair?: ValidatorSchemaOptions
|
336 | isInt?: ValidatorSchemaOptions
|
337 | isFloat?: ValidatorSchemaOptions
|
338 | isDecimal?: ValidatorSchemaOptions
|
339 | isHexadecimal?: ValidatorSchemaOptions
|
340 | isDivisibleBy?: ValidatorSchemaOptions
|
341 | isHexColor?: ValidatorSchemaOptions
|
342 | isMD5?: ValidatorSchemaOptions
|
343 | isJSON?: ValidatorSchemaOptions
|
344 | isEmpty?: ValidatorSchemaOptions
|
345 | isLength?: ValidatorSchemaOptions
|
346 | isByteLength?: ValidatorSchemaOptions
|
347 | isUUID?: ValidatorSchemaOptions
|
348 | isMongoId?: ValidatorSchemaOptions
|
349 | isDate?: ValidatorSchemaOptions
|
350 | isAfter?: ValidatorSchemaOptions
|
351 | isBefore?: ValidatorSchemaOptions
|
352 | isIn?: ValidatorSchemaOptions
|
353 | isCreditCard?: ValidatorSchemaOptions
|
354 | isISIN?: ValidatorSchemaOptions
|
355 | isISBN?: ValidatorSchemaOptions
|
356 | isISSN?: ValidatorSchemaOptions
|
357 | isMobilePhone?: ValidatorSchemaOptions
|
358 | isCurrency?: ValidatorSchemaOptions
|
359 | isISO8601?: ValidatorSchemaOptions
|
360 | isBase64?: ValidatorSchemaOptions
|
361 | isDataURI?: ValidatorSchemaOptions
|
362 | isWhitelisted?: ValidatorSchemaOptions
|
363 |
|
364 |
|
365 | equals?: ValidatorSchemaOptions
|
366 | contains?: ValidatorSchemaOptions
|
367 | matches?: ValidatorSchemaOptions
|
368 | }
|
369 |
|
370 |
|
371 |
|
372 |
|
373 | interface MinMaxOptions {
|
374 | min?: number;
|
375 | max?: number;
|
376 | }
|
377 |
|
378 | interface MinMaxExtendedOptions extends MinMaxOptions {
|
379 | lt?: number;
|
380 | gt?: number;
|
381 | }
|
382 |
|
383 | interface IsIntOptions extends MinMaxExtendedOptions {
|
384 | allow_leading_zeroes?: boolean;
|
385 | }
|
386 |
|
387 | |
388 |
|
389 |
|
390 |
|
391 |
|
392 |
|
393 |
|
394 |
|
395 |
|
396 | interface IsEmailOptions {
|
397 | allow_display_name?: boolean;
|
398 | allow_utf8_local_part?: boolean;
|
399 | require_tld?: boolean;
|
400 | }
|
401 |
|
402 | |
403 |
|
404 |
|
405 |
|
406 |
|
407 |
|
408 |
|
409 |
|
410 |
|
411 |
|
412 |
|
413 |
|
414 |
|
415 |
|
416 |
|
417 | interface IsURLOptions {
|
418 | protocols?: URLProtocol[];
|
419 | require_tld?: boolean;
|
420 | require_protocol?: boolean;
|
421 | require_host?: boolean;
|
422 | require_valid_protocol?: boolean;
|
423 | allow_underscores?: boolean;
|
424 | host_whitelist?: (string | RegExp)[];
|
425 | host_blacklist?: (string | RegExp)[];
|
426 | allow_trailing_dot?: boolean;
|
427 | allow_protocol_relative_urls?: boolean;
|
428 | }
|
429 |
|
430 | |
431 |
|
432 |
|
433 |
|
434 |
|
435 |
|
436 |
|
437 |
|
438 | interface IsFQDNOptions {
|
439 | require_tld?: boolean;
|
440 | allow_underscores?: boolean;
|
441 | allow_trailing_dot?: boolean;
|
442 | }
|
443 |
|
444 | |
445 |
|
446 |
|
447 |
|
448 |
|
449 |
|
450 |
|
451 | interface IsISSNOptions {
|
452 | case_sensitive?: boolean
|
453 | require_hyphen?: boolean
|
454 | }
|
455 |
|
456 | |
457 |
|
458 |
|
459 |
|
460 |
|
461 |
|
462 |
|
463 |
|
464 |
|
465 |
|
466 |
|
467 |
|
468 |
|
469 |
|
470 |
|
471 |
|
472 |
|
473 | interface IsCurrencyOptions {
|
474 | symbol?: string;
|
475 | require_symbol?: boolean;
|
476 | allow_space_after_symbol?: boolean;
|
477 | symbol_after_digits?: boolean;
|
478 | allow_negatives?: boolean;
|
479 | parens_for_negatives?: boolean;
|
480 | negative_sign_before_digits?: boolean;
|
481 | negative_sign_after_digits?: boolean;
|
482 | allow_negative_sign_placeholder?: boolean;
|
483 | thousands_separator?: string;
|
484 | decimal_separator?: string;
|
485 | allow_space_after_digits?: boolean;
|
486 | }
|
487 |
|
488 | interface OptionalOptions {
|
489 | checkFalsy?: boolean;
|
490 | }
|
491 |
|
492 |
|
493 |
|
494 |
|
495 | |
496 |
|
497 |
|
498 |
|
499 |
|
500 |
|
501 |
|
502 |
|
503 |
|
504 |
|
505 |
|
506 |
|
507 |
|
508 |
|
509 |
|
510 |
|
511 | interface NormalizeEmailOptions {
|
512 | all_lowercase?: boolean
|
513 | gmail_lowercase?: boolean
|
514 | gmail_remove_dots?: boolean
|
515 | gmail_remove_subaddress?: boolean
|
516 | gmail_convert_googlemaildotcom?: boolean
|
517 | outlookdotcom_lowercase?: boolean
|
518 | outlookdotcom_remove_subaddress?: boolean
|
519 | yahoo_lowercase?: boolean
|
520 | yahoo_remove_subaddress?: boolean
|
521 | icloud_lowercase?: boolean
|
522 | icloud_remove_subaddress?: boolean
|
523 | }
|
524 | }
|