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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@followwinter/rpn-calculate

v2.0.0

Published

波兰计算器 --- > 用[逆波兰表达式](https://zh.m.wikipedia.org/wiki/%E6%B3%A2%E5%85%B0%E8%A1%A8%E7%A4%BA%E6%B3%95)实现的计算器 ### 版本 - v1.0.0 这个版本不推荐用, 在逆波兰计算上有错误, 并且在词素化的环节使用的方式对维护不友好 - v2.0.0 与 v1.0.0 不兼容, 完全重写的代码和重新设计的 api, 将整个分析过程规范化: `词法分析`->`语法分析`->`转化RPN`->`计算结果`

Readme

波兰计算器

逆波兰表达式实现的计算器

版本

  • v1.0.0 这个版本不推荐用, 在逆波兰计算上有错误, 并且在词素化的环节使用的方式对维护不友好
  • v2.0.0 与 v1.0.0 不兼容, 完全重写的代码和重新设计的 api, 将整个分析过程规范化: 词法分析->语法分析->转化RPN->计算结果

功能

  • 任意顺序的四则+-*/运算
  • 支持()
  • 前端后端通用
  • 提供直接计算函数
  • 提供四则运算表达式转逆波兰AST函数
  • 提供语法分析函数(暂时只支持上下两个字符判定)

问题

  • ~~暂未支持语法分析, 也就是输入错误格式的表达式也不会报错, 下一个版本将会引入~~
  • ~~已经引入词法分析, 使用向下递归解析, 但是只支持上下两个字符之间判定, 而无法全文判定, 主要是左右括号的匹配~~
  • 使用引用计数修复括号匹配的问题, 前后字符词法分析, 已经解决了括号问题了

脚本

  • 测试: npm run test
  • 打包: npm run build

安装

npm install --save @followwinter/rpn-calculate

使用

// 计算
rpn.calculateText(`1+2`) // 3

// 语法检测
rpn.syntaxAnalyzeText(`1+2`) // true
rpn.syntaxAnalyzeText(`)))`) // syntax error: ....

// 中缀转后缀
rpn.parseText(`1+2`) // [{"type": "TYPE_NUMBER", "value": 1}, {"type": "TYPE_NUMBER", "value": 1}, {"type": "TYPE_OPERATION_ADD","value": "+"}]

api介绍

所有以Text结尾的api都是直接封装了中间环节的

  • rpn.calculateText(text:String):Number: 根据输入的表达式字符串计算结果
    rpn.calculateText(`1+1`) // 2
  • rpn.parseText(text:String):List<RpnASTNode>: 根据输入的表达式字符串转化成后缀表达式AST
    rpn.parseText(`1+1`) // [{"type": "TYPE_NUMBER", "value": 1}, {"type": "TYPE_NUMBER", "value": 1}, {"type": "TYPE_OPERATION_ADD","value": "+"}]
  • rpn.syntaxAnalyzeText(text:String):true|throw error: 根据输入的表达式字符串检测语法是否正确
    rpn.syntaxAnalyzeText(`1+1`) // true

效果

rpn