js-expr-runner

2.1.0 • Public • Published

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)"

Readme

Keywords

none

Package Sidebar

Install

npm i js-expr-runner

Weekly Downloads

1

Version

2.1.0

License

ISC

Unpacked Size

181 kB

Total Files

20

Last publish

Collaborators

  • zag2art