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

jsrpn

v1.0.1

Published

Reverse Polish Notation tools. Translate infix expression to reverse polish notation (postfix expression) and Calculate reverse polish notation. support + - * / ^ % ! √ ( )

Downloads

4

Readme

逆波兰表达式工具Reverse Polish Notation tool

1. 介绍Intro

逆波兰表达式工具Reverse polish notation tool, 普通表达式 和 逆波兰表达式 互相转换 translate between infix expression and reverse polish notation, 计算 普通表达式 和 逆波兰表达式calculate infix expression and reverse polish notation, 支持 + - * / ^ % ! √ ( )support + - * / ^ % ! √ ( ).

可以在浏览器里使用,也可以当作Node的模块使用the tool is both can work in browser and work as a node module.


2. 用法Usage

2.1 Node

$npm install jsrpn
$node
> let rpn = require('rpn.js');
> console.log(rpn.calculate('1+2+3+4+5+√√81!'));
21

2.2 Browser

<script src='./rpn.js'></script>

<script>console.log(rpn.calculate('1+2+3+4+5+√√81!')); //21 </script>


3. 接口Interface

3.1 计算算式表达式Calculate infix expression

rpn.calculate(expression)

范例Example
rpn.calculate('1+2+3');
6
rpn.calculate('8!');
40320
rpn.calculate('√81');
9
rpn.calculate('√√81!');
6
rpn.calculate('1+2+3+4+5+√√81!');
21
rpn.calculate('1+2*3+4/5');
7.8
rpn.calculate('1+2^3');
9
rpn.calculate('1%+2^3');
8.01
rpn.calculate('15%+2^3');
8.15

3.2 转换算式表达式为逆波兰表达式Translate infix expression to reverse polish notation

rpn.infix2rpn(expression)

范例Example

rpn.infix2rpn('1+2+3');
"1 2 + 3 +"
rpn.infix2rpn('8!');
"8 !"
rpn.infix2rpn('√81');
"81 √"
rpn.infix2rpn('√√81!');
"81 √ √ !"
rpn.infix2rpn('1+2+3+4+5+√√81!');
"1 2 + 3 + 4 + 5 + 81 √ √ ! +"
rpn.infix2rpn('1+2*3+4/5');
"1 2 3 * + 4 5 / +"
rpn.infix2rpn('1+2^3');
"1 2 3 ^ +"
rpn.infix2rpn('1%+2^3');
"1 % 2 3 ^ +"
rpn.infix2rpn('15%+2^3');
"15 % 2 3 ^ +"

3.3 计算逆波兰表达式Calculate reverse polish notation

rpn.rpnCalculate(expression)

范例Example

rpn.rpnCalculate('1 2 + 3 +');
6
rpn.rpnCalculate('8 !');
40320
rpn.rpnCalculate('81 √');
9
rpn.rpnCalculate('81 √ √ !');
6
rpn.rpnCalculate('1 2 + 3 + 4 + 5 + 81 √ √ ! +');
21
rpn.rpnCalculate('1 2 3 * + 4 5 / +');
7.8
rpn.rpnCalculate('1 2 3 ^ +');
9
rpn.rpnCalculate('1 % 2 3 ^ +');
8.01
rpn.rpnCalculate('15 % 2 3 ^ +');
8.15

3.4 转换逆波兰表达式为算式表达式Translate reverse polish notation to infix expression

rpn.rpn2infix(expression)

范例Example

rpn.rpn2infix('1 2 + 3 +');
"1 + 2 + 3"
rpn.rpn2infix('8 !');
"8!"
rpn.rpn2infix('81 √');
"√81"
rpn.rpn2infix('81 √ √ !');
"√√81!"
rpn.rpn2infix('1 2 + 3 + 4 + 5 + 81 √ √ ! +');
"1 + 2 + 3 + 4 + 5 + √√81!"
rpn.rpn2infix('1 2 3 * + 4 5 / +');
"1 + 2 * 3 + 4 / 5"
rpn.rpn2infix('1 2 3 ^ +');
"1 + 2 ^ 3"
rpn.rpn2infix('1 % 2 3 ^ +');
"1% + 2 ^ 3"
rpn.rpn2infix('15 % 2 3 ^ +');
"15% + 2 ^ 3"

4. 调试及测试Debug and testing

  • mocha
  • 如果有全局安装 'mocha' 工具,用命令直接启动测试If 'mocha' already installed as a global tool, use command to start testing
  • npm install
  • 安装测试工具 mocha 和 测试报告工具 mochawesomeUse this command to install test tool 'mocha' and test report tool 'mochawesome'
  • npm test
  • 用命令会启动测试,完成后测试报告会显示在浏览器里Use this command to start testing, and the test report will open in browser after test finish.