
Product
Secure Your AI-Generated Code with Socket MCP
Socket MCP brings real-time security checks to AI-generated code, helping developers catch risky dependencies before they enter the codebase.
@sensative/jsep-eval
Advanced tools
A configurable eval function, which uses jsep to parse expressions. The generated result is evaluated w.r.t. a supplied object context.
jsep-eval evaluates javascript expressions, and uses jsep to parse the expressions. A context can/should be supplied against which identifers are matched.
First, run npm install jsep-eval
. Then, in your source file:
const jsepEval = require("jsep-eval");
const evaluate = jsepEval.evaluate;
const two = evaluate('1 + 1');
const three = evaluate('two + 1', {two: 2});
jsep-eval exposes the objects the allowed expression types
const types = jsepEval.types;
So it is possible to dis-allow a given expression type by removing it from this array:
const types = jsepEval.types;
evaluate('2 + 2'); // returns 4
delete types.BINARY;
evaluate('2 + 2'); // throws error
It is also possible to restrict evaluation by operator (both binary and unary):
const binaryOps = jsepEval.operators.binary;
const unaryOps = jsepEval.operators.unary;
evaluate('2 === 2'); // returns true
delete binaryOps['==='];
evaluate('2 === 2'); // throws error
evaluate('!false'); // returns true
unaryOps['!'] = () => 'bob';
evaluate('!false'); // returns 'bob'
jsep-eval is under the MIT license. See LICENSE file.
FAQs
A configurable eval function, which uses jsep to parse expressions. The generated result is evaluated w.r.t. a supplied object context.
We found that @sensative/jsep-eval demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 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.
Product
Socket MCP brings real-time security checks to AI-generated code, helping developers catch risky dependencies before they enter the codebase.
Security News
As vulnerability data bottlenecks grow, the federal government is formally investigating NIST’s handling of the National Vulnerability Database.
Research
Security News
Socket’s Threat Research Team has uncovered 60 npm packages using post-install scripts to silently exfiltrate hostnames, IP addresses, DNS servers, and user directories to a Discord-controlled endpoint.