1.1.2 โ€ข Published 5 months ago

take-n-pipe v1.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

take 'n pipe

Simple tool to seamlessly chain code execution.

MIT License

Code sample

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

  1. Take any input data.
take(data)
  1. Transform data with the pipe(...) method as many times as you want.
.pipe((data: object) => {...})
  1. Optionally Catch errors with catch(...) method at any time.
.catch((error: unknown) => {...})
  1. Obtain results.
.get()

Async pipes

  1. Take any input data.
takeAsync(promise)
  1. Transform data with the pipeAsync(...) method as many times as you want.
.pipeAsync(async (data: object) => {...})
  1. Optionally Catch errors with catchAsync(...) method at any time.
.catchAsync((error: unknown) => {...})
  1. Obtain results as a Promise.
.toPromise()

Mixed pipes

  1. Start within sync context, take any input data.
take(data)
  1. Being in sync context transform data with the pipe(...) method as many times as you want.
.pipe((data: object) => {...})
  1. 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) => {...})
  1. Obtain results as a Promise.
.toPromise()

Examples

https://github.com/IdkMan2/take-n-pipe/blob/8a01d6223fa37f061db6074f09c7dd522d13e758/tests/examples/sync-pipes.ts#L14-L43

https://github.com/IdkMan2/take-n-pipe/blob/8a01d6223fa37f061db6074f09c7dd522d13e758/tests/examples/mixed-pipes.ts#L29-L66

1.1.2

5 months ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago