boolean-json-eval

3.0.1 • Public • Published
var evaluate = require('boolean-json-eval')

The package exports a function of two arguments:

  1. a boolean-json expression

  2. an object map from string variable name to true or false

It returns true or false.

var assert = require('assert')
 
assert(evaluate('x', {x: true}))
 
assert(
  evaluate(
    {or: ['a', {not: 'b'}, 'c']},
    {a: false, b: true, c: true}
  )
)
 
assert(
  evaluate(
    {
      and:
      [
        {not: 'a'},
        {not: {not: {not: 'a'}}},
        {or: ['a', {not: 'a'}]}
      ]
    },
    {a: false}
  )
)

The function throws an exception if its expression argument references an undefined variable.

assert.throws(function() {
  evaluate('x', {})
})

Package Sidebar

Install

npm i boolean-json-eval

Weekly Downloads

1

Version

3.0.1

License

MIT

Last publish

Collaborators

  • kemitchell