
Research
Security News
The Growing Risk of Malicious Browser Extensions
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
simple-eval
Advanced tools
Simple JavaScript expression evaluator.
yarn add simple-eval
or if npm is package manager of your choice
npm install simple-eval --save
import simpleEval from 'simple-eval';
simpleEval('2 + 4 * 10 + -4'); // 38
simpleEval('Math.floor(Math.PI * 10)'); // exception
simpleEval('Math.floor(Math.PI * 10)', { Math }); // 31, works because we provided Math
simpleEval('foo.bar.baz ? 10 : Math.random()', {
Math,
foo: {
bar: {
baz: false,
}
}
}); // some random number, as returned by Math.random()
By default, simple-eval
uses jsep
,
but you're free to use any ESTree compliant parser such as acorn
, @babel/parser
, or esprima
.
Although a number of use cases is supported, do note that this library does not aim to be a drop-in replacement for eval
.
By supporting a limited set of instructions, it's arguably safer than eval
, albeit it's still not supposed to be used instead of proper sandbox.
In particular, all kind of declarations and assignments are prohibited.
FAQs
Simple JavaScript expression evaluator
The npm package simple-eval receives a total of 820,874 weekly downloads. As such, simple-eval popularity was classified as popular.
We found that simple-eval demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer 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.
Research
Security News
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
Research
Security News
An in-depth analysis of credential stealers, crypto drainers, cryptojackers, and clipboard hijackers abusing open source package registries to compromise Web3 development environments.
Security News
pnpm 10.12.1 introduces a global virtual store for faster installs and new options for managing dependencies with version catalogs.