infix-to-postfix
v0.0.3
Published
Returns a postfix (Reverse Polish Notation) expression from an infix expression.
Downloads
2,357
Maintainers
Readme
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