flitbit / middles

Another small middleware pipeline library for Nodejs.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

About

Another small middleware pipeline library for Nodejs.

License:MIT License


Languages

Language:TypeScript 77.3%Language:JavaScript 14.7%Language:HTML 8.0%