npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

validio

v0.1.7

Published

A Node.js type less schema validation. Also, Validio can run as Synchronous and as Promise implementation too

Downloads

14

Readme

Npm version

Validio

A Node.js type less schema validation for model, objects and data formats. Also, Validio can run as Synchronous and as Promise implementation too, see more at Validio Npm.

How to install

npm install --save validio

How to test a specific suite

mocha -w -g "Extras arguments validating parsing extras content"

How to use it

First we need to generate the schema to validate an object where name is a string which max length is 20, and field age is an int which max value is 100:

var validio = require('validio')
validio.parse('req name 20, lastName 20, age int 100');

It will generate the next schema

{
    name: {
        validators: {
            isString: {},
            isLength: {
                args: {length: 20}
            }
        },
        required: true,
        length: 20,
        type: 'string'
    },
    lastName: {
        validators: {
            isString: {},
            isLength: {
                args: {length: 20}
            }
        },
        length: 20,
        type: 'string'
    },
    age: {
        validators: {
            isInt: {
                args: {max: 100}
            }
        },
        type: 'int'
    }
}

In this case we will use the Person class, and will validate object instances using the schema:

function Person(name, email, age, phone, birth, height) {
    this.name = name;
    this.email = email;
    this.age = age;
    this.phone = phone;
    this.birth = birth;
    this.height = height;
};

Then we can validate the object using the schema, in this case it will validate the name and age because those are the only fields that appears on the schema.

var person = new Person('Joe', '[email protected]', 45);

var result = validio.validate(schema, person);

if(!result.isValid) {
    console.log(result.errors.length == 1 ? 'There is an error:' : 'There are many errors:');
    for(error in result.errors)
        console.log(error);
}
else
    console.log('Validation succeeded');

Validio as Promise

We can use Validio as Promise implementation, in the next sample we will use the same schema we build before.

var validio = require('validio').aspromise;

var schema = validio.parse('name 20, age int 100');
var person = new Person('Joe', '[email protected]', 45);


validio.validate(schema, person)
.then(function(result) {
    console.log('Validation succeeded');
})
.catch(function(result) {
    for(error of result.errors)
        console.log(error);
});

New Features

  • Adding support for Password, Picture formats
  • Adding support for ArrayTypes
  • Fully supporting Basic ArrayType
  • Fully supporting Schema Relations with ArrayType

Disclaimer

Strictly supporting packages up to next versions: