Simple pipe function, takes return value of a function and passes it as the first argument to the next function.
- Supports async functions
- Works everywhere (browser, NodeJS)
- No dependencies
Install PipeJS with npm
npm install @dodiameer/pipe-js
Install PipeJS with pnpm
pnpm install @dodiameer/pipe-js
Install PipeJS with yarn
yarn add @dodiameer/pipe-js
import { pipe } from "@dodiameer/pipe-js" // or `import pipe from "@dodiameer/pipe-js"`
const value = await pipe(
getDataFromApi,
serializeData,
// To pass arguments, write an array with the function
// as the first item and the rest of the arguments
[prettyPrint, { tabWidth: 2 }]
)
// Above is equivalent to this
const data = await getDataFromApi()
const serializedData = serializeData(data)
const value = prettyPrint(serializedData, { tabWidth: 2 })
See this CodePen