svv

0.3.0 • Public • Published

Simple Value Validator

A small module the validate values easily (opinionated).

Install:

yarn add svv
// or
npm install svv

Usage example:

import { Runner, Item } from 'svv';
 
const validator = new Runner();
 
validator.all([
    new Item('content', property1).required(),
    new Item('category', property2).requiredIf(property1 === 'something')
], { /* options */ })
.then((result) => {
    if (result.valid) {
       // valid
    } else {
       // invalid
       //
       // checking if the error is specific to a field:
       // result.errors.has('content') => boolean // content has errors
       //
       // checking the first error message for a field
       // result.errors.first('content') => 'The content field is required'
    }
});

Homepage

API DOCS v0.2.3

Readme

Keywords

none

Package Sidebar

Install

npm i svv

Weekly Downloads

2

Version

0.3.0

License

MIT

Unpacked Size

5.52 kB

Total Files

3

Last publish

Collaborators

  • chrisakakay