You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.4 KiB

4 years ago
  1. # p-pipe [![Build Status](https://travis-ci.org/sindresorhus/p-pipe.svg?branch=master)](https://travis-ci.org/sindresorhus/p-pipe)
  2. > Compose promise-returning & async functions into a reusable pipeline
  3. ## Install
  4. ```
  5. $ npm install p-pipe
  6. ```
  7. ## Usage
  8. ```js
  9. const pPipe = require('p-pipe');
  10. const addUnicorn = str => Promise.resolve(`${str} Unicorn`);
  11. const addRainbow = str => Promise.resolve(`${str} Rainbow`);
  12. const pipeline = pPipe(addUnicorn, addRainbow);
  13. pipeline('❤️').then(console.log);
  14. //=> '❤️ Unicorn Rainbow'
  15. ```
  16. ## API
  17. ### pPipe(input, …)
  18. The `input` functions are applied from left to right.
  19. You can also specify an array as the first argument instead of multiple function arguments. Mostly only useful if you have to support Node.js 4. With Node.js 6 and above you can just use spread syntax.
  20. #### input
  21. Type: `Function`
  22. Expected to return a `Promise` or any value.
  23. ## Related
  24. - [p-each-series](https://github.com/sindresorhus/p-each-series) - Iterate over promises serially
  25. - [p-series](https://github.com/sindresorhus/p-series) - Run promise-returning & async functions in series
  26. - [p-waterfall](https://github.com/sindresorhus/p-waterfall) - Run promise-returning & async functions in series, each passing its result to the next
  27. - [More…](https://github.com/sindresorhus/promise-fun)
  28. ## License
  29. MIT © [Sindre Sorhus](https://sindresorhus.com)