chrisakakay / svv

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

About


Languages

Language:JavaScript 100.0%