8889841cindex.js 0000666 00000000527 15043203143 0006214 0 ustar 00 '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.md 0000666 00000003041 15043203143 0006320 0 ustar 00 # p-pipe [](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)
---
license 0000666 00000002135 15043203143 0006111 0 ustar 00 MIT 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.ts 0000666 00000011137 15043203143 0006447 0 ustar 00 declare 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.json 0000666 00000001425 15043203143 0007033 0 ustar 00 {
"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"
}
}