mohamedGamalAbuGalala / validation-helpers

Validation liberary helps to validate any request

Home Page:https://www.npmjs.com/package/validation-helpers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

Usage

const { errors, isValid } = validationHelpers(value, rules);

rules need to be like

new Builder().required().isMember(["foo", "bla", "hi"]).value;

Example

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']

TODO

  1. Write readable usage example.
  2. Write Unit test for all cases.
  3. Integrate with CI.

About

Validation liberary helps to validate any request

https://www.npmjs.com/package/validation-helpers

License:MIT License


Languages

Language:JavaScript 100.0%