# script-eval-js

> eval with context, execute script block, pass parameters, global function variables

Latest version **1.0.7** (published 2022-05-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install script-eval-js
pnpm add script-eval-js
yarn add script-eval-js
bun add script-eval-js
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.7 |
| Published | 2022-05-24 |
| First published | 2022-05-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 16.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | hanks |
| Maintainers | vblegend |
| Keywords | eval, eval with context, execute script |

## Links

- npm: https://www.npmjs.com/package/script-eval-js
- Repository: https://github.com/vblegend/script-runner
- Homepage: https://github.com/vblegend/script-runner#readme
- Issues: https://github.com/vblegend/script-runner/issues
- npm.io page: https://npm.io/package/script-eval-js

## Recent versions

- 1.0.7 (latest) — 2022-05-24
- 1.0.6 — 2022-05-24
- 1.0.5 — 2022-05-24
- 1.0.0 — 2022-05-23

## README

Script Runner
=======

Make your eval pass parameters and specify this context when executing the script, and you can register global functions and variables for him.

License: MIT


`install`
```
npm install script-eval-js


import { ScriptRunner } from 'script-eval-js';
```



`examples`
``` typescript
const result = ScriptRunner.eval(`return 1+1;`);
console.log(result);
```

``` typescript
const result = ScriptRunner.eval(`console.log(this);`);
console.log(result);
```

``` typescript
const result = ScriptRunner.eval(`console.log(id+name);`, { id: 100,  name: 'script runner' });
console.log(result);
```
``` typescript
const func = ScriptRunner.buildFunction(`console.log(this); return id + name;`, ['id','name'],this);
const result = func(100,'script runner');
console.log(result);
```



`typescript typing`
```
/**
* global context
*/
export declare class ScriptEvalContext {
    constructor(baseContext?: ScriptEvalContext, initLib?: boolean);
    clear(): void;
    register(name: string, object: any): void;
    remove(name: string): void;
    get(name: string): any;
    get names(): string[];
    get values(): any[];
}
export declare class ScriptRunner {
    static buildFunction(script: string, argNames?: string[], thisContext?: Object, globalContext?: ScriptEvalContext): Function;
    static eval<TResult>(script: string, parameters: Record<string, any>, thisContext?: Object, globalContext?: ScriptEvalContext): TResult;
}
```

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