1.0.1 • Published 7 years ago

boolean-json-joi-schema v1.0.1

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

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 ✅