UNPKG

1.2 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.sanitize = void 0;
4const chain_1 = require("../chain");
5const utils_1 = require("../utils");
6const context_builder_1 = require("../context-builder");
7let hasNotified = false;
8function sanitize(fields = '', locations = []) {
9 if (!hasNotified) {
10 hasNotified = true;
11 console.warn('express-validator: sanitize(), sanitizeBody() and other sanitization-only middlewares ' +
12 'have been deprecated.\nPlease use check(), body() and others instead, which must offer ' +
13 'the same API, and more.');
14 }
15 const builder = new context_builder_1.ContextBuilder()
16 .setFields(Array.isArray(fields) ? fields : [fields])
17 .setLocations(locations);
18 const runner = new chain_1.ContextRunnerImpl(builder);
19 const middleware = async (req, _res, next) => {
20 try {
21 await runner.run(req);
22 next();
23 }
24 catch (e) {
25 next(e);
26 }
27 };
28 return Object.assign(middleware, utils_1.bindAll(runner), utils_1.bindAll(new chain_1.SanitizersImpl(builder, middleware)), { builder });
29}
30exports.sanitize = sanitize;