mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
Update to version 2.20.4
Update methods from node-validator (https://github.com/chriso/validator.js) and update express-validator methods to adhere to the latest api.
This commit is contained in:
parent
82a7e73511
commit
4e00b9e8dc
@ -15,19 +15,23 @@ app.post('/:urlparam', function(req: express.Request, res: express.Response) {
|
||||
// Similarly checkParams only checks in req.params (URL params) and
|
||||
// checkQuery only checks req.query (GET params).
|
||||
req.checkBody('postparam', 'Invalid postparam').notEmpty().isInt();
|
||||
req.checkParams('urlparam', 'Invalid urlparam').isAlpha();
|
||||
req.checkParams('urlparam', 'Invalid urlparam').isAlpha().matches(/test?/i).matches('test?', 'i');
|
||||
req.checkQuery('getparam', 'Invalid getparam').isInt();
|
||||
req.checkHeader('testHeader', 'Invalid testHeader').isLowercase().isUppercase();
|
||||
req.checkFiles('testFiles', 'Invalid testFiles').isUrl();
|
||||
|
||||
req.checkHeaders('testHeader', 'Invalid testHeader').isLowercase().isUppercase();
|
||||
req.checkFiles('testFiles', 'Invalid testFiles').isURL();
|
||||
|
||||
// OR assert can be used to check on all 3 types of params.
|
||||
// req.assert('postparam', 'Invalid postparam').notEmpty().isInt();
|
||||
// req.assert('urlparam', 'Invalid urlparam').isAlpha();
|
||||
// req.assert('getparam', 'Invalid getparam').isInt();
|
||||
|
||||
req.sanitize('postparam').toBoolean();
|
||||
req.filter('postparam').toBoolean();
|
||||
req.sanitize('postparam').blacklist('t').blacklist(['<script', '</script>']).whitelist('hello').whitelist(['h', 'e', 'l']);
|
||||
req.sanitizeBody('postvar').trim().stripLow().escape();
|
||||
req.sanitizeQuery('queryvar').toDate();
|
||||
req.sanitizeParams('urlparam').toFloat().toInt().toInt(10);
|
||||
req.sanitizeHeaders('header').normalizeEmail();
|
||||
|
||||
|
||||
var errors = req.validationErrors();
|
||||
var mappedErrors = req.validationErrors(true);
|
||||
|
||||
136
express-validator/express-validator.d.ts
vendored
136
express-validator/express-validator.d.ts
vendored
@ -1,9 +1,10 @@
|
||||
// Type definitions for express-validator 2.9.0
|
||||
// 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>
|
||||
// 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 {
|
||||
@ -31,25 +32,33 @@ declare namespace ExpressValidator {
|
||||
param: string;
|
||||
}
|
||||
|
||||
interface ValidatorFunction { (item: string, message: string): Validator; }
|
||||
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: ValidatorFunction;
|
||||
check: ValidatorFunction;
|
||||
assert: ValidatorExtraFunction;
|
||||
validate: ValidatorExtraFunction;
|
||||
check: ValidatorExtraFunction;
|
||||
checkBody: ValidatorFunction;
|
||||
checkFiles: ValidatorFunction;
|
||||
checkHeader: ValidatorFunction;
|
||||
checkHeaders: ValidatorFunction;
|
||||
checkParams: ValidatorFunction;
|
||||
checkQuery: ValidatorFunction;
|
||||
validate: ValidatorFunction;
|
||||
|
||||
|
||||
filter: SanitizerFunction;
|
||||
sanitize: SanitizerFunction;
|
||||
|
||||
sanitizeBody: SanitizerFunction;
|
||||
sanitizeQuery: SanitizerFunction;
|
||||
sanitizeParams: SanitizerFunction;
|
||||
sanitizeHeaders: SanitizerFunction;
|
||||
|
||||
onValidationError(errback: (msg: string) => void): void;
|
||||
validationErrors(mapped?: boolean): Dictionary<any> | any[];
|
||||
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 {
|
||||
@ -61,12 +70,13 @@ declare namespace ExpressValidator {
|
||||
* Alias for notRegex()
|
||||
*/
|
||||
not(): Validator;
|
||||
isEmail(): Validator;
|
||||
isEmail(options?:{}): Validator;
|
||||
/**
|
||||
* Accepts http, https, ftp
|
||||
*/
|
||||
isUrl(): Validator;
|
||||
|
||||
isURL(): Validator;
|
||||
isFQDN(options?: MinMaxOptions): Validator;
|
||||
|
||||
/**
|
||||
* Combines isIPv4 and isIPv6
|
||||
*/
|
||||
@ -74,8 +84,21 @@ declare namespace ExpressValidator {
|
||||
isIPv4(): Validator;
|
||||
isIPv6(): Validator;
|
||||
isMACAddress(): Validator;
|
||||
isAlpha(): Validator;
|
||||
isAlphanumeric(): 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;
|
||||
/**
|
||||
@ -85,7 +108,7 @@ declare namespace ExpressValidator {
|
||||
/**
|
||||
* isNumeric accepts zero padded numbers, e.g. '001', isInt doesn't
|
||||
*/
|
||||
isInt(): Validator;
|
||||
isInt(options?: MinMaxOptions): Validator;
|
||||
isLowercase(): Validator;
|
||||
isUppercase(): Validator;
|
||||
isDecimal(): Validator;
|
||||
@ -93,10 +116,13 @@ declare namespace ExpressValidator {
|
||||
* Alias for isDecimal
|
||||
*/
|
||||
isFloat(): Validator;
|
||||
isFullWidth(): Validator;
|
||||
isHalfWidth(): Validator;
|
||||
isVariableWidth(): Validator;
|
||||
/**
|
||||
* Check if length is 0
|
||||
*/
|
||||
notNull(): Validator;
|
||||
//notNull(): Validator; // I don't see this in the documentation or code anywhere.
|
||||
isNull(): Validator;
|
||||
/**
|
||||
* Not just whitespace (input.trim().length !== 0)
|
||||
@ -104,12 +130,14 @@ declare namespace ExpressValidator {
|
||||
notEmpty(): Validator;
|
||||
equals(equals:any): Validator;
|
||||
contains(str:string): Validator;
|
||||
notContains(str:string): Validator;
|
||||
//notContains(str:string): Validator; // I don't see this in the documentation or code anywhere.
|
||||
matches(pattern:string, modifiers?:string): Validator;
|
||||
matches(pattern: RegExp): Validator;
|
||||
/**
|
||||
* Usage: regex(/[a-z]/i) or regex('[a-z]','i')
|
||||
*/
|
||||
regex(pattern:string, modifiers:string): Validator;
|
||||
notRegex(pattern:string, modifiers:string): Validator;
|
||||
//regex(pattern:string, modifiers:string): Validator; // I don't see this in the documentation or code anywhere.
|
||||
//notRegex(pattern:string, modifiers:string): Validator; // I don't see this in the documentation or code anywhere.
|
||||
/**
|
||||
* max is optional
|
||||
*/
|
||||
@ -117,7 +145,7 @@ declare namespace ExpressValidator {
|
||||
/**
|
||||
* Version can be 3, 4 or 5 or empty, see http://en.wikipedia.org/wiki/Universally_unique_identifier
|
||||
*/
|
||||
isUUID(version:number): Validator;
|
||||
isUUID(version?:number): Validator;
|
||||
/**
|
||||
* Alias for isUUID(3)
|
||||
*/
|
||||
@ -137,17 +165,20 @@ declare namespace ExpressValidator {
|
||||
/**
|
||||
* Argument is optional and defaults to today. Comparison is non-inclusive
|
||||
*/
|
||||
isAfter(date:Date): Validator;
|
||||
isAfter(date?:Date): Validator;
|
||||
/**
|
||||
* Argument is optional and defaults to today. Comparison is non-inclusive
|
||||
*/
|
||||
isBefore(date:Date): Validator;
|
||||
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);
|
||||
/**
|
||||
* Will work against Visa, MasterCard, American Express, Discover, Diners Club, and JCB card numbering formats
|
||||
*/
|
||||
@ -155,7 +186,10 @@ declare namespace ExpressValidator {
|
||||
/**
|
||||
* Check an input only when the input exists
|
||||
*/
|
||||
optional(): Validator;
|
||||
isSurrogatePar(): Validator;
|
||||
|
||||
optional(options?: { checkFalsy?: boolean }): Validator;
|
||||
withMessage(message: string): Validator;
|
||||
}
|
||||
|
||||
interface Sanitizer {
|
||||
@ -165,40 +199,50 @@ declare namespace ExpressValidator {
|
||||
trim(...chars:string[]): Sanitizer;
|
||||
ltrim(...chars:string[]): Sanitizer;
|
||||
rtrim(...chars:string[]): Sanitizer;
|
||||
ifNull(replace:any): Sanitizer;
|
||||
stripLow(keep_new_lines?: boolean): Sanitizer;
|
||||
//ifNull(replace:any): Sanitizer; // I don't see this in the documentation or code anywhere.
|
||||
toFloat(): Sanitizer;
|
||||
toInt(): Sanitizer;
|
||||
toInt(radix?: number): Sanitizer;
|
||||
/**
|
||||
* True unless str = '0', 'false', or str.length == 0
|
||||
*/
|
||||
toBoolean(): Sanitizer;
|
||||
/**
|
||||
* False unless str = '1' or 'true'
|
||||
*/
|
||||
toBooleanStrict(): Sanitizer;
|
||||
/**
|
||||
* Decode HTML entities
|
||||
* 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;
|
||||
|
||||
entityDecode(): Sanitizer;
|
||||
entityEncode(): Sanitizer;
|
||||
* Convert the input string to a date, or null if the input is not a date.
|
||||
*/
|
||||
toDate(): Sanitizer;
|
||||
|
||||
/**
|
||||
* Escape &, <, >, and "
|
||||
*/
|
||||
escape(): Sanitizer;
|
||||
|
||||
/**
|
||||
* Remove common XSS attack vectors from user-supplied HTML
|
||||
* Replaces HTML encoded entities with <, >, &, ', " and /.
|
||||
*/
|
||||
xss(): Sanitizer;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Remove common XSS attack vectors from images
|
||||
* !!! XSS sanitization was removed from the library (see: https://github.com/chriso/validator.js#xss-sanitization)
|
||||
*/
|
||||
xss(fromImages:boolean): Sanitizer;
|
||||
}
|
||||
|
||||
|
||||
interface MappedError {
|
||||
param: string;
|
||||
msg: string;
|
||||
value: string;
|
||||
}
|
||||
|
||||
interface MinMaxOptions {
|
||||
min?: number;
|
||||
max?: number;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user