validation-helpers

1.1.1 • Public • Published

Validation-helpers

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.

Package Sidebar

Install

npm i validation-helpers

Weekly Downloads

2

Version

1.1.1

License

ISC

Unpacked Size

418 kB

Total Files

84

Last publish

Collaborators

  • bugalala