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

rpn-cli

v2.1.2

Published

Command line RPN calculator using math.js engine. example: '$ rpn 1 2 +'

Downloads

31

Readme

rpn-cli - Command Line RPN Calculator

RPN(Reverse Polish Notation) HP stype calculator for command line. using math.js engine.

Similar to unix dc command but you can write formula in command line parameters not only stdin like below.

>rpn 1 2 +
#result:3

>echo $(rpn 1 2 +)
#result:3

dc style is also suported(-s option). You can mix stdin formula and command line.

>rpn -s <<<'1 2 +'
#result:3

>echo '1 2'|rpn -s +
#same as rpn 1 2 +

>rpn '1 1 1 +'|rpn -s +
#pipeline,same as echo '1 2'|rpn -s +

Compare to ruby rcalc, rpn-cli is simple but is designed for easy and short to type formula. For example, "(sin(1/3) - cos(1/3))^2" is "3 inv dup sin swap cos - sqr p" in rcalc, "3ipswc-2^" in rpn-cli.

All operators are single charactor and not necessary to be escaped in bash shell.

Multiply can be "x" (to avoid bash * wildcard)

>rpn 2 2 x
#result:4

Seperator(white space) can be comma(,) or omit it

>rpn 2,2x
#result:4

>rpn 1,1,1,1++++
#result:4

You can use rpn-cli as module.

rpn=require("rpn-cli");
try{
	rs=rpn([1,2,'+']);
	console.log(rs[0]); //'3'
}catch(e){
	console.error(e);
}

Install

sudo npm install -g rpn-cli

Usage

cli.js [-h?dsb] <formula>
version 2.1.2
Copyright(c) 2017-2019 @kssfilo(https://kanasys.com/gtech/)
options:
	-d:debug
	-s:mix stdin "<stdin formula> <command line formula>"
	-b:64 digits precition mode (default:14 digits)
	-h/-?:this help

operators:
	+:add last two stack elements
	-:subtract element 1 from element 2
	x:multiply last two stack elements (* is ok but need escape in bash)
	/:divide element 2 by element 1
	%:element 2 mod element 1

	^:raise element 2 to the power of element 1
	v:n-th root (element 1 root of element 2)
	2v:(combination) squrare root

	n:Negate last element
	i:Invert last element
	a:Absolute value (last element)
	l:Log e (last element)
	L:exponent of e (last element,reverse function of Log e)
	f:Factorial (last element,! is ok but need escape in bash)

	s:Sin (last element,ragian)
	c:Cos (last element,ragian)
	t:Tan (last element,radian)
	S:arcSin (last element,radian)
	C:arcCos (last element,radian)
	T:arcTan (last element,radian)
	P/180x:(combination) radian -> degree (last element)
	180/Px:(combination) degree -> radian (last element)

	_:floor last element
	=:round last element
	1+_:(combination) ceil last element

	w:sWap last 2 elements
	r:Rotate all elements(1 2 3 -> 3 1 2)
	R:Rotate all elements(1 2 3 -> 2 3 1)
	d:Drop last element
	D:Drop all elements
	V:Drop except last elements
	p:duP last element

	Y:move last element to 0th Register
	y:recall from 0th Register
	Q:move element 2 to <element 1>th Register
	q:recall from <element 1>th Register

	N:couNt all elements and push to stack
	M:find Max of all elements and push to stack
	m:find Min of all elements and push to stack
	A:sum of All elements and push to stack
	X:product of all elements and push to stack

	F:apply next operator to all elements(1,2,3,F,1,+ -> 2,3,4)

	NyAY/V:(combination) arithmetic mean(avarage)
	NyXYvV:(combination) geometric mean
	NyAY/F-F2^AY1-/2vV:(combination) standard deviation

constants:
	P:Pi
	1L:(combination) base of natural logarithm(e)

number:
	e:Exponent (5e3 -> 5000/5e-3 -> 0.005)
	-:negative(<any operator/number>- -> subtract,for example:1-1 -> 1 - 1 but 1 -1 -> 1 -1)

example:
	cli.js 1 2 +  #result:3
	cli.js 1 2 1++ #result:4
	cli.js 1,2,1++ #result:4
	
	cli.js 1 2 1 + +|cli.js -s 3 + #pipeline:same as cli.js 1 2 1 + + 3 +
	cli.js -s <<<'1 2 +' #dc style
	
	cli.js 5e3 5 / #same as cli.js 5000 5 /
	cli.js 10 3 /=  #round:3.3333 -> 3

Change Log

  • 2.1.0:upgrades internal mathjs engine to v6
  • 2.0.0:breaking change:store(y/q)/recall(Y/Q) -> store(Y/Q)/recall(y/q)
  • 1.1.0:added statistics operator:count(N)/sum(A)/product(X)/max(M)/min(m)
  • 1.1.0:added register feature:store(y/q)/recall(Y/Q)
  • 1.1.0:added various removing operator:except last element(V)/all(D)
  • 0.3.x:added sin(s)/cos(c)/tan(t)/asin(S)/acos(C)/atan(T)/Pi(P)/v(n-th root)/R(reverse rotate)
  • 0.3.x:s(square root) has been deprecated(use 2v)
  • 0.3.x:c(ceil) has been deprecated(use 1+_)
  • 0.2.x:added factorial(f)/drop(d)/dup(p)/log(l)/exponent(L)/-b option
  • 0.2.x:constant E has been deprecated(use 1E)
  • 0.1.x:added ceil(c)/floor(f)/round(r)
  • 0.0.x:first release