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