middles
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

middles

CircleCI codecov

Another small processing pipeline library for Nodejs.

middles enables you to compose a processing pipeline out of synchronous and asynchronous processing functions. Later, you can push arguments into the pipeline, and those items are processed by each successive processor. After the pipeline runs, either the result of the final processor is returned, or an error is thrown.

Install

In your shell:

npm install middles

Import

In your module:

import { Pipeline } from 'middles';

Use

A pipeline is a sequence of processing steps. Each item pushed onto the pipe, is processed by each step, in the order in which the steps were added.

import { Pipeline } from 'middles';

const doubled = (n: number): number => n << 1;
const magnitude = (n: number): number => n * 10;
const half = (n: number): number => n >> 1;

const contrived = new Pipeline()
	.use(doubled)
	.use(magnitude)
	.use(magnitude)
	.use(half)
	.use(doubled);

const res = contrived.push(3);

Good Practice

Well written, highly composable processors should exhibit these characteristics:

  • distrusts inputs
  • only proceeds if it can succeed (fail-fast)
  • seldom preserves state (prefer stateless behaviors)
  • performs a single responsibility
  • strive for deterministic behavior

/middles/

    Package Sidebar

    Install

    npm i middles

    Weekly Downloads

    1

    Version

    1.0.1

    License

    MIT

    Unpacked Size

    37.7 kB

    Total Files

    10

    Last publish

    Collaborators

    • cerebralkungfu