
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
基于 JavaScript 编写的 JavaScript 解释器;A JavaScript interpreter, written completely in JavaScript;
用于解决在不支持
eval
或Function
的执行环境下执行 JavaScript 代码。例如:各种小程序。
npm install --save eval5
import { evaluate, Function, vm, Interpreter } from 'eval5';
// 设置默认作用域
Interpreter.global = window;
//或 evaluate("1+1", Object.create(window));
evaluate("1+1", window); // 2
const func = new Function('a','b', 'return a+b;');
console.log(func(1,1)); // 2
const interpreter = new Interpreter(ctx, {
timeout: 1000
});
let result;
try {
result = interpreter.evaluate('1+1');
console.log(result) //2
} catch(e) {
//..
}
static
global设置默认作用域对象
例如:
Interpreter.global = window;
constructor
(ctx: {}, options?: { timeout?: number})构造函数
var interpreter = new Interpreter(window);
evaluate
(code: string, ctx?: {}): any返回脚本中执行的最后一个表达式结果
var interpreter = new Interpreter(window);
interpreter.evaluate('alert(1+1)')
执行给定的字符串脚本,返回脚本中执行的最后一个表达式结果
evaluate('console.log(1+1)', {console: console})
同 js 原生的 Function
const func = new Function('a','b', 'return a+b;');
console.log(func(1,2))
参考 node.js vm
支持 api 列表:
ISC
FAQs
A JavaScript interpreter written in JavaScript
The npm package eval5 receives a total of 2,453 weekly downloads. As such, eval5 popularity was classified as popular.
We found that eval5 demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.