p-pipe

  • Version 4.0.0
  • Published
  • 8.13 kB
  • No dependencies
  • MIT license

Install

npm i p-pipe
yarn add p-pipe
pnpm add p-pipe

Overview

Compose promise-returning & async functions into a reusable pipeline

Index

Functions

Type Aliases

Functions

function pPipe

pPipe: {
<ValueType, ReturnType>(f1: UnaryFunction<ValueType, ReturnType>): Pipeline<
ValueType,
ReturnType
>;
<ValueType, ResultValue1, ReturnType>(
f1: UnaryFunction<ValueType, ResultValue1>,
f2: UnaryFunction<ResultValue1, ReturnType>
): Pipeline<ValueType, ReturnType>;
<ValueType, ResultValue1, ResultValue2, ReturnType>(
f1: UnaryFunction<ValueType, ResultValue1>,
f2: UnaryFunction<ResultValue1, ResultValue2>,
f3: UnaryFunction<ResultValue2, ReturnType>
): Pipeline<ValueType, ReturnType>;
<ValueType, ResultValue1, ResultValue2, ResultValue3, ReturnType>(
f1: UnaryFunction<ValueType, ResultValue1>,
f2: UnaryFunction<ResultValue1, ResultValue2>,
f3: UnaryFunction<ResultValue2, ResultValue3>,
f4: UnaryFunction<ResultValue3, ReturnType>
): Pipeline<ValueType, ReturnType>;
<ValueType, ResultValue1, ResultValue2, ResultValue3, ResultValue4, ReturnType>(
f1: UnaryFunction<ValueType, ResultValue1>,
f2: UnaryFunction<ResultValue1, ResultValue2>,
f3: UnaryFunction<ResultValue2, ResultValue3>,
f4: UnaryFunction<ResultValue3, ResultValue4>,
f5: UnaryFunction<ResultValue4, ReturnType>
): Pipeline<ValueType, ReturnType>;
<
ValueType,
ResultValue1,
ResultValue2,
ResultValue3,
ResultValue4,
ResultValue5,
ReturnType
>(
f1: UnaryFunction<ValueType, ResultValue1>,
f2: UnaryFunction<ResultValue1, ResultValue2>,
f3: UnaryFunction<ResultValue2, ResultValue3>,
f4: UnaryFunction<ResultValue3, ResultValue4>,
f5: UnaryFunction<ResultValue4, ResultValue5>,
f6: UnaryFunction<ResultValue5, ReturnType>
): Pipeline<ValueType, ReturnType>;
<
ValueType,
ResultValue1,
ResultValue2,
ResultValue3,
ResultValue4,
ResultValue5,
ResultValue6,
ReturnType
>(
f1: UnaryFunction<ValueType, ResultValue1>,
f2: UnaryFunction<ResultValue1, ResultValue2>,
f3: UnaryFunction<ResultValue2, ResultValue3>,
f4: UnaryFunction<ResultValue3, ResultValue4>,
f5: UnaryFunction<ResultValue4, ResultValue5>,
f6: UnaryFunction<ResultValue5, ResultValue6>,
f7: UnaryFunction<ResultValue6, ReturnType>
): Pipeline<ValueType, ReturnType>;
<
ValueType,
ResultValue1,
ResultValue2,
ResultValue3,
ResultValue4,
ResultValue5,
ResultValue6,
ResultValue7,
ReturnType
>(
f1: UnaryFunction<ValueType, ResultValue1>,
f2: UnaryFunction<ResultValue1, ResultValue2>,
f3: UnaryFunction<ResultValue2, ResultValue3>,
f4: UnaryFunction<ResultValue3, ResultValue4>,
f5: UnaryFunction<ResultValue4, ResultValue5>,
f6: UnaryFunction<ResultValue5, ResultValue6>,
f7: UnaryFunction<ResultValue6, ResultValue7>,
f8: UnaryFunction<ResultValue7, ReturnType>
): Pipeline<ValueType, ReturnType>;
<
ValueType,
ResultValue1,
ResultValue2,
ResultValue3,
ResultValue4,
ResultValue5,
ResultValue6,
ResultValue7,
ResultValue8,
ReturnType
>(
f1: UnaryFunction<ValueType, ResultValue1>,
f2: UnaryFunction<ResultValue1, ResultValue2>,
f3: UnaryFunction<ResultValue2, ResultValue3>,
f4: UnaryFunction<ResultValue3, ResultValue4>,
f5: UnaryFunction<ResultValue4, ResultValue5>,
f6: UnaryFunction<ResultValue5, ResultValue6>,
f7: UnaryFunction<ResultValue6, ResultValue7>,
f8: UnaryFunction<ResultValue7, ResultValue8>,
f9: UnaryFunction<ResultValue8, ReturnType>
): Pipeline<ValueType, ReturnType>;
(...functions: UnaryFunction<any, unknown>[]): Pipeline<unknown, unknown>;
};
  • Compose promise-returning & async functions into a reusable pipeline.

    Parameter

    ...input - Iterated over sequentially when returned function is called.

    Returns

    The input functions are applied from left to right.

    Example 1

    import pPipe from 'p-pipe';
    const addUnicorn = async string => `${string} Unicorn`;
    const addRainbow = async string => `${string} Rainbow`;
    const pipeline = pPipe(addUnicorn, addRainbow);
    console.log(await pipeline('❤️'));
    //=> '❤️ Unicorn Rainbow'

Type Aliases

type Pipeline

type Pipeline<ValueType, ReturnType> = (value?: ValueType) => Promise<ReturnType>;

    type UnaryFunction

    type UnaryFunction<ValueType, ReturnType> = (
    value: ValueType
    ) => ReturnType | PromiseLike<ReturnType>;

      Package Files (1)

      Dependencies (0)

      No dependencies.

      Dev Dependencies (4)

      Peer Dependencies (0)

      No peer dependencies.

      Badge

      To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

      You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/p-pipe.

      • Markdown
        [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/p-pipe)
      • HTML
        <a href="https://www.jsdocs.io/package/p-pipe"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>