0.1.1 • Published 7 years ago

coffinjs v0.1.1

Weekly downloads
1
License
MIT
Repository
-
Last release
7 years ago

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.