index.d.ts 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. // Type definitions for express-validator 3.0.0
  2. // Project: https://github.com/express-validator/express-validator
  3. // 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 <kacper@hypequality.com>
  4. // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
  5. ///<reference types="express"/>
  6. import * as express from 'express';
  7. import { Location } from './check/location';
  8. import {
  9. Result,
  10. Validator as BaseValidator,
  11. ValidatorOptions
  12. } from './check';
  13. import { Sanitizer as BaseSanitizer } from './filter'
  14. // Add RequestValidation Interface on to Express's Request Interface.
  15. declare global {
  16. namespace Express {
  17. interface Request extends ExpressValidator.RequestValidation { }
  18. }
  19. }
  20. export as namespace ExpressValidator;
  21. interface ExpressValidatorOptions {
  22. errorFormatter?(param: string, msg: string, value: any, location: Location): any,
  23. customSanitizers?: Record<string, (...value: any[]) => any>,
  24. customValidators?: Record<string, (...value: any[]) => boolean | Promise<any>>,
  25. }
  26. declare function ExpressValidator(options?: ExpressValidatorOptions): express.RequestHandler;
  27. export = ExpressValidator;
  28. // Internal Module.
  29. declare namespace ExpressValidator {
  30. export type ValidationSchema = Record<
  31. string,
  32. ValidationSchemaParamOptions | { [custom: string]: ValidatorSchemaOptions }
  33. >;
  34. interface ValidatorSchemaOptions {
  35. options?: any[]
  36. errorMessage?: any
  37. }
  38. interface ValidationSchemaParamOptions {
  39. in?: Location
  40. errorMessage?: any
  41. // Additional ValidatorChain.prototype.* validators
  42. optional?: boolean | ValidatorOptions.OptionalOptions
  43. notEmpty?: boolean | { errorMessage: string }
  44. len?: ValidatorSchemaOptions
  45. // exported from validator.js
  46. isEmail?: ValidatorSchemaOptions
  47. isURL?: ValidatorSchemaOptions
  48. isMACAddress?: ValidatorSchemaOptions
  49. isIP?: ValidatorSchemaOptions
  50. isFQDN?: ValidatorSchemaOptions
  51. isBoolean?: ValidatorSchemaOptions
  52. isAlpha?: ValidatorSchemaOptions
  53. isAlphanumeric?: ValidatorSchemaOptions
  54. isNumeric?: ValidatorSchemaOptions
  55. isLowercase?: ValidatorSchemaOptions
  56. isUppercase?: ValidatorSchemaOptions
  57. isAscii?: ValidatorSchemaOptions
  58. isFullWidth?: ValidatorSchemaOptions
  59. isHalfWidth?: ValidatorSchemaOptions
  60. isVariableWidth?: ValidatorSchemaOptions
  61. isHash?: ValidationSchemaParamOptions
  62. isMultibyte?: ValidatorSchemaOptions
  63. isSurrogatePair?: ValidatorSchemaOptions
  64. isInt?: ValidatorSchemaOptions
  65. isFloat?: ValidatorSchemaOptions
  66. isDecimal?: ValidatorSchemaOptions
  67. isHexadecimal?: ValidatorSchemaOptions
  68. isDivisibleBy?: ValidatorSchemaOptions
  69. isHexColor?: ValidatorSchemaOptions
  70. isMD5?: ValidatorSchemaOptions
  71. isJSON?: ValidatorSchemaOptions
  72. isLatLong?: ValidationSchemaParamOptions
  73. isEmpty?: ValidatorSchemaOptions
  74. isLength?: ValidatorSchemaOptions
  75. isByteLength?: ValidatorSchemaOptions
  76. isPostalCode?: ValidationSchemaParamOptions
  77. isUUID?: ValidatorSchemaOptions
  78. isMongoId?: ValidatorSchemaOptions
  79. isAfter?: ValidatorSchemaOptions
  80. isBefore?: ValidatorSchemaOptions
  81. isIn?: ValidatorSchemaOptions
  82. isCreditCard?: ValidatorSchemaOptions
  83. isISIN?: ValidatorSchemaOptions
  84. isISRC?: ValidatorSchemaOptions
  85. isISBN?: ValidatorSchemaOptions
  86. isISSN?: ValidatorSchemaOptions
  87. isMimeType?: ValidatorSchemaOptions
  88. isMobilePhone?: ValidatorSchemaOptions
  89. isPort?: ValidatorSchemaOptions
  90. isCurrency?: ValidatorSchemaOptions
  91. isISO31661Alpha2?: ValidatorSchemaOptions
  92. isISO8601?: ValidatorSchemaOptions
  93. isBase64?: ValidatorSchemaOptions
  94. isDataURI?: ValidatorSchemaOptions
  95. isWhitelisted?: ValidatorSchemaOptions
  96. // Additional Validators provided by validator.js
  97. equals?: ValidatorSchemaOptions
  98. contains?: ValidatorSchemaOptions
  99. matches?: ValidatorSchemaOptions
  100. }
  101. interface ValidatorFunction {
  102. (item: string | string[] | number, message?: any): Validator;
  103. (schema: {}): Validator;
  104. }
  105. interface SanitizerFunction { (item: string): Sanitizer; }
  106. export interface RequestValidation {
  107. assert: ValidatorFunction;
  108. validate: ValidatorFunction;
  109. check: ValidatorFunction;
  110. checkBody: ValidatorFunction;
  111. checkCookies: ValidatorFunction;
  112. checkHeaders: ValidatorFunction;
  113. checkParams: ValidatorFunction;
  114. checkQuery: ValidatorFunction;
  115. filter: SanitizerFunction;
  116. sanitize: SanitizerFunction;
  117. sanitizeBody: SanitizerFunction;
  118. sanitizeQuery: SanitizerFunction;
  119. sanitizeParams: SanitizerFunction;
  120. sanitizeHeaders: SanitizerFunction;
  121. sanitizeCookies: SanitizerFunction;
  122. validationErrors(mapped?: boolean): Record<string, any> | any[];
  123. validationErrors<T>(mapped?: boolean): Record<string, T> | T[];
  124. asyncValidationErrors(mapped?: boolean): Promise<any[] | Record<string, any>>;
  125. asyncValidationErrors<T>(mapped?: boolean): Promise<T[] | Record<string, T>>;
  126. getValidationResult(): Promise<Result>
  127. }
  128. export interface Validator extends BaseValidator, Sanitizer {
  129. notEmpty(): this;
  130. len(options: ValidatorOptions.MinMaxOptions): this;
  131. }
  132. export interface Sanitizer extends BaseSanitizer {}
  133. }