Skip to content

wmzy/validate-easy

Repository files navigation

Build Status Coverage Status

Validate Easy

Validate your data easy with pipeline style.

Why

Most existing validation libraries are based on the schema, which makes it so heavy and hard to extend.

  • Tiny and tree-shaking friendly.
  • Easy to extend.
  • Easy to combine with other libraries.
  • Detailed errors.

Install

npm install validate-easy

Usage

import _ from 'lodash';
import * as v from 'validate-easy';

const data = v.v(
  v.required('foo', 'bar', 'baz'),
  v.prop('foo')(v.isNumber, v.lt(10), v.gt(0)),
  v.prop('bar')(_.trim, Number, v.isInt)
)({
  foo: 5,
  bar: ' 4',
  baz: null
})

console.log(data);
// result
// {
//   foo: 5,
//   bar: 4,
//   baz: null
// }

Error Handling

// todo

TODO

  • pipe function
  • build for node and browser
  • async validator

About

(wip) Validate your data easy with pipe style.

Resources

Stars

Watchers

Forks

Packages

No packages published