npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

infix-postfix

v3.0.2

Published

infix to postfix converter

Downloads

36

Readme

infix-postfix

This package allows you to convert infix expressions to postfix expressions.

Installation

npm install infix-postfix

Usage

Importing

import infixToPostfix from "infix-postfix";

or

const infixToPostfix = require("infix-postfix");

Converting

to a string
console.log(infixToPostfix("(a+2b)^-2").toString());

/* Output:
    a 2 b * + 2 − ^
*/
to an array
console.log(infixToPostfix("(a+2b)^-2").toArray());

/* Output:
    [
      'a', 2, 'b', '*',
      '+', 2, '−', '^'
    ]
*/

Examples

2+3*42 3 4 * + a b(3+4)2a b * 3 4 + * 2 * -12-312 − 3 - 12^-212 2 − ^ ((2cm+112)*12.2/3)^22 cm * 112 + 12.2 * 3 / 2 ^

Features

Operator parsing

+, -, *, /, (), ^ 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.

Operator reduction

Unnecessary operators get removed automatically. For example ---+4 gets parsed to 4 −, +(12) gets parsed to 12.

Number parsing support

Numbers get parsed. Obviously only works with the toArray() method.

Variable support

Any variable not containing operator characters (+, -, ...) is supported. For example a-6 gets parsed to a 6 -.

Multiplication shortcut support

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 *. Furthermore a(3)2 is translated to a 3 * 2 *.