开发者社区> 镜像站> NPM> @blakek/fn-pipe
@blakek/fn-pipe
🚰 Compose functions and promises to make a pipeline
Last updated 6 months ago by blakek .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @blakek/fn-pipe 
SYNC missed versions from official npm registry.

Function Pipe

???? Compose functions and promises to make a pipeline

Code can become complex when several functions wrap others or reduce() is abused for a list of funtions.

This is an alternative that allows creating a pipeline of the functions and calls them in order.

Install

Using Yarn:

$ yarn add @blakek/fn-pipe

…or using npm:

$ npm i --save @blakek/fn-pipe

Usage

This example fetches a list of todos from a server, filters for completed todos, and counts the result.

import { fnPipe } from 'fn-pipe';

const userId = 5;

const getCompletedCount = fnPipe([
  userId => fetch(`https://jsonplaceholder.typicode.com/todos?userId=${userId}`)
  todos => todos.filter(todo => todo.complted),
  todos => todos.length
], userId);

getCompletedCount(); //» 12

API

fnPipe

function fnPipe([fn, ...fns]: Function[], initialValue?: any): Promise<any>;

Contributing

Node.js and Yarn are required to work with this project.

To install all dependencies, run:

yarn

Useful Commands

yarn build Builds the project to ./dist
yarn format Format the source following the Prettier styles
yarn test Run project tests
yarn test --watch Run project tests, watching for file changes

License

MIT

Current Tags

  • 2.0.2                                ...           latest (6 months ago)

6 Versions

  • 2.0.2                                ...           6 months ago
  • 2.0.1                                ...           6 months ago
  • 2.0.0                                ...           6 months ago
  • 1.0.1                                ...           6 months ago
  • 1.0.0                                ...           6 months ago
  • 0.1.0                                ...           6 months ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 6
Last Month 12
Dependencies (0)
None
Dependents (0)
None