Skip to content

RobertHerhold/boolean-json-joi-schema

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 ✅

About

Joi Schema for boolean expressions

Resources

License

Stars

Watchers

Forks

Packages

No packages published