4.1.3 • Published 11 months ago

isolated-eval v4.1.3

Weekly downloads
-
License
MIT
Repository
-
Last release
11 months ago

Isolated-eval

The isolated-eval package provides a Safe class designed for securely executing code and isolating potentially unsafe variables and objects.

Installation

You can install the isolated-eval package via npm:

npm install isolated-eval

Usage

Importing the Module

const Safe = require('isolated-eval');

Methods

static getPotentialUnsafeVariables()

Returns an array of names of potentially unsafe variables and objects that can be isolated.

Returns:

  • Array<string>: An array of names of potentially unsafe variables and objects.

Example:

const unsafeVars = Safe.getPotentialUnsafeVariables();
console.log(unsafeVars);

static eval(code = '', args = {}, isolation = this.getPotentialUnsafeVariables())

Executes the given code with the specified arguments and isolates the specified objects.

Parameters:

  • code (string): The code to be executed.
  • args (object): An object containing the arguments for the code execution.
  • isolation (Array<string>): An array of names of objects to be isolated.

Returns:

  • The result of the code execution.

Example:

const result = Safe.eval('console.log(message)', { message: 'Hello, world!' });

Example

const Safe = require('isolated-eval');

// Get potentially unsafe variables
const unsafeVars = Safe.getPotentialUnsafeVariables();
console.log('Potentially unsafe variables:', unsafeVars);

// Execute code with isolation
const result = Safe.eval('console.log(message)', { message: 'Hello, world!' });

License

This project is licensed under the MIT License.

1.0.0

11 months ago

3.0.0

11 months ago

4.1.3

11 months ago

4.1.0

11 months ago

4.0.1

11 months ago

4.0.0

11 months ago

4.1.2

11 months ago

4.1.1

11 months ago

2.0.0

11 months ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago