1.1.1 • Published 7 years ago

sg-validator v1.1.1

Weekly downloads
3
License
Apache-2.0
Repository
github
Last release
7 years ago

sg-validator

Build Status npm Version JS Standard

JSON Schema validator

Installation

$ npm install sg-validator --save

Usage

'use strict'

const sgValidator = require('sg-validator')

// Define a validator with JSON-Schema
let validator = sgValidator({
  title: 'Example Schema',
  type: 'object',
  properties: {
    firstName: {
      type: 'string'
    },
    lastName: {
      type: 'string'
    },
    age: {
      description: 'Age in years',
      type: 'integer',
      minimum: 0
    }
  },
  required: [ 'firstName', 'lastName' ]
})

// Execute validation
let errors = validator.validate({
  firstName: 'hoge',
  lastName: 'fuge'
})

if (errors) {
  throw new Error('Something is wrong!')
} else {
  console.log('Matches to the schema!')
}

License

This software is released under the Apache-2.0 License.

Links