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

jumpstack

v0.0.3

Published

Minimalistic callback style helpers like chain, parallel, parallelMap etc.

Downloads

7

Readme

node-typescript-boilerplate

Minimalistic callback style async function helpers

Quick start

npm i jumpstack

Chain

Chain runs your callback functions sequentially. Passing the callback value to the next step.

If it encounters an error, jumps to the end callback.

  chain([
   (cb) => redis.get('foo', cb),
   (cb, data) => {
     dosomething(data);
     redis.get('bar', data, cb)},
  ]).then((data)=>{
    console.log(data)
  })

or use it in callback style,

 chain([
  (cb) => redis.get('foo', cb),
  (cb, data) => {
    // data is the callback value from the previous step
    dosomething(data);
    redis.get('bar', data, cb);
  }
 ], (err, value) => {

 })

Chain, also has a context variable - this was one of the main reasons for this library, because it is very convenient to add something to context in a step and then get it back somewhere else.

    chain([
      (cb) => { cb(null, 1); },
      (cb, v, ctx) => { ctx.add({ctxVal: 'ctx'}); cb(null, v+1); },
      (cb, v) => { cb(null, v+2); },
      (cb, _v, ctx) => { cb(null, ctx.get('ctxVal')); }

    ], (err, val) => {

    })

also you can break chain by using context, this will break the chain, set the value and skip the remaning steps

    chain([
      (cb, _, ctx)=>{
        ctx.break("test", cb)
      },
      (cb)=>cb(null, "123")
    ], (_err, val)=>{
      // val will be "test"
    })

you can also use chain with a timeout (which I find it super-handy to debug)

    chainWithTimeout([
      (cb) => {
        // do something heavy
        cb(null, val); // if it takes more than X seconds, it will raise Error
      },
    ], 1000, // max time to wait in every step
    (_err, _val)=>{
      done();
    })

mapChain

mapChain iterates over your input and collects values returned by your cb function.

    mapChain([1,2,3], (value, cb)=>{
      cb(null, value+1)
    }, (errors, values)=>{
      // values will be [2,3,4]
      // in the same order as the input
    })

parallel

parallel just runs your functions, and then run your callback function

Its handy when you don't really care about the return values and just want to wait for some functions to complete.

    parallel([
      (cb)=>cb(null, 1),
      (cb)=>cb(null, 2),
      (cb)=>cb(null, 3),
    ], (_errs, val)=>{
      // val will be 3
      // this will run after all functions have completed
    })

parallelMap

works like mapChain but doesn't keep the order. Most of the time you'll just use mapChain. This is only useful when you want to sort values by execution time

  • if you'll ever need that
    parallelMap([1,2,3], (value, cb)=>{
      cb(null, value+1)
    }, (errors, values)=>{
      // values will be [2,3,4] or [3,2,4] or [4,2,3] etc.
      // in the same order as the input
    })

Unit tests

Run

npm test

Available scripts

  • clean - remove coverage data, Jest cache and transpiled files,
  • build - transpile TypeScript to ES6,
  • build:watch - interactive watch mode to automatically transpile source files,
  • lint - lint source files and tests,
  • test - run tests,
  • test:watch - interactive watch mode to automatically re-run tests

License

BSD