Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
A module for grafting a function pipe (middleware) over other functions in nodejs.
A function pipe eases the construction of extensible processing pipelines.
Each step in the pipeline takes the result of the prior step as input, and produces its own result, which in turn, is used by the next step in the pipeline, until processing is complete and a final result is produced. Each step in the pipeline can be thought of as middleware, but unlike the connect framework, the inputs and outputs are not related to nodejs' original callback pattern.
The 2018 version 1.0.0 has very little in common with the version published in 2012. The 2018 version of the Pipe
is exclusively ES6, and is intended for use in nodejs.
Create a pipeline by constructing an instance of the Pipe
class, optionally specifying initial processing steps, then as needed, add additional processing steps using the .pipe()
method, and eventually, execute the pipeline using the .process()
method.
const res = await new Pipe(fn1)
.pipe(fn2)
.pipe(fn3)
.process('an argument for fn1');
console.log(`Result of pipeline processing: ${res}`);
The result of each step in the process cascades into the next step, just like Promise
's .then()
method.
arg ---v
fn1(arg1) ---v
fn2(arg2) ---v
fn3(arg3) ---v
result
The constructor can take multiple steps...
const res = await new Pipe(fn1, fn2, fn3).process('an argument for fn1');
console.log(`Result of pipeline processing: ${res}`);
.pipe()
can take multiple steps...
const res = await new Pipe(fn2)
.pipe(
fn2,
fn3
)
.process(42);
Arguments passed to .process()
are projected into the first step...
const res = await new Pipe((x, y) => x + y)
.pipe(x => x + 1)
.pipe(x => x * 2)
.process(10, 10);
Each step's result can be projected down stream in the pipe...
const res = await new Pipe((x, y) => [x * 2, y * 5], true)
.pipe(
(x, y) => [x + y, 1],
true
)
.pipe((x, y) => (x + y) * 2)
.process(5, 2);
Errors propagate to the caller...
const stdout = console.log.bind(console);
try {
const res = await new Pipe()
.pipe(() => stdout('click'))
.pipe(() => stdout('click'))
.pipe(() => {
throw new Error('Boom!');
})
.pipe(() => stdout('click'))
.pipe(() => stdout('click'))
.process();
} catch (err) {
assert.equal('Boom!', err.message);
}
FAQs
A module for grafting a function pipe (middleware) over other functions in nodejs.
The npm package fpipe receives a total of 0 weekly downloads. As such, fpipe popularity was classified as not popular.
We found that fpipe 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
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.