3.2.2 • Published 9 years ago
@kupibilet/boolean-json-eval v3.2.2
var evaluate = require('boolean-json-eval')The package exports a function of two arguments:
a boolean-json expression
an object map from string variable name to
true,falseor a predicate (a function returning a boolean value) to be computed lazily.
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: () => 2 * 2 === 4}
)
)
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', {})
})