infix-to-postfix

0.0.3 • Public • Published

infix-to-postfix

Returns a postfix (Reverse Polish Notation) expression from an infix expression.

Demo

https://lab.miguelmota.com/infix-to-postfix

Install

npm install infix-to-postfix

Usage

const infixToPostfix = require('infix-to-postfix');
 
console.log(infixToPostfix('1 + 2')); // '1 2 +'
console.log(infixToPostfix('(1 + 2) * (-4)')); // '1 2 + -4 *'
console.log(infixToPostfix('((3 * 4) / (2 + 5)) * (3 + 4)')); // '3 4 * 2 5 + / 3 4 + *'
console.log(infixToPostfix('((57.5 - -34.1) * (6 / 3.2)) + 4.3')); // '57.5 -34.1 - 6 3.2 / * 4.3 +'
console.log(infixToPostfix('a & 5')); // null (invalid expressions return null)

Use the postfix-calculator module for calculating postfix expressions.

Test

npm test

Credit

License

MIT

Package Sidebar

Install

npm i infix-to-postfix

Weekly Downloads

282

Version

0.0.3

License

MIT

Last publish

Collaborators

  • miguelmota