coffinjs
v0.1.1
Published
Javascript sandbox module for node
Downloads
3
Maintainers
Readme
Coffin
A small and fast module providing sandboxed javasript execution for node
Installation
npm install coffinjs --save
Usage
As a sync function:
const Coffin = require('coffinjs');
let coffin = new Coffin();
let result = coffin.runSync('console.log("a"); return 1 + 1;');
// result -> { console: ["a"], returnValue: 2 }
With callback:
const Coffin = require('coffinjs');
let coffin = new Coffin();
coffin.run('console.log("a"); return 1 + 1;', (result) => {
// result -> { console: ["a"], returnValue: 2 }
});
Setting options:
const Coffin = require('coffinjs');
let coffin = new Coffin({ timeout: 200 });
// or
let coffin = new Coffin();
coffin.setOptions({ timeout: 200 });
API
- .setOptions( )
- .run( code , callback )
- .runSync( code )
Options
- timeout: 200 // 200ms timeout
Tests
npm run test
npm run test:watch
npm run test:coverage
Contributing
Please try to keep the coding style (mostly Crockford) and always write tests for any new or changed code. Lint will be added later.