UNPKG

894 BJavaScriptView Raw
1const check = require('../check/check');
2
3module.exports = (field, location, message, contexts, { validators, sanitizers }) => {
4 const chain = check([field], Array.isArray(location) ? location : [location], message);
5 contexts.push(chain._context);
6
7 chain.notEmpty = () => chain.isLength({ min: 1 });
8 chain.len = chain.isLength;
9
10 Object.keys(validators).forEach(name => {
11 chain[name] = (...options) => {
12 chain._context.validators.push({
13 options,
14 custom: true,
15 negated: chain._context.negateNext,
16 validator: validators[name]
17 });
18 chain._context.negateNext = false;
19 return chain;
20 };
21 });
22
23 Object.keys(sanitizers).forEach(name => {
24 chain[name] = (...options) => {
25 chain._context.sanitizers.push({
26 options,
27 sanitizer: sanitizers[name]
28 });
29 return chain;
30 };
31 });
32
33 return chain;
34};
\No newline at end of file