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

pipeworks

v1.3.1

Published

Modularize functionality into execution pipelines. Create pipes. Fit 'em together. Start the flow!

Downloads

31,845

Readme

pipeworks

Create pipes. Fit 'em together. Start the flow!

With pipeworks, you can:

  • Fit components into execution pipelines.
  • Siphon the flow into branches during execution.
  • Join multiple pipelines together.
  • Intercept errors during execution.

Build Status

Example

var pipeworks = require('pipeworks');

pipeworks()
  .fit(function(context, next) {
    next(context.replace(/hot dogs/, 'tofu rolls'));
  })
  .fit(function(context, next) {
    next(context.replace(/o/g, '0')
      .replace(/e/g, '3')
      .replace(/a/g, '4')
      .replace(/l/g, '1')
      .replace(/!/, '!!11~!11!')
      .toUpperCase());
  })
  .fit(function(context, next) {
    console.log(context);
    next(context);
  })
  .flow('i bet i could eat more hot dogs than anyone!');

// Output:
// I B3T I C0U1D 34T M0R3 T0FU R011S TH4N 4NY0N3!!11~!11!

Install

$ npm install pipeworks

Usage

initialize

Start by initializing a pipeline.

var pipeworks = require('pipeworks');

var pipeline = pipeworks();

pipes

Pipes are the modular component of pipeworks. Fit pipes together to form a pipeline.

They have the following signature: function([arguments], next). Pipes can take any number of arguments you wish to pass. However, it's common to use a single context variable as a record to pass state between steps in the execution pipeline. The last parameter passed to a pipe is a reference to the next function in the pipeline. Pipes should always end with a call to next([arguments]).

See below.

var pipe = function(context, next) {
  context.scores = [25.0, 17.0, 14.7];
  next(context);
};

pipeline.fit([options], pipe)

Add a pipe to the pipeline.

options.affinity - Either hoist or sink. Adds to the pre and post queues, respectively. Ensures a pipe gets fitted before or after the main execution pipeline.

The effect of setting the pipeline affinity to 'hoist':

pipeworks()
  .fit(function(context, next) {
    console.log('Cal Naughton, Jr: Shake and bake!');
    next(context);
  })
  .fit({ affinity: 'hoist' }, function(context, next) {
    console.log('Ricky Bobby: If you ain\'t first, you\'re last!');
    next(context);
  })
  .flow({});

// Output:
// Ricky Bobby: If you ain't first, you're last!
// Cal Naughton, Jr: Shake and bake!

pipeline.siphon([arguments], next)

Redirect the flow to another pipeline.

var hijacker = pipeworks();
var main = pipeworks();

hijacker
  .fit(function(context, next) {
    context.hijacked = true;
    console.log('hijacked!');
    next(context);
  });

main
  .fit(function(context, next) {
    console.log('getting started');
    next(context);
  })
  .fit(function(context, next) {
    console.log('am i getting hijacked?');
    hijacker.siphon(context, next);
  })
  .fit(function(context, next) {
    console.log('done-zo');
    next(context);
  });

main.flow({});

// Output: 
// getting started
// am i getting hijacked?
// hijacked!
// done-zo

pipeline.join(pipeline)

Link pipelines together.

var first = pipeworks();
var second = pipeworks();
var third = pipeworks();

first
  .fit(function(context, next) {
    console.log('alpha');
    next(context);
  })
  .fit(function(context, next) {
    console.log('atlanta');
    next(context);
  });

second
  .fit(function(context, next) {
    console.log('beta');
    next(context);
  })
  .fit(function(context, next) {
    console.log('boise');
    next(context);
  });

third
  .fit(function(context, next) {
    console.log('gamma');
    next(context);
  })
  .fit(function(context, next) {
    console.log('georgetown');
    next(context);
  });

first.join(second).join(third).flow({});

// Output:
// alpha
// atlanta
// beta
// boise
// gamma
// georgetown

pipeline.flow([arguments])

Send something down the pipeline! Any number of arguments can be sent, but often there's just a single context object.

pipeworks()
  .fit(function(context, next) {
    context.age = 30;
    next(context);
  })
  .fit(function(context, next) {
    console.log(context);
    next(context);
  })
  .flow({ name: 'Kevin' });

// Output:
// { name: 'Kevin', age: 30 }

pipeline.fault(callback)

Handle errors during pipeline execution. Using pipeline.fault allows access to the current execution context when errors occur in the pipeline.

  • callback - has the signature function([arguments], error, next)
    • [arguments] - the list of arguments sent to the currently executing pipe
    • error is what was thrown
    • next is a reference to the following pipe in the pipeline. The next argument, in most cases, should not be called.

Note: It's advisable to exit the process after an uncaught exception. Exceptions leave your application in an unknown state. This method uses domains under the hood.

var breakfast = pipeworks()
  .fit(function(context, next) {
    process.nextTick(function() {
      if (context.flavor !== 'cinnamon') {
        throw new Error('These waffles are not *jazzy*!');
      }
    }); // simulate async I/O operation
  })
  .fit(function(context, next) {
    console.log('Thanks for breakfast!'); // never reached
  });

breakfast.fault(function(context, error) {
  console.log('Flavor on error:', context.flavor);
  console.log(error.stack);
  process.exit(); // the safe play
});

breakfast.flow({ flavor: 'plain' })

Usage Notes: Joined pipelines should be treated as new pipelines. Use fault on the joined pipeline itself for reliability. It is possible to have different fault handlers for each pipeline when using siphon.

Enjoy!

License

MIT