boolean-json-joi-schema

1.0.1 • Public • Published

boolean-json-joi-schema

NPM

Build Status

This package is a Joi port of boolean-json-schema. It exports a Joi schema that can be used to validate boolean JSON expressions.

The simplest valid expression is just a variable name:

const schema = require('boolean-json-joi-schema');
const Joi = require('joi');
 
Joi.validate('myVar', schema, function(err) {
    expect(err).to.be.null;
});

Per the original, the schema permits negation, conjunction, disjunction, and arbitrary combinations:

{ not: 'x' }
 
{ and: [ 'x', 'y' ] }
 
{ or: [ 'x', 'y' ] }
 
{ and: [ { or: [ 'x', 'y' ] }, { not: 'z' } ] }

Conjunctions and disjunctions must have at least two operands:

{ and: [ 'x' ]} // INVALID 🚫
{ and: [ 'x', 'y', 'z' ]} // VALID ✅
 
{ or: [ 'x' ]} // INVALID 🚫
{ or: [ 'x', 'y', 'z' ]} // VALID ✅

Package Sidebar

Install

npm i boolean-json-joi-schema

Weekly Downloads

1

Version

1.0.1

License

MIT

Last publish

Collaborators

  • robertherhold