# vm-agent

> This library is able to get all inner variables

Latest version **0.6.0** (published 2019-12-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install vm-agent
pnpm add vm-agent
yarn add vm-agent
bun add vm-agent
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.6.0 |
| Published | 2019-12-04 |
| First published | 2016-12-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 18.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Suguru Motegi |
| Maintainers | suguru03 |
| Keywords | vm |

## Links

- npm: https://www.npmjs.com/package/vm-agent
- Repository: https://github.com/suguru03/vm-agent
- Issues: https://github.com/suguru03/vm-agent/issues
- npm.io page: https://npm.io/package/vm-agent

## Dependencies (2)

- [esprima](https://npm.io/package/esprima.md) ^4.0.1
- [escodegen](https://npm.io/package/escodegen.md) ^1.12.0

## Recent versions

- 0.6.0 (latest) — 2019-12-04
- 0.5.8 — 2018-11-19
- 0.5.7 — 2018-07-12
- 0.5.6 — 2018-07-12
- 0.5.5 — 2018-07-12
- 0.5.4 — 2017-12-06
- 0.5.3 — 2017-12-01
- 0.5.2 — 2017-11-29
- 0.5.1 — 2017-11-29
- 0.5.0 — 2017-11-29
- 0.4.0 — 2017-08-03
- 0.3.3 — 2017-05-02
- 0.3.2 — 2017-04-27
- 0.3.1 — 2017-01-24
- 0.3.0 — 2017-01-14
- … 1 more at https://npm.io/package/vm-agent/versions

## README

# vm-agent

The library is vm module wrapper, it is supposed to be used for testing inner variables or hacking scripts. It is not for production.

It supports executing scripts, functions by filepath or functions.
Also, it will be able to access inner variables.

## Usage

```sh
$ npm i -D vm-agent
```

If you want to run a script using vm, you need to set a filepath and call `run`. The context is resolved automatically.

```js
const { Agent } = require('vm-agent');
const agent = new Agent(<filepath>).run();
// or
const exec = require('vm-agent');
const agent = exec(<filepath>);
```

If the script is an async function, you need to call `runAsync` function.

```js
const agent = new Agent(<filepath>).runAsync();
```

After that, if you wanna get inner variables, you need to call `getInnerVariable` or `getValue`.

```js
const innerVariables = agent.getInnerVariable();
// or
const innerVariables = agent.getValue();
```

## Examples

### Inner functions

```js
function func1() {
  console.log('func1 is called');
  function func2() {
    console.log('func2 is called');
  }
}
exec(func1)
  .getInnerVariable()
  .func2();
```

### Async/Await

```js
async function func1() {
  const util = require('util');
  const delay = util.promisify(setTimeout);
  await delay(100);
  console.log('func1 is called');
  async function func2() {
    await delay(100);
    console.log('func2 is called');
  }
}

async function execute() {
  const agent = await new Agent(func1).runAsync();
  const { func2 } = agent.getInnerVariable();
  await new Agent(func2, agent.getContext()).runAsync();
}

execute();
```

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