little-schema

1.0.0 • Public • Published

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 parameters
  • Check Variable types
  • Will need to support nested objects
  • Use as an expressjs middleware
  • Support arrays

Readme

Keywords

none

Package Sidebar

Install

npm i little-schema

Weekly Downloads

0

Version

1.0.0

License

ISC

Last publish

Collaborators

  • kucukkanat