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

soft-processor

v0.2.3

Published

A soft processor which can run simple calculation programs.

Downloads

11

Readme

Demo

Simple calculation

const c = {
  a: 10,
  b: 20
}
const p = new Processor(c)
let r:any = null

r = p.run(`
  a+b;
  _r/7;
  .2;
`)
console.log(Object.keys(r), (r._r as Big).toNumber())

Processor supports + - * / as mathematical operators. _r is the intermediate result during the calculation process. Special operator . means round function Result r from Processor.run is the whole context Result r._r is the calculation result and its type is Big.

Special operator :

r = p.run(`
a-b;
:tmp;
tmp*6;
`)
console.log(Object.keys(r), (r._r as Big).toNumber(), (r.tmp as Big).toNumber())

Special operator : means create a new field in the context and save the intermediate result into this new field. The following calculation can use this new field.

Special operators \\

r = p.run(`
a-b;
\\abs;
`)
console.log(Object.keys(r), (r._r as Big).toNumber())

Special operator \\ means executing a Big function and using the intermediate result as the input parameter

Special operators !

const pf1 = new Processor(c, {
  demo1: (a:number, b:number) => {
    // return a Big instance will update the context._r
    // else the context._r will keep unchanged
    return Big(a + b)
  }
})
r = pf1.run(`
!demo1,a,b;
`)
console.log(Object.keys(r), (r._r as Big).toNumber())

Processor constructor accepts the 2nd input parameter as extension. You may provide your own extension functions here. Special operator ! means executing a Big function and using specified context fields as input parameters

const pf2 = new Processor(c, {
  demo2: (c:ContextType) => {
    console.log(c)
    // return a Big instance will update the context._r
    // else the context._r will keep unchanged
    return Big(c.a || 0).times(c.b || 0)
  }
})
r = pf2.run(`
!demo2;
`)
console.log(Object.keys(r), (r._r as Big).toNumber())

If no context fields specified, the whole context will be pass into the extension function as input parameter