[go: up one dir, main page]

Skip to content
/ nosix Public

nosix.js abstracts input validation, making it easier and straighforward for you to validate any type of input.

Notifications You must be signed in to change notification settings

gpestana/nosix

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nosix.js

nosix.js abstracts input validation, making it easier and straighforward for you to validate any type of input.

You run nosix by providing a list of validator functions and an input. nosix will test the input against the validators and return the results.

If the input fails to pass one of more validators, the result will be an object with the validation errors. You can initialize nosix.js with a set of validators and add/remove validators at run time.

By default, Nosix works async. You may also run Nosix in a sync mode.

Instalation

npm install nosix

How to use nosix.js

const nosix = require('nosix');

const fn1 = input => typeof input == 'string' ? true : `${input} must be a string`;
const fn2 = input => input != '' ? true : `${input} cannot be empty`;

const stringInput = "a random string";
const objInput = { random: "object" };

// validate async
nosix.validate(stringInput, [fn1, fn2], err => {
  if(!err) console.log('validation OK'); // validation OK
});

// validate sync
const err = validateSync(objectInput, [fn1, fn2]);
console.log(err); // [ '[Object object] must be a string' ] 

The returned object err is null if there was no validation errors. Otherwise the returned value is an array with all validation errors.

License:

MIT © Gonçalo Pestana

About

nosix.js abstracts input validation, making it easier and straighforward for you to validate any type of input.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published