4.1.3 • Published 5 months ago
isolated-eval v4.1.3
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.