express-validator
Advanced tools
Comparing version 6.3.0 to 6.3.1
@@ -69,3 +69,5 @@ --- | ||
Adds a custom validator to the current validation chain. | ||
The custom validator may return a promise to indicate an async validation task. In case it's rejected, the field is considered invalid. | ||
The custom validator may return a promise to indicate an async validation task. | ||
- If it's rejected, the field is considered invalid; | ||
- If it's resolved, the field is considered valid **regardless of the returned value**. | ||
@@ -72,0 +74,0 @@ The custom validator may also throw JavaScript exceptions (eg `throw new Error()`) and return falsy values to indicate the field is invalid. |
@@ -19,2 +19,4 @@ --- | ||
> **Note:** if your custom validator returns a promise, it must reject to indicate that the field is invalid. | ||
### Example: checking if e-mail is in use | ||
@@ -21,0 +23,0 @@ ```js |
@@ -9,3 +9,3 @@ { | ||
], | ||
"version": "6.3.0", | ||
"version": "6.3.1", | ||
"homepage": "https://express-validator.github.io", | ||
@@ -36,3 +36,3 @@ "license": "MIT", | ||
"test": "jest", | ||
"lint": "eslint 'src/**/*.ts'", | ||
"lint": "eslint --ignore-path .gitignore 'src/**/*.ts'", | ||
"report-coverage": "cat coverage/lcov.info | coveralls", | ||
@@ -39,0 +39,0 @@ "version": "npm run docs:version -- $npm_package_version && git add -A website" |
@@ -41,5 +41,5 @@ import { ReadonlyContext } from './context'; | ||
} | ||
export declare const contextsSymbol: unique symbol; | ||
export declare const contextsKey = "express-validator#contexts"; | ||
export interface InternalRequest extends Request { | ||
[contextsSymbol]?: ReadonlyContext[]; | ||
[contextsKey]?: ReadonlyContext[]; | ||
} | ||
@@ -46,0 +46,0 @@ export declare type Middleware = (req: Request, res: any, next: (err?: any) => void) => void; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.contextsSymbol = Symbol('express-validator#contexts'); | ||
exports.contextsKey = 'express-validator#contexts'; | ||
class ValidationHalt extends Error { | ||
} | ||
exports.ValidationHalt = ValidationHalt; |
@@ -49,3 +49,3 @@ "use strict"; | ||
const internalReq = req; | ||
internalReq[base_1.contextsSymbol] = (internalReq[base_1.contextsSymbol] || []).concat(context); | ||
internalReq[base_1.contextsKey] = (internalReq[base_1.contextsKey] || []).concat(context); | ||
} | ||
@@ -52,0 +52,0 @@ return context; |
@@ -10,3 +10,3 @@ "use strict"; | ||
const locationFilter = createLocationFilter(options.locations); | ||
return _(internalReq[base_1.contextsSymbol]) | ||
return _(internalReq[base_1.contextsKey]) | ||
.flatMap(fieldExtractor) | ||
@@ -13,0 +13,0 @@ .filter(validityFilter) |
@@ -31,3 +31,3 @@ "use strict"; | ||
})); | ||
req[base_1.contextsSymbol] = (req[base_1.contextsSymbol] || []).concat(surrogateContext); | ||
req[base_1.contextsKey] = (req[base_1.contextsKey] || []).concat(surrogateContext); | ||
try { | ||
@@ -34,0 +34,0 @@ const allErrors = yield Promise.all(promises); |
@@ -46,3 +46,3 @@ "use strict"; | ||
return (req) => { | ||
const contexts = req[base_1.contextsSymbol] || []; | ||
const contexts = req[base_1.contextsKey] || []; | ||
const errors = _.flatMap(contexts, 'errors'); | ||
@@ -49,0 +49,0 @@ return new Result(actualOptions.formatter, errors); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
115984
89