Socket
Socket
Sign inDemoInstall

@blakek/fn-pipe

Package Overview
Dependencies
0
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @blakek/fn-pipe

🚰 Compose functions and promises to make a pipeline


Version published
Weekly downloads
0
Maintainers
1
Created
Weekly downloads
 

Readme

Source

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 buildBuilds the project to ./dist
yarn formatFormat the source following the Prettier styles
yarn testRun project tests
yarn test --watchRun project tests, watching for file changes

License

MIT

Keywords

FAQs

Last updated on 03 Jun 2020

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc