Validation helpers makes you validate your body of request or any value you want with a simple set of rules with the help of Validator and other simple packages.
const { errors, isValid } = validationHelpers(value, rules);
rules
need to be like
new Builder().required().isMember(["foo", "bla", "hi"]).value;
const { errors, isValid } =
validationHelpers('hello',
new Builder()
.required()
.isMember(['foo', 'bla', 'hi'],'Not a valid member')
.value;
);
This will throw an error for isMember rule with a simple message 'Not a valid member'
.
Or the old way rules can be written with array of objects.
[
{ type: Rules.REQUIRED },
{ type: Rules.IS_MEMBER, array: ["foo", "bla", "hi"] }
];
type
must be a valid type from validationHelpers.Types every type may have a second property must be passed like
{ type: Rules.IS_MEMBER, array: ['foo', 'bla', 'hi']
- Write readable usage example.
- Write Unit test for all cases.
- Integrate with CI.