npm.io
4.0.2 • Published 2 years ago

metalman-schema

Licence
ISC
Version
4.0.2
Deps
2
Size
5 kB
Vulns
1
Weekly
0
Stars
1

metalman-schema

Greenkeeper badge

A JSON schema validation middleware for the metalman module.

var metalman = require('metalman')
var action = require('metalman-action')

var command = metalman([validate])
var fn = command({
  schema: {
    type: 'object',
    required: ['foo'],
    additionalProperties: false,
    properties: {
      foo: {type: 'number'}
    }
  }
})

fn({foo: 'bar'}, function (err) {
  // err instanceof Error
  // err.name equals 'ValidationError'
  // err.message equals "Value at path '/foo' should be number"
})

fn({foo: 1}, function (err) {
  // err equals null if the schema is valid
})

Keywords