4.1.3 • Published 5 months ago

isolated-eval v4.1.3

Weekly downloads
-
License
MIT
Repository
-
Last release
5 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

6 months ago

3.0.0

6 months ago

4.1.3

5 months ago

4.1.0

6 months ago

4.0.1

6 months ago

4.0.0

6 months ago

4.1.2

6 months ago

4.1.1

6 months ago

2.0.0

6 months ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago