1.1.2 โข Published 5 months ago
take-n-pipe v1.1.2
take 'n pipe
Simple tool to seamlessly chain code execution.
Why take 'n pipe
?
- Easy way to process data in a linear and readable manner.
- You are not polluting current scope with unnecessary, single use variables.
- Catch errors predictably, at any point in a chain, instead of nesting multiple try-catch clauses.
- You can start processing your data synchronously and proceed to the asynchronous context at any point.
Features
- ๐ Ridiculously simple.
- โ๏ธ Sync & async context.
- ๐ฆ Distributions in ESM and CommonJS standards.
- ๐ Full TypeScript support.
- ๐ Bateries included - no dependencies.
- ๐งช Well tested with Jest.
Installation
# With NPM
npm install take-n-pipe
# With Yarn
yarn add take-n-pipe
The way you go
Sync pipes
- Take any input data.
take(data)
- Transform data with the
pipe(...)
method as many times as you want.
.pipe((data: object) => {...})
- Optionally Catch errors with
catch(...)
method at any time.
.catch((error: unknown) => {...})
- Obtain results.
.get()
Async pipes
- Take any input data.
takeAsync(promise)
- Transform data with the
pipeAsync(...)
method as many times as you want.
.pipeAsync(async (data: object) => {...})
- Optionally Catch errors with
catchAsync(...)
method at any time.
.catchAsync((error: unknown) => {...})
- Obtain results as a Promise.
.toPromise()
Mixed pipes
- Start within sync context, take any input data.
take(data)
- Being in sync context transform data with the
pipe(...)
method as many times as you want.
.pipe((data: object) => {...})
- Call the
pipeAsync(...)
method to proceed to async context.
By calling the
pipeAsync(...)
method on a synchronous chain, you turn it into an asynchronous chain from that point on.This is a one-way ticket, there is no way to go back to the synchronous chain anymore.
.pipeAsync(async (data: object) => {...})
- Obtain results as a Promise.
.toPromise()