@keqingrong/vm
v0.2.0
Published
A JavaScript utility like Node's vm module for browsers
Downloads
1
Readme
@keqingrong/vm
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