Security News
npm Updates Search Experience with New Objective Sorting Options
npm has a revamped search experience with new, more transparent sorting options—Relevance, Downloads, Dependents, and Publish Date.
infix-postfix
Advanced tools
This package allows you to convert infix expressions to postfix expressions.
npm install infix-postfix
import infixToPostfix from "infix-postfix";
or
const infixToPostfix = require("infix-postfix");
console.log(infixToPostfix("(a+2b)^-2"));
2+3*4
▶ 2 3 4 * +
-12-3
▶ 12 − 3 -
12^-2
▶ 12 2 − ^
((2cm+112)*12.2/3)^2
▶ 2 cm * 112 + 12.2 * 3 / 2 ^
+
, -
, *
, /
, ()
, ^
get parsed to +
(addition), -
(subtraction), −
(negation), *
(multiplication), /
(division) and ^
(exponentiation). The difference between -
and −
is, that −
(negation) is an unary operator (e.g. -4
gets parsed to 4 −
) and -
(subtraction) is
a binary operator (e.g. 2-6
gets parsed to 2 6 -
).
There is no unary +
operator, because one can simply ignore such for mathematical reasons.
Unnecessary operators get removed automatically.
For example ---+4
gets parsed to 4 −
, +(12)
gets parsed to 12
.
Any variable not containing operator characters (+
, -
, ...) is supported. For example a-6
gets parsed to a 6 -
.
A common parser would parse b/10b
to b 10b /
- which is unfortunately wrong. This parser recognizes that 10
and b
are different operands. It parses the string to b 10 b * /
.
Added to that a b
gets parsed to a b *
.
To understand how this converter works set the function's second argument to true: infixToPostfix("2*2", true);
. This will print every step in detail to the console.
FAQs
infix to postfix converter
The npm package infix-postfix receives a total of 0 weekly downloads. As such, infix-postfix popularity was classified as not popular.
We found that infix-postfix demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
npm has a revamped search experience with new, more transparent sorting options—Relevance, Downloads, Dependents, and Publish Date.
Security News
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.