UNPKG

cheke

Version:

Express request validator with object's style response body and inspired by Laravel's Validator

1 lines 375 B
const hasErrors=require("./hasErrors"),requests=["params","body","query"],cheke=({errors:b="errors",...a})=>async(c,d,e)=>{if("string"!=typeof b)throw Error("errors should be a string");let f;return await new Promise(b=>{requests.forEach(async d=>{f||a[d]&&(f=await hasErrors({data:c[d],reqRules:a[d],path:d}),b())})}),f?d.status(400).json({[b]:f}):e()};module.exports=cheke;