boolean-json-joi-schema
v1.0.1
Published
Joi Schema for boolean expressions
Downloads
8
Maintainers
Readme
boolean-json-joi-schema
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 ✅