open-index/open-npm huggingface dataset:
npm package: @scriptdb/vm
Description: Virtual machine package for script database
Latest version: 1.1.3

# ScriptDB VM

Virtual Machine package for executing TypeScript and JavaScript code in a secure sandboxed environment.

## Installation

```bash
npm install @scriptdb/vm
# or
yarn add @scriptdb/vm
# or
bun add @scriptdb/vm
```

## Quick Start

```typescript
import { VM } from '@scriptdb/vm';

// Create a VM instance
const vm = new VM();

// Execute TypeScript code
const result = await vm.run(`
  const greet = (name: string) => \`Hello, \${name}!\`;
  greet("World");
`);

console.log(result); // "Hello, World!"
```

## API Reference

### Constructor

```typescript
new VM(options?)
```

Creates a new VM instance with the specified options.

#### Options

```typescript
interface VMOptions {
  language?: 'ts' | 'js';           // Code language (default: 'ts')
  registerModules?: { [key: string]: any };  // Modules to register in the VM context
}
```

### Methods

#### run(code, options?)

Executes code in the VM context.

```typescript
await vm.run(code: string, options?: vm.RunningCodeOptions | string): Promise<any>
```

- `code` (string): The TypeScript or JavaScript code to execute
- `options` (optional): Execution options or filename

Returns a promise that resolves with the result of the code execution.

#### register(context)

Registers modules and values in the VM context.

```typescript
vm.register(context: { [key: string]: any }): void
```

- `context` (object): Object with keys that will be available in the VM context

## Development

```bash
# Install dependencies
bun install

# Run in development mode
bun run dev

# Build the package
bun run build:all

# Run tests
bun run test

# Run linting
bun run lint

# Type checking
bun run typecheck
```