forked from express-validator/express-validator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
150 lines (133 loc) · 5.22 KB
/
index.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
// Type definitions for express-validator 3.0.0
// Project: https://github.com/express-validator/express-validator
// Definitions by: Ayman Nedjmeddine <https://github.com/IOAyman>, Nathan Ridley <https://github.com/axefrog/>, Jonathan Häberle <http://dreampulse.de>, Peter Harris <https://github.com/codeanimal/>, Kacper Polak <[email protected]>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
///<reference types="express"/>
import * as express from 'express';
import { Location } from './check/location';
import {
Result,
Validator as BaseValidator,
ValidatorOptions
} from './check';
import { Sanitizer as BaseSanitizer } from './filter'
// Add RequestValidation Interface on to Express's Request Interface.
declare global {
namespace Express {
interface Request extends ExpressValidator.RequestValidation { }
}
}
export as namespace ExpressValidator;
interface ExpressValidatorOptions {
errorFormatter?(param: string, msg: string, value: any, location: Location): any,
customSanitizers?: Record<string, (...value: any[]) => any>,
customValidators?: Record<string, (...value: any[]) => boolean | Promise<any>>,
}
declare function ExpressValidator(options?: ExpressValidatorOptions): express.RequestHandler;
export = ExpressValidator;
// Internal Module.
declare namespace ExpressValidator {
export type ValidationSchema = Record<
string,
ValidationSchemaParamOptions | { [custom: string]: ValidatorSchemaOptions }
>;
interface ValidatorSchemaOptions {
options?: any[]
errorMessage?: any
}
interface ValidationSchemaParamOptions {
in?: Location
errorMessage?: any
// Additional ValidatorChain.prototype.* validators
optional?: boolean | ValidatorOptions.OptionalOptions
notEmpty?: boolean | { errorMessage: string }
len?: ValidatorSchemaOptions
// exported from validator.js
isEmail?: ValidatorSchemaOptions
isURL?: ValidatorSchemaOptions
isMACAddress?: ValidatorSchemaOptions
isIP?: ValidatorSchemaOptions
isFQDN?: ValidatorSchemaOptions
isBoolean?: ValidatorSchemaOptions
isAlpha?: ValidatorSchemaOptions
isAlphanumeric?: ValidatorSchemaOptions
isNumeric?: ValidatorSchemaOptions
isLowercase?: ValidatorSchemaOptions
isUppercase?: ValidatorSchemaOptions
isAscii?: ValidatorSchemaOptions
isFullWidth?: ValidatorSchemaOptions
isHalfWidth?: ValidatorSchemaOptions
isVariableWidth?: ValidatorSchemaOptions
isHash?: ValidationSchemaParamOptions
isMultibyte?: ValidatorSchemaOptions
isSurrogatePair?: ValidatorSchemaOptions
isInt?: ValidatorSchemaOptions
isFloat?: ValidatorSchemaOptions
isDecimal?: ValidatorSchemaOptions
isHexadecimal?: ValidatorSchemaOptions
isDivisibleBy?: ValidatorSchemaOptions
isHexColor?: ValidatorSchemaOptions
isMD5?: ValidatorSchemaOptions
isJSON?: ValidatorSchemaOptions
isLatLong?: ValidationSchemaParamOptions
isEmpty?: ValidatorSchemaOptions
isLength?: ValidatorSchemaOptions
isByteLength?: ValidatorSchemaOptions
isPostalCode?: ValidationSchemaParamOptions
isUUID?: ValidatorSchemaOptions
isMongoId?: ValidatorSchemaOptions
isAfter?: ValidatorSchemaOptions
isBefore?: ValidatorSchemaOptions
isIn?: ValidatorSchemaOptions
isCreditCard?: ValidatorSchemaOptions
isISIN?: ValidatorSchemaOptions
isISRC?: ValidatorSchemaOptions
isISBN?: ValidatorSchemaOptions
isISSN?: ValidatorSchemaOptions
isMimeType?: ValidatorSchemaOptions
isMobilePhone?: ValidatorSchemaOptions
isPort?: ValidatorSchemaOptions
isCurrency?: ValidatorSchemaOptions
isISO31661Alpha2?: ValidatorSchemaOptions
isISO8601?: ValidatorSchemaOptions
isBase64?: ValidatorSchemaOptions
isDataURI?: ValidatorSchemaOptions
isWhitelisted?: ValidatorSchemaOptions
// Additional Validators provided by validator.js
equals?: ValidatorSchemaOptions
contains?: ValidatorSchemaOptions
matches?: ValidatorSchemaOptions
}
interface ValidatorFunction {
(item: string | string[] | number, message?: any): Validator;
(schema: {}): Validator;
}
interface SanitizerFunction { (item: string): Sanitizer; }
export interface RequestValidation {
assert: ValidatorFunction;
validate: ValidatorFunction;
check: ValidatorFunction;
checkBody: ValidatorFunction;
checkCookies: ValidatorFunction;
checkHeaders: ValidatorFunction;
checkParams: ValidatorFunction;
checkQuery: ValidatorFunction;
filter: SanitizerFunction;
sanitize: SanitizerFunction;
sanitizeBody: SanitizerFunction;
sanitizeQuery: SanitizerFunction;
sanitizeParams: SanitizerFunction;
sanitizeHeaders: SanitizerFunction;
sanitizeCookies: SanitizerFunction;
validationErrors(mapped?: boolean): Record<string, any> | any[];
validationErrors<T>(mapped?: boolean): Record<string, T> | T[];
asyncValidationErrors(mapped?: boolean): Promise<any[] | Record<string, any>>;
asyncValidationErrors<T>(mapped?: boolean): Promise<T[] | Record<string, T>>;
getValidationResult(): Promise<Result>
}
export interface Validator extends BaseValidator, Sanitizer {
notEmpty(): this;
len(options: ValidatorOptions.MinMaxOptions): this;
}
export interface Sanitizer extends BaseSanitizer {}
}