Pipe functions in a Unix-like style. It supports
Promises (async) anywhere in the pipeline and every step will be executed sequentially. The return (resolve in case of
Promises) of each function will be passed in as an argument to the next one
Promises, or any lib following the Promises/A+ spec about being thenable (.then() method)
Promiseswill be executed sequentially
- First argument can be of any type (
Date, etc.) or even a
- Node.js and Browser ready (to be used on a Browser, without a build step, check
- Lightweight, 501 bytes, before gzip!
NPM / Node
npm install pipe-functions
const pipe = ;// First argument can be of any typeconst result = ;// And also a functionconst result2 = ;
If the pipeline contains a
Promise anywhere in the pipeline, we must treat
pipe like a
Promise itself, so we must to use .then() to get the final result.
const pipe = ;// First argument can be of any type, as shown in the previous example;
A suggestion regarding
Promises. Probably you've seen, or had to write, a stack of promises like that:
It could be written as:
const pipe = ;
OBS: Some examples needs a platform with support for Destructuring (Nodejs v6+, Chrome).
const pipe = ;/** Functions **/const capitalize = v0 + v;const quote = `""`;/** Pipe **/// result will be: "Time"const result = ;
const pipe = ;/** Functions **/// Syncconst capitalize = v0 + v;// Asyncconst fetchAndSetBandName = ;/** Pipe **/// the result will be: Pink Floyd - Time
Example with destructuring,
To easily pass in more than one value (within an Object or Array) through the pipeline.
const pipe = ;/** Functions **/// Asyncconst fetchBandName =;// Syncconst concatBandAndSong = ` - `;/** Pipe **/// the result will be: Pink Floyd - Time