@hapify/vm
TypeScript icon, indicating that this package has built-in type declarations

1.4.1 • Public • Published

Hapify VM

Description

This repository provides a secured sandbox to execute unsafe JavaScript code

Usage

Basic usage

import { HapifyVM } from '@hapify/vm';

const script = `const concat = a + b; return concat;`;
const result = new HapifyVM().run(script, { a: 'hello', b: 'world' }); // result = 'hello world'

Advanced usage

import { HapifyVM } from '@hapify/vm';

const script = `const sum = a + b; return sum;`;
const options = {
  timeout: 200, // Maximum script execution time. Default to 5000ms.
  allowAnyOutput: true, // Allow the input script to return any data type. Default to false.
  eval: true, // Allow function constructors (Function, GeneratorFunction, etc)
};
const result = new HapifyVM(options).run(script, { a: 1, b: 2 }); // result = 3

Readme

Keywords

Package Sidebar

Install

npm i @hapify/vm

Weekly Downloads

35

Version

1.4.1

License

MIT

Unpacked Size

20.1 kB

Total Files

20

Last publish

Collaborators

  • edouarddemotes
  • dt-tractr