epochtalk-validator
v0.0.5
Published
Validation module for epochtalk and epochcore
Downloads
3
Readme
Validator
Schema validation module for all Epoch Projects.
Installation
$ git clone [email protected]:epochtalk/validator
$ cd validator
$ npm install
Usage Example
Access predefined validation methods
var authValidator = require('validator').api.auth; // Access the auth validator within api
var credentials = {
username: 'test_user',
password: 'password'
};
var err = authValidator.login(credentials); // pass parameters in to validator
if(err) {
// do error related things
}
else {
// do success related things
}
Directly access predefined Joi Schema
var authSchemas = require('validator').api.auth.schema; // Access Auth Schema
var Joi = require('joi');
var credentials = {
username: 'test_user',
password: 'password'
};
var loginSchema = authSchema.login; // grab the auth login schema
var err = Joi.validate(credentials, loginSchema); // Manually call Joi.validate with schema
if(err) {
// do error related things
}
else {
// do success related things
}