infix-to-postfix

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

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
infix-to-postfix
510.0.35 years ago7 years agoMinified + gzip package size for infix-to-postfix in KB

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