2.1.0 • Published 2 years ago

js-expr-runner v2.1.0

Weekly downloads
61
License
ISC
Repository
-
Last release
2 years ago

js-expr-runner

js-expr-runner allows you to parse an expression string and run it in an isolated context

install

npm install js-expr-runner

example

const exp = require('js-expr-runner')

const run = (expression, context) => {
  const runner = exp.getRunner(expression)
  return runner.run(context).value
}

console.log(run('a + 3 * fn(20)', {
  a: 50,
  fn: n => n * 2
}))
// 170


// SECURITY 

console.log(run('window', {}))
// undefined

console.log(run('global', {}))
// undefined

console.log(run('console', {}))
// undefined

Restrictions

In js-expr-runner you can use anything js allows to use in js (ES5) expressions (in the right part of an assignment operator) except bitwise operations and in-place functions (lambdas are also forbidden)

In addition to ES5 you can also use "?.", "??" operators and spread in arrays "...a, 1,2, ...b" and call arguments "a(...b, c)"

2.1.0

2 years ago

2.0.0

3 years ago

1.0.0

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago