# scriptcontext

> provides a disposable sandbox for scripts

Latest version **3.0.1** (published 2017-08-04) · ISC license · 0 weekly downloads

## Install

```sh
npm install scriptcontext
pnpm add scriptcontext
yarn add scriptcontext
bun add scriptcontext
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.1 |
| Published | 2017-08-04 |
| First published | 2016-12-13 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Bonuspunkt |
| Maintainers | bonuspunkt |

## Links

- npm: https://www.npmjs.com/package/scriptcontext
- Repository: https://github.com/Bonuspunkt/scriptcontext
- Homepage: https://github.com/Bonuspunkt/scriptcontext#readme
- Issues: https://github.com/Bonuspunkt/scriptcontext/issues
- npm.io page: https://npm.io/package/scriptcontext

## Recent versions

- 3.0.1 (latest) — 2017-08-04
- 3.0.0 — 2017-01-11
- 2.0.0 — 2017-01-04
- 1.1.0 — 2016-12-14
- 1.0.0 — 2016-12-13

## README

# scriptcontext
[![Build Status](https://travis-ci.org/Bonuspunkt/scriptcontext.svg?branch=master)](https://travis-ci.org/Bonuspunkt/scriptcontext)
[![codecov.io](https://img.shields.io/codecov/c/github/Bonuspunkt/scriptcontext.svg?branch=master)](https://codecov.io/gh/Bonuspunkt/scriptcontext?branch=master)
[![npm](https://img.shields.io/npm/v/scriptcontext.svg)](https://www.npmjs.com/package/scriptcontext)
[![license](https://img.shields.io/npm/l/scriptcontext.svg)](https://tldrlegal.com/license/-isc-license)

provides a disposable sandbox for scripts

**WARNING:** its only protected via `vm` it doesn't start a new child process. it will not protect you against `while(1);`

## how to use
``` js
const { EventEmitter } = require('events');
const scriptContext = require('scriptcontext');

const emitter = new EventEmitter();

const config = {
    resolve: {
        func: () => console.log('func'),
        object: {
            func: () => console.log('object.func')
        }
    },
    subscribe: {
        emitter
    }
};

const scripts = [{
    file: 'filename (optional)',
    content: 'const objectFunc = resolve("object.func"); objectFunc();'
}, {
    content: 'const func = resolve("func"); subscribe("emitter.event", func);'
}];

const context = scriptcontext(config, scripts);
// console prints `object.func`
emitter.emit('event');
// console prints `func`

context.destroy();
```

## scriptcontext(config, scripts)

- `config`

see `lib/provider`

    - `resolve` <Object>

    - `scriptEvent` <Boolean>

    - `scriptFn` <Boolean>

    - `subscribe` <Object>

    - `onError` <Function>

    - `timeout` <Boolean>

- `scripts`


## install
```
npm install scriptcontext --save
```

---
_Source: https://npm.io/package/scriptcontext · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
