pipeoperator

0.1.1 • Public • Published

pipeoperator

A library that creates pipelines in JavaScript. It works exactly like the pipe operator from Elixir or Bash.

Installation

npm install pipeoperator
import { pipeline } from 'pipeoperator';

Usage

 
const pipedValue = pipeline(value)
  .pipe(doSomething)
  .pipe(doSomethingElse)
  .pipe(doAnotherThing)
  .pipe(value => value.map(v => v.property))
  .result();
  
function doSomething(arg) { /* ... */ }
function doSomethingElse(arg) { /* ... */ }
function doAnotherThing(arg) { /* ... */ }

pipe() also takes additional arguments that are passed into the called function:

const total = pipeline(1)
  .pipe(sum, 3, 2)
  .pipe(sum, 4)
  .result();
 
// total === 10
 
function sum(...args) {
  return args.reduce((total, number) => {
    return total + number;
  }, 0);
}

Package Sidebar

Install

npm i pipeoperator

Weekly Downloads

2

Version

0.1.1

License

MIT

Last publish

Collaborators

  • octav445