Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

simple-eval

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simple-eval

Simple JavaScript expression evaluator

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
586K
decreased by-12.91%
Maintainers
1
Weekly downloads
 
Created
Source

simple-eval

Simple JavaScript expression evaluator.

Install

yarn add simple-eval

or if npm is package manager of your choice

npm install simple-eval --save

Usage

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.

Caveats

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.

LICENSE

MIT

Keywords

FAQs

Package last updated on 17 Jul 2022

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc