forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
express-validator.d.ts
245 lines (220 loc) · 6.67 KB
/
express-validator.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
// Type definitions for express-validator 2.20.4
// Project: https://github.com/ctavan/express-validator
// Definitions by: Nathan Ridley <https://github.com/axefrog/>, Jonathan Häberle <http://dreampulse.de>, Peter Harris <https://github.com/codeanimal/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference path="../express/express.d.ts" />
/// <reference path="../bluebird/bluebird.d.ts" />
// Add RequestValidation Interface on to Express's Request Interface.
declare namespace Express {
interface Request extends ExpressValidator.RequestValidation {}
}
// External express-validator module.
declare module "express-validator" {
import express = require('express');
/**
*
* @middlewareOptions see: https://github.com/ctavan/express-validator#middleware-options
*/
function ExpressValidator(middlewareOptions?:any):express.RequestHandler;
export = ExpressValidator;
}
// Internal Module.
declare namespace ExpressValidator {
export interface ValidationError {
msg: string;
param: string;
}
interface ValidatorFunction { (item: string | {}, message?: string): Validator; }
interface ValidatorExtraFunction extends ValidatorFunction { (matchIndex: number, message?: string): Validator; }
interface SanitizerFunction { (item: string): Sanitizer; }
interface Dictionary<T> { [key: string]: T; }
export interface RequestValidation {
assert: ValidatorExtraFunction;
validate: ValidatorExtraFunction;
check: ValidatorExtraFunction;
checkBody: ValidatorFunction;
checkFiles: ValidatorFunction;
checkHeaders: ValidatorFunction;
checkParams: ValidatorFunction;
checkQuery: ValidatorFunction;
filter: SanitizerFunction;
sanitize: SanitizerFunction;
sanitizeBody: SanitizerFunction;
sanitizeQuery: SanitizerFunction;
sanitizeParams: SanitizerFunction;
sanitizeHeaders: SanitizerFunction;
onValidationError(errback: (msg: string) => void): void;
validationErrors(mapped?: boolean): Dictionary<MappedError> | MappedError[];
validationErrors<T>(mapped?: boolean): Dictionary<T> | T[];
asyncValidationErrors(mapped?: boolean): Promise<MappedError[] | Dictionary<MappedError>>;
asyncValidationErrors<T>(mapped?: boolean): Promise<T[] | Dictionary<T>>;
}
export interface Validator {
/**
* Alias for regex()
*/
is(): Validator;
/**
* Alias for notRegex()
*/
not(): Validator;
isEmail(options?:{}): Validator;
/**
* Accepts http, https, ftp
*/
isURL(): Validator;
isFQDN(options?: MinMaxOptions): Validator;
/**
* Combines isIPv4 and isIPv6
*/
isIP(): Validator;
isIPv4(): Validator;
isIPv6(): Validator;
isMACAddress(): Validator;
isISBN(version?: number): Validator;
isISIN(): Validator;
isISO8601(): Validator;
isMobilePhone(locale: string): Validator;
isMongoId(): Validator;
isMultibyte(): Validator;
isAlpha(locale?: string): Validator;
isAlphanumeric(locale?: string): Validator;
isAscii(): Validator;
isBase64(): Validator;
isBoolean(): Validator;
isByteLength(options: MinMaxOptions): Validator;
isCurrency(options: {}): Validator;
isDataURI(): Validator;
isDivisibleBy(num: number): Validator;
isNumeric(): Validator;
isHexadecimal(): Validator;
/**
* Accepts valid hexcolors with or without # prefix
*/
isHexColor(): Validator;
/**
* isNumeric accepts zero padded numbers, e.g. '001', isInt doesn't
*/
isInt(options?: MinMaxOptions): Validator;
isLowercase(): Validator;
isUppercase(): Validator;
isDecimal(): Validator;
/**
* Alias for isDecimal
*/
isFloat(): Validator;
isFullWidth(): Validator;
isHalfWidth(): Validator;
isVariableWidth(): Validator;
/**
* Check if length is 0
*/
isNull(): Validator;
/**
* Not just whitespace (input.trim().length !== 0)
*/
notEmpty(): Validator;
equals(equals:any): Validator;
contains(str:string): Validator;
/**
* Usage: matches(/[a-z]/i) or matches('[a-z]','i')
*/
matches(pattern:string, modifiers?:string): Validator;
matches(pattern: RegExp): Validator;
/**
* max is optional
*/
len(min:number, max?:number): Validator;
/**
* Version can be 3, 4 or 5 or empty, see http://en.wikipedia.org/wiki/Universally_unique_identifier
*/
isUUID(version?:number): Validator;
/**
* Alias for isUUID(3)
*/
isUUIDv3(): Validator;
/**
* Alias for isUUID(4)
*/
isUUIDv4(): Validator;
/**
* Alias for isUUID(5)
*/
isUUIDv5(): Validator;
/**
* Uses Date.parse() - regex is probably a better choice
*/
isDate(): Validator;
/**
* Argument is optional and defaults to today. Comparison is non-inclusive
*/
isAfter(date?:Date): Validator;
/**
* Argument is optional and defaults to today. Comparison is non-inclusive
*/
isBefore(date?:Date): Validator;
isIn(options:string): Validator;
isIn(options:string[]): Validator;
notIn(options:string): Validator;
notIn(options:string[]): Validator;
max(val:string): Validator;
min(val:string): Validator;
isJSON(): Validator;
isLength(options: MinMaxOptions): Validator;
isWhitelisted(chars: string): Validator;
/**
* Will work against Visa, MasterCard, American Express, Discover, Diners Club, and JCB card numbering formats
*/
isCreditCard(): Validator;
/**
* Check an input only when the input exists
*/
isSurrogatePar(): Validator;
optional(options?: { checkFalsy?: boolean }): Validator;
withMessage(message: string): Validator;
}
interface Sanitizer {
/**
* Trim optional `chars`, default is to trim whitespace (\r\n\t )
*/
trim(...chars:string[]): Sanitizer;
ltrim(...chars:string[]): Sanitizer;
rtrim(...chars:string[]): Sanitizer;
stripLow(keep_new_lines?: boolean): Sanitizer;
toFloat(): Sanitizer;
toInt(radix?: number): Sanitizer;
/**
* True unless str = '0', 'false', or str.length == 0. In strict mode only '1' and 'true' return true.
*/
toBoolean(strict?: boolean): Sanitizer;
/**
* Convert the input string to a date, or null if the input is not a date.
*/
toDate(): Sanitizer;
/**
* Escape &, <, >, and "
*/
escape(): Sanitizer;
/**
* Replaces HTML encoded entities with <, >, &, ', " and /.
*/
unescape(): Sanitizer;
blacklist(chars: string): Sanitizer;
blacklist(chars: string[]): Sanitizer;
whitelist(chars: string): Sanitizer;
whitelist(chars: string[]): Sanitizer;
normalizeEmail(options?: { lowercase?: boolean; remove_dots?: boolean; remove_extensions?: boolean }): Sanitizer;
/**
* !!! XSS sanitization was removed from the library (see: https://github.com/chriso/validator.js#xss-sanitization)
*/
}
interface MappedError {
param: string;
msg: string;
value: string;
}
interface MinMaxOptions {
min?: number;
max?: number;
}
}