@keqingrong/vm
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

@keqingrong/vm

npm version

A JavaScript utility like Node's vm module for browsers

Live demo available at here.

Installation

$ npm install @keqingrong/vm

The CDN build is also available on unpkg:

Usage

import { runInNewContext } from '@keqingrong/vm';

const sandbox = {
  x: 2
};
const code = 'function add(a) { return a+x; }; add(42);';
runInNewContext(code, sandbox).then((result) => {
  console.log(result); // 44
}, (error) => {
  console.error(error);
});

API

  • runInNewContext(code, sandbox, options)
  • runInNewIframe(code, sandbox)
  • runInNewWorker(code, sandbox)

License

MIT

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.2.0
    0
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.2.0
    0
  • 0.1.2
    0
  • 0.1.1
    0
  • 0.1.0
    0

Package Sidebar

Install

npm i @keqingrong/vm

Weekly Downloads

0

Version

0.2.0

License

MIT

Unpacked Size

17.2 kB

Total Files

13

Last publish

Collaborators

  • dearke