@kupibilet/boolean-json-eval

evaluate boolean-json expressions

Stats

StarsIssuesVersionUpdatedCreatedSize
@kupibilet/boolean-json-eval
403.2.24 years ago4 years agoMinified + gzip package size for @kupibilet/boolean-json-eval in KB

Readme

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, false or 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', {})
})

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.