8889841cindex.js000066600000000527150432031430006214 0ustar00'use strict'; module.exports = (...functions) => { if (functions.length === 0) { throw new Error('Expected at least one argument'); } return async input => { let currentValue = input; for (const fn of functions) { currentValue = await fn(currentValue); // eslint-disable-line no-await-in-loop } return currentValue; }; }; readme.md000066600000003041150432031430006320 0ustar00# p-pipe [![Build Status](https://travis-ci.com/sindresorhus/p-pipe.svg?branch=master)](https://travis-ci.com/sindresorhus/p-pipe) > Compose promise-returning & async functions into a reusable pipeline ## Install ``` $ npm install p-pipe ``` ## Usage ```js const pPipe = require('p-pipe'); const addUnicorn = async string => `${string} Unicorn`; const addRainbow = async string => `${string} Rainbow`; const pipeline = pPipe(addUnicorn, addRainbow); (async () => { console.log(await pipeline('❤️')); //=> '❤️ Unicorn Rainbow' })(); ``` ## API ### pPipe(input…) The `input` functions are applied from left to right. #### input Type: `Function` Expected to return a `Promise` or any value. ## Related - [p-each-series](https://github.com/sindresorhus/p-each-series) - Iterate over promises serially - [p-series](https://github.com/sindresorhus/p-series) - Run promise-returning & async functions in series - [p-waterfall](https://github.com/sindresorhus/p-waterfall) - Run promise-returning & async functions in series, each passing its result to the next - [More…](https://github.com/sindresorhus/promise-fun) ---
Get professional support for this package with a Tidelift subscription
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.
license000066600000002135150432031430006111 0ustar00MIT License Copyright (c) Sindre Sorhus (https://sindresorhus.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. index.d.ts000066600000011137150432031430006447 0ustar00declare namespace pPipe { type UnaryFunction = ( value: ValueType ) => ReturnType | PromiseLike; type Pipeline = ( value?: ValueType ) => Promise; } /** Compose promise-returning & async functions into a reusable pipeline. @param ...input - Iterated over sequentially when returned `function` is called. @returns The `input` functions are applied from left to right. @example ``` import pPipe = require('p-pipe'); const addUnicorn = async string => `${string} Unicorn`; const addRainbow = async string => `${string} Rainbow`; const pipeline = pPipe(addUnicorn, addRainbow); (async () => { console.log(await pipeline('❤️')); //=> '❤️ Unicorn Rainbow' })(); ``` */ declare function pPipe( f1: pPipe.UnaryFunction ): pPipe.Pipeline; declare function pPipe( f1: pPipe.UnaryFunction, f2: pPipe.UnaryFunction ): pPipe.Pipeline; declare function pPipe( f1: pPipe.UnaryFunction, f2: pPipe.UnaryFunction, f3: pPipe.UnaryFunction ): pPipe.Pipeline; declare function pPipe< ValueType, ResultValue1, ResultValue2, ResultValue3, ReturnType >( f1: pPipe.UnaryFunction, f2: pPipe.UnaryFunction, f3: pPipe.UnaryFunction, f4: pPipe.UnaryFunction ): pPipe.Pipeline; declare function pPipe< ValueType, ResultValue1, ResultValue2, ResultValue3, ResultValue4, ReturnType >( f1: pPipe.UnaryFunction, f2: pPipe.UnaryFunction, f3: pPipe.UnaryFunction, f4: pPipe.UnaryFunction, f5: pPipe.UnaryFunction ): pPipe.Pipeline; declare function pPipe< ValueType, ResultValue1, ResultValue2, ResultValue3, ResultValue4, ResultValue5, ReturnType >( f1: pPipe.UnaryFunction, f2: pPipe.UnaryFunction, f3: pPipe.UnaryFunction, f4: pPipe.UnaryFunction, f5: pPipe.UnaryFunction, f6: pPipe.UnaryFunction ): pPipe.Pipeline; declare function pPipe< ValueType, ResultValue1, ResultValue2, ResultValue3, ResultValue4, ResultValue5, ResultValue6, ReturnType >( f1: pPipe.UnaryFunction, f2: pPipe.UnaryFunction, f3: pPipe.UnaryFunction, f4: pPipe.UnaryFunction, f5: pPipe.UnaryFunction, f6: pPipe.UnaryFunction, f7: pPipe.UnaryFunction ): pPipe.Pipeline; declare function pPipe< ValueType, ResultValue1, ResultValue2, ResultValue3, ResultValue4, ResultValue5, ResultValue6, ResultValue7, ReturnType >( f1: pPipe.UnaryFunction, f2: pPipe.UnaryFunction, f3: pPipe.UnaryFunction, f4: pPipe.UnaryFunction, f5: pPipe.UnaryFunction, f6: pPipe.UnaryFunction, f7: pPipe.UnaryFunction, f8: pPipe.UnaryFunction ): pPipe.Pipeline; declare function pPipe< ValueType, ResultValue1, ResultValue2, ResultValue3, ResultValue4, ResultValue5, ResultValue6, ResultValue7, ResultValue8, ReturnType >( f1: pPipe.UnaryFunction, f2: pPipe.UnaryFunction, f3: pPipe.UnaryFunction, f4: pPipe.UnaryFunction, f5: pPipe.UnaryFunction, f6: pPipe.UnaryFunction, f7: pPipe.UnaryFunction, f8: pPipe.UnaryFunction, f9: pPipe.UnaryFunction ): pPipe.Pipeline; // Fallbacks if more than 9 functions are passed as input (not type-safe). declare function pPipe( ...functions: (pPipe.UnaryFunction)[] ): pPipe.Pipeline; export = pPipe; package.json000066600000001425150432031430007033 0ustar00{ "name": "p-pipe", "version": "3.1.0", "description": "Compose promise-returning & async functions into a reusable pipeline", "license": "MIT", "repository": "sindresorhus/p-pipe", "funding": "https://github.com/sponsors/sindresorhus", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", "url": "https://sindresorhus.com" }, "engines": { "node": ">=8" }, "scripts": { "test": "xo && ava && tsd" }, "files": [ "index.js", "index.d.ts" ], "keywords": [ "promise", "pipe", "pipeline", "compose", "composition", "combine", "flow", "serial", "functions", "reusable", "async", "await", "promises", "bluebird" ], "devDependencies": { "ava": "^1.4.1", "sinon": "^7.3.1", "tsd": "^0.7.2", "xo": "^0.24.0" } }