boolean-json-schema

3.0.0 • Public • Published
var schema = require('boolean-json-schema')

The package exports a JSON Schema. You will need a compatible library to validate objects:

var validate = require('tv4').validate

The simplest valid expression is just a variable name:

var assert = require('assert')
 
assert(validate('first', schema))

The syntax is very minimal. The schema permits negation, conjunction, disjunction, and arbitrary combinations:

assert(validate({ not: 'x' }, schema))
 
assert(validate({ and: [ 'x', 'y' ] }, schema))
 
assert(validate({ or: [ 'x', 'y' ] }, schema))
 
assert(validate({ and: [ { or: [ 'x', 'y' ] }, { not: 'z' } ] }, schema))

Conjunctions and disjunctions must have at least two operands:

assert(validate({ and: [ 'x' ]}, schema) === false)
assert(validate({ and: [ 'x', 'y', 'z' ]}, schema) === true)
 
assert(validate({ or: [ 'x' ]}, schema) === false)
assert(validate({ or: [ 'x', 'y', 'z' ]}, schema) === true)

Package Sidebar

Install

npm i boolean-json-schema

Weekly Downloads

1

Version

3.0.0

License

MIT

Last publish

Collaborators

  • kemitchell