sg-validator

1.1.1 • Public • Published

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

Readme

Keywords

Package Sidebar

Install

npm i sg-validator

Weekly Downloads

0

Version

1.1.1

License

Apache-2.0

Last publish

Collaborators

  • realglobe