JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 161
  • Score
    100M100P100Q83299F
  • License ISC

A JavaScript interpreter written in JavaScript

Package Exports

  • evaljs

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (evaljs) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

eval.js

Build Status Dependency Status devDependency Status

A JavaScript interpreter written in JavaScript.

Why?

You might be working in a JavaScript environment where eval() isn't allowed (and you have a genuinely good reason why you want to use it). Maybe this'll slip under the radar. You could also extend this to make it execute ES6 code in an ES5 environment. PRs welcome!

How?

Most of the heavy lifting is done by acorn, a JavaScript parser written in JavaScript. eval.js converts the AST it generates into JavaScript function closures, which when run execute the whole program.

It's also possible to use eval.js with esprima.

API

  • evaljs.evaluate(code) A drop in alternative for window.eval().
  • new evaljs.Environment([scopesOrGlobalObject]) Generates a new JS Environment to 'run' code in. The argument can be one of the following:
    • a global object
    • nothing (in this case, '{}' is used as the global object)
    • a list of objects. The first will be the global object, others will be other scopes loaded into the interpreter. Kind of like wrapping the code in a with statement for each further object in the array. This is handy for emulating Node.js (for passing in require(), exports, and module.)

Size?

15.4kB min+gzip

License?

ISC

Is it complete?

No labeled statements; no nice error handling; no for-in loops. There are probably bugs. That said, it can run itself so its supported subset of JS is usable. PRs containing improvements welcome!

How slow is it?

Not sure. I only tested with small snippets so far in Node.js, for which the speed difference isn't notable. But it's probably slow.

Who?

eval.js is written by Marten de Vries. Credits for the original idea go to closure-interpreter.