New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

calculator-lib

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

calculator-lib

Calculate infix / postfix expressions

  • 1.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
8
increased by60%
Maintainers
1
Weekly downloads
 
Created
Source

Calculator lib

Provides functions for evaluating infix (and RPN postfix) expressions, in JavaScript.

Source is in ES6, released as ES5. Transpiled using Babel.

Installation:

npm install calculator-lib

Usage:

Evaluation of infix expressions

const { evaluateInfix } = require('calculator-lib');

evaluateInfix('4 + 5'); // -> 9

evaluateInfix('2+3/(5^-1)*-1.5'); // -> -20.5

Supported operators

Currently, operations are limited to the following:

  • Multiplication (*)
  • Division (/)
  • Addition (+)
  • Subtraction (-)
  • Exponentiation (^)

Feel free to add more in a pull request! For example, trigonometric operations would come in handy...

Other methods:

Evaluation of (RPN) postfix expressions

const { evaluatePostfix } = require('calculator-lib');

evaluatePostfix('1 2 + 3 +'); // -> 6

evaluatePostfix('21 -3.2 *'); // -> -67.2

Conversion of infix expressions to (RPN) postfix expressions

const { infixToPostfix } = require('calculator-lib');

infixToPostfix('21 ^ 3 * 2 - 10'); // -> '21 3 ^ 2 * 10 -'

Keywords

FAQs

Package last updated on 12 Sep 2021

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