Javascript Object Validator
A simple javascript Object Validator prototype
Create a validator first
var UserValidator = new Validator({username:'',password:''})
Then send your object to your created validator :
var result = UserValidator({username:'tolga'})
Example :
var Validator = require('./validator.js')
var userSchema = {
user : {
username : "kucukkanat",
age : 22
},
social : {
facebook : {link:"http://facebook.com",email:"eeek@facebook.com"},
twitter : {username:"kucukkanat",followers:3562}
},
id : 3127
}
var UserSchemaValidator = new Validator(userSchema)
var result = UserSchemaValidator({
id : 4,
user : {username:3},
social:{facebook:{}}
})
console.log(result)
Contribution
Please feel free to contribute and advice about new features
TO-DO
Add optional parametersCheck Variable types- Will need to support nested objects
- Use as an expressjs middleware
- Support arrays