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-ts

v0.0.3

Published

revers polish notation calculator

Downloads

14

Readme

npm install rpn-ts

usage

import Rpn from "rpn-calculator"
const rpn = new Rpn();

const value = rpn.valueOf("sin(10ded)^ * cos(10deg)^") // 1
const value = rpn.valueOf("2x + 3!")//

if(value === null && rpn.last.details.isFunction){
   // rpn.last.details.funcVarNames // return ["x"]
	const values = rpn.valuesOf([{x: 1}, {x:2}]); // [8, 10]
}

methods

  • valueOf("expression") - return value of mathematical expression or null if is functions

  • valuesOf([{x: number, y:number}], ?:IExpression) - return array of values for given array of arguments - if you don't pass expression it will calculate it for last computed expression;

  • last - return last computed IExpression

  • lastValue - return last computed value

  • expressionFrom - compute rpn expression for given string

  • use(extension: func | IProcces, ?: (race: proccessedId[]) => number)

  • exclude - remove given procces from computed pipe

  • extend(processId: string, transform(process: IProcess) => IProcess) -extend given procc

##allowed expressions

  • Values
    • "1.41545" - floated number
    • "-45" - negative number
    • "3Pi" - 3 * 3,14
    • "2e" - 2 * const e
    • "3x + 5z + 9t" - any letter is threaded as variable (expect e)
  • Basic operation
    • "1 + 2" - Summation
    • "1 - 2" - Subtraction
    • "1 * 2" - Multiplication
    • "2 / 2" - Division
    • "3!" - Factorial
    • "3^" - 2 to power of 2
  • Functions
    • "sin(3)" sin of number 3
    • "cos(3deg)" cos of angle 3 degrees
    • "ctg(3x)" cotangent of variable 3 * x
    • "tg(3)" tangent
    • "ln()" - natural logarithm
    • "log(3,2)" - logarithm of 3 on base 2
    • "sqrt(3)" - square root of number 3
    • "root(27, 3)" - third root of 27
    • "pow(2,5)" - 2 to power of 5
    • "abs(-4)" - absolut value of -4
    • "| -4 |" - absolute value of -4
  • Grouping and organization
    • "3 * (4 + 1)" - brackets
    • "5 + [1 + 2] *2" - brackets
    • "pow(3, 5)" - comma separator of function args
  • Comparisons
    • "1 > 3" - greeter
    • "1 >= 3" - greeter or equal
    • "3 < 5" - less
    • "6 <= 6" - less or equal
    • "3x = 3" - equal

expression erros

import Rpn from "rpn-calculator"
const rpn = new Rpn();

const value = rpn.valueOf("()[(pow(4)))") 
if(!value && rpn.last.errors){
    rpn.last.errors.forEach(error =>{
        console.log(error.id, error.message, error.position)
    })
    //will print 
    // EmptyBracket, Expression contains empty bracket pattern, 2
    // BracketMissmatch, Incorrect sequence of brackets, 10
    // FunctionArgument, Function power expect to have 2 arguments
}