🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

built-in-math-eval

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

built-in-math-eval

Evaluate mathematical expression with the built-in math object

0.3.0
latest
Source
npm
Version published
Weekly downloads
268
40.31%
Maintainers
1
Weekly downloads
 
Created
Source

built-in-math-eval

Build Status NPM Coverage Status Stability

js-standard-style

Evaluate mathematical expression with the built-in math object

Table of Contents generated with DocToc

Description

This module evaluates the generated code from math-codegen for the built in Math namespace providing the necessary adapter methods

Installation

$ npm install --save built-in-math-eval

API

var compile = require('built-in-math-eval');

code = compile(expression)

params

  • expression {string} the expression to be parsed

returns {Object}

  • return.eval {function} The compiled function to be called with some scope variables

return.eval([scope])

params

  • scope {Object}

An optional object which holds some variables to be used in the expression, all variables are casted to Number

returns {*} a number or a boolean value depending on the operation made

Examples

Also have a look at test/index.js

var compile = require('built-in-math-eval');

// > 3
compile('1 + 2').eval()

// > 8
compile('2^3').eval()

// > 8
compile('x^3').eval({ x: 2 })

// > 1
compile('cos(x)').eval({ x: 0 })

// > 8
compile('2x^2').eval({ x: 2 })

// > 3.1415
compile('PI').eval()

2015 © Mauricio Poppe

Keywords

built-in-math-eval

FAQs

Package last updated on 10 Dec 2015

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