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

expr-eval

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

expr-eval

Mathematical expression evaluator

  • 2.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
476K
increased by1.93%
Maintainers
1
Weekly downloads
 
Created

What is expr-eval?

The expr-eval npm package is a mathematical expression evaluator for JavaScript. It allows you to parse and evaluate mathematical expressions, define custom functions and variables, and perform various mathematical operations programmatically.

What are expr-eval's main functionalities?

Basic Expression Evaluation

This feature allows you to evaluate basic mathematical expressions. The code sample demonstrates how to parse and evaluate a simple arithmetic expression.

const { Parser } = require('expr-eval');
const parser = new Parser();
const expr = parser.parse('2 + 3 * (7 - 5)');
console.log(expr.evaluate()); // Output: 8

Variable Support

This feature allows you to define and use variables within expressions. The code sample shows how to evaluate an expression with variables.

const { Parser } = require('expr-eval');
const parser = new Parser();
const expr = parser.parse('x * y + z');
const variables = { x: 2, y: 3, z: 4 };
console.log(expr.evaluate(variables)); // Output: 10

Custom Functions

This feature allows you to define custom functions that can be used within expressions. The code sample demonstrates how to create and use a custom function.

const { Parser } = require('expr-eval');
const parser = new Parser();
parser.functions.customFunc = function(a, b) { return a * b + 1; };
const expr = parser.parse('customFunc(2, 3)');
console.log(expr.evaluate()); // Output: 7

Logical and Comparison Operators

This feature supports logical and comparison operators within expressions. The code sample shows how to evaluate an expression with logical and comparison operators.

const { Parser } = require('expr-eval');
const parser = new Parser();
const expr = parser.parse('x > 5 && y < 10');
const variables = { x: 6, y: 8 };
console.log(expr.evaluate(variables)); // Output: true

Other packages similar to expr-eval

Keywords

FAQs

Package last updated on 28 Sep 2019

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