Skip to content Skip to sidebar Skip to footer

Any Ways To Simplify Express-validator Middleware In Seperate File

i have project that takes alot of validations using Express-Validator , so each time i need to validate something , i do like that in each file: //Validation and Sanitizing Rules c

Solution 1:

You should flip it around, and use a structure like:

constvalidators= {
    s:isString,
    n:isNumeric,
    ...
};

Then given a rule array validationRules like `['n', 'tr', 'es'], you can do:

validationRules.reduce((rule, acc) => validators[rule].call(acc), param(paramName));

Post a Comment for "Any Ways To Simplify Express-validator Middleware In Seperate File"