Socket
Book a DemoInstallSign in
Socket

little-schema

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

little-schema

A simple javascript Object Validator prototype

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

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

FAQs

Package last updated on 30 Jan 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts