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

nano-pipe

v0.0.7

Published

A tiny library (<450 bytes gzipped) to create chainable functions/pipelines including support for async generators.

Downloads

3

Readme

nano-pipe

A tiny library (<450 bytes gzipped) to create chainable functions/pipelines including support for async generators.

Installation

npm install nano-pipe

NanoPipe uses ES2016 and is not provided in transpiled form.

Version 9x of NodeJS requires the use of the --harmony flag.

You can use the code un-transpiled in the most recent versions of Chrome and Firefox. Edge requires transpiling.

Usage

NanoPipe can be used in three easy steps:

  1. Use the static method NanoPipe.pipeable(function[,string]) to make functions chainable. You can pass in a regular function, an async function, a generator, or an async generator. If it is anonymous, you can pass in a string for the name. It will be called with each upstream value passed down the pipe bound to this. With the exception of undefined, values yielded or returned by your function are passed further down the pipeline.
function render(template) { // render a value into a string literal template
	return Function("return `" + template + "`").call(this);
}
function log() { // log a value to the console
	console.log(this);
	return this;
}
NanoPipe.pipeable(render);
NanoPipe.pipeable(log);
  1. Create pipelines using your functions, e.g.
const mypipe1 = NanoPipe().render("Name: ${this.name}").log(),
	mypipe2 = NanoPipe().log();
  1. Use the pipelines by feeding them iterables with <pipe>.pipe(iterable), including instantiated sychronous or asynchronous generators, as many times as you want, e.g.
mypipe1.pipe([{name:"Joe"},{name:"Mary"}]);

mypipe1.pipe([{name:"Jane"}]);

mypipe2.pipe([{name:"Joe"},{name:"Mary"}]);

mypipe2.pipe(async function*() { yield {name:"Joe"}; }());

pipe returns a Promise for an array of final values, so you can loop over them like this:

mypipe1.pipe([{name:"Joe"},{name:"Mary"}]).then(array => { for(const item of array) console.log(item); });

Examples

  1. Load examples/index.html in your browser to see he above code in action.

  2. Run node --harmony examples/scrape.js to see a web scraping pipeline.

API

Instance Methods

pipe(iterable) - The last call in a pipe chain invokes pipe processing and returns a Promise for an array of results based on the input iterable. All other methods are up to you!

Static Method For Custom Functions

NanoPipe.pipeable(function[,name]) - You can pass in any of the following function types to make the function available as part of a pipe:

  1. function() {}

  2. async function() {}

  3. function*() {}

  4. async function*() { }

Use name if your function is anonymous or you want to use a different name in the pipe.

pipeable is chainable so you can call NanoPipe.pipeable(f1).pipeable(f2)....

Release History (reverse chronological order)

2020-05-27 - v0.0.7 Adjusted to me more minimization robust by elimiating some compact destructures.

2018-04-30 - v0.0.6 Corrected README.md example typos.

2018-04-28 - v0.0.5 Updated scraping example.

2018-04-28 - v0.0.4 Made pipeable chainable. Added web scraping example.

2018-04-28 - v0.0.3 Added "use strict" and test script

2018-04-25 - v0.0.2 Added unit tests. Added support for multiple function types.

2018-04-25 - v0.0.1 First public release