
Security News
Vite+ Joins the Push to Consolidate JavaScript Tooling
Evan You announces Vite+, a commercial, Rust-powered toolchain built on the Vite ecosystem to unify JavaScript development and fund open source.
pipe-functions
Advanced tools
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
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
Key features:
Promises
Promises
will be executed sequentiallyString
, Number
, Date
, etc.) or even a Function
or a Promise
npm install pipe-functions
const pipe = require('pipe-functions');
// First argument can be of any type
const result = pipe('input', fn1, fn2, fnN);
// And also a function
const result2 = pipe(fn0, fn1, fn2, fnN);
Promises
)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 = require('pipe-functions');
// First argument can be of any type, as shown in the previous example
pipe('input', fn1, fnPromise1, fn2, fnPromise2).then(console.log);
OBS: Some examples needs a platform with support for Destructuring (Nodejs v6+, Chrome).
const pipe = require('pipe-functions');
/** Functions **/
const capitalize = v => v[0].toUpperCase() + v.slice(1);
const quote = v => `"${v}"`;
/** Pipe **/
// result will be: "Time"
const result = pipe('time', capitalize, quote);
Promises
)const pipe = require('pipe-functions');
/** Functions **/
// Sync
const capitalize = v => v[0].toUpperCase() + v.slice(1);
// Async
const fetchAndSetBandName = v => new Promise((resolve, reject) => setTimeout(() => resolve(`Pink Floyd - ${v}`), 1000));
/** Pipe **/
// the result will be: Pink Floyd - Time
pipe('time', capitalize, fetchAndSetBandName).then(console.log)
To easily pass in more than one value (within an Object or Array) through the pipeline.
const pipe = require('pipe-functions');
/** Functions **/
// Async
const fetchBandName = ({ song }) => new Promise((resolve, reject) =>
setTimeout(() => resolve({ song, band: 'Pink Floyd' }), 1000));
// Sync
const concatBandAndSong = ({ song, band }) => `${band} - ${song}`;
/** Pipe **/
// the result will be: Pink Floyd - Time
pipe('time', fetchBandName, concatBandAndSong).then(console.log)
FAQs
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
The npm package pipe-functions receives a total of 88,414 weekly downloads. As such, pipe-functions popularity was classified as popular.
We found that pipe-functions demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Evan You announces Vite+, a commercial, Rust-powered toolchain built on the Vite ecosystem to unify JavaScript development and fund open source.
Security News
Ruby Central’s incident report on the RubyGems.org access dispute sparks backlash from former maintainers and renewed debate over project governance.
Research
/Security News
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.