iterative-eval

0.1.0 • Public • Published

iterative-eval

Iteratively evaluate code in a single context as you would in a repl. You can do this using vm.createContext and vm.runInContext but bugs in vm's implementation make this pretty leaky.

Installation

With your favorite package manager:

  • packin: packin add iterative-eval
  • npm: npm install iterative-eval

then in your app:

var Evaluator = require('iterative-eval')

API

Evaluator(path)

Creates a new evaluation context. If you pass a path all code evaluated by it the Evaluator will be run as if it was being run from that file system location. So require, __filename etc.. can all work as expected.

var ctx = new Evaluator(__filename)

ctx#eval(js)

Execute js and return the result

ctx.eval("var a=1") // => undefined
ctx.eval("a") // => 1
ctx.eval("require('iterative-eval')") // => Evaluator
ctx.eval("__dirname") // => __dirname

Package Sidebar

Install

npm i iterative-eval

Weekly Downloads

1

Version

0.1.0

License

MIT

Last publish

Collaborators

  • jkroso