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 🙏

© 2025 – Pkg Stats / Ryan Hefner

k-pipeline

v3.3.1

Published

Executes a bunch of callback styled functions serially

Downloads

39

Readme

k-pipeline

Executes a bunch of callback styled functions serially

This is an adhoc/opinionated version of the popular async.<waterfall|serial>

npm status Travis build status Dependency status

install

With npm do:

npm install k-pipeline

example - flow control

const Pipeline = require('k-pipeline')
const assert = require('assert')

let pipeline = Pipeline.create([
    
    // state is just a new javascript object
    (state, ops) => { 
        state.foo = 'bar'
        ops.next() 
    },

    // stop the execution in the middle -> jump directly to final callback
    (state, ops) => { 
        assert(state.foo === 'bar')
        ops.stop() 
    }, 
    
    // this will not be executed
    (state, ops) => { ops.next() }
])

pipeline.run((err, state, isStop) => {
    assert(isStop)
})

example - pipeline callback api is available as both functions or methods of the first parameter

const Pipeline = require('k-pipeline')

let pipeline = Pipeline.create([
    (state, ops) => { 
        ops.next() // === ops()
        // ops.stop()
        // ops.loop()
        // ops.save('foo')
    },
    (state, next, stop, loop, save) => { 
        next()
    }
])

// override constructor state
pipeline.run((err, state) => {})

example - custom state

const Pipeline = require('k-pipeline')

let aState = { foo: 'bar' }
let pipeline = Pipeline.create([
    (state, next) => { 
        console.log(state === aState) // true
        next()
    }
])

// override constructor state
pipeline.run(aState, (err, state) => {
    console.log(state === aState) // true
})

example - reuse the pipeline

const Pipeline = require('k-pipeline')

let aState = { foo: 'bar' }
let pipeline = Pipeline.create([
    (state, next) => { next() }
])

// state will reset to a new javascript object each run()
pipeline.run((err, state) => {
    pipeline.run((err, state) => { 
    })
})

example - error in the pipe

const Pipeline = require('k-pipeline')

let error = new Error()
let pipeline = Pipeline.create([
    (state, next) => { next(error) },
    (state, next) => { next() } // will not be executed
])

pipeline.run((err, state) => {
    console.log(error === err) //true
})

example - stopping the pipeline

const Pipeline = require('k-pipeline')
const assert = require('assert')

let aState = { foo: 'bar' }
let pipeline = Pipeline.create([
    (state, ops) => { ops.next() },
    (state, ops) => { ops.stop() },
    (state, ops) => { ops.next() } // will never get executed
])

// state will reset to a new javascript object each run()
pipeline.run((err, state, isStop) => {
    assert(isStop)
})

example - loops inside the pipeline

const Pipeline = require('k-pipeline')
const assert = require('assert')

let aState = { foo: 'bar' }
let pipeline = Pipeline.create([
    (state, ops) => { 
        state.count = 0 
        ops.next() 
    },
    (state, ops) => { 
        if (++state.count === 10) return ops.loop()
        ops.next()
    },
    (state, next) => { next() }
])

// state will reset to a new javascript object each run()
pipeline.run((err, state, isStop) => {
    assert(state.count === 10)
})

example - save results of an operation to the pipeline state

const Pipeline = require('k-pipeline')
const assert = require('assert')

function foo(callback) {
    callback(null, 1, 2, 3)
}

let pipeline = Pipeline.create([
    (state, ops) => { 
        foo(ops.save('foo'))
    }
])

// state will reset to a new javascript object each run()
pipeline.run((err, state, isStop) => {
    assert.deepStrictEqual([1, 2, 3], state.foo)
})

stuff you can't do

call a callback twice
const Pipeline = require('k-pipeline')

let pipeline = Pipeline.create([
    (state, next, stop) => { 
        next()
        next() // throws an error
    }
])

pipeline.run((err, state) => {})
call run() twice in the same tick
const Pipeline = require('k-pipeline')

let pipeline = Pipeline.create([
    (state, next, stop) => { next() }
])

pipeline.run((err, state) => {})
pipeline.run((err, state) => {}) // throws an error

Changelog

3.3.0

  • add save() to callback api
  • expose all callback functions as method of the first parameter: (state, next, stop, loop, save) => {} can now be written as (state, ops) => { ops.save(); ops.stop() ...}

license

MIT © yaniv kessler