vda-schemas

1.0.0 • Public • Published

VDA

Create schemas to validate data.

Usage

const vda = require('vda-schema');
const validatePerson = vda.validator({
    name: vda.str(3, 20),          // must be a string between 3-20 chars long
     age: vda.optional.int(1, 100) // must be a whole number between 1-100
});

validatePerson({name: "trevor", age: -3}); // false
validatePerson({name: "max"});             // true

Documentation

// check if not undefined
vda.any()

// check if string length is within some range
vda.str(min=0, max=Infinity)

// check if string matches regex or check if the number of matches are within some range
vda.regex(expr, min=1, max=Infinity)

// check if a real number is within some range
vda.num(min=-Infinity, max=Infinity)

// check if an integer is within some range
vda.int(min=-Infinity, max=Infinity)

// check if an object matches a schema
// default handler is for additional properties that weren't defined in the schema
vda.validator(schema, defaultHandler = () => true);

// operators
vda.not(function)
vda.and(...functions)
vda.or(...functions)

Package Sidebar

Install

npm i vda-schemas

Weekly Downloads

0

Version

1.0.0

License

ISC

Unpacked Size

2.66 kB

Total Files

3

Last publish

Collaborators

  • mystical_x9