https://github.com/bluzi/paipu
:rocket: Yet another streaming library for Node (UNDER DEVELOPMENT)
https://github.com/bluzi/paipu
Last synced: 12 months ago
JSON representation
:rocket: Yet another streaming library for Node (UNDER DEVELOPMENT)
- Host: GitHub
- URL: https://github.com/bluzi/paipu
- Owner: bluzi
- License: mit
- Created: 2018-04-06T19:14:45.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-10-01T05:11:23.000Z (almost 8 years ago)
- Last Synced: 2024-11-29T08:15:50.031Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 48.8 KB
- Stars: 6
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## paipu
Piapue is Japanese for Pipe, and it's also a pipes library for Node.
### Install
```
npm i paipu
```
### Usage
You can throw anything into the pipe:
* Functions and Promises will be evaluated and the result will be the context for the next pipe
* Other pipes will extend the current pipe
* Anything else will set the context for the rest of the pipe
To execute a pipe, call `resolve()` at the end of it.
### Examples
Simple pipe:
```js
const paipu = require('paipu');
const result =
await paipu
.pipe('hello')
.pipe(context => context.substr(0, 4))
.resolve();
// Result = 'hell'
```
Pipe with promises:
```js
const paipu = require('paipu');
const result =
await paipu
.pipe('abcdefg')
.pipe(async context => context.substr(0, 3))
.resolve();
// Result = 'abc'
```
Pipe with nested pipes:
```js
const paipu = require('paipu');
const encrypt =
paipu
.pipe(context => context.replace('a', 'b'))
.pipe(context => context.replace('c', 'd'))
const result =
await paipu
.pipe('abcdefg')
.pipe(encrypt)
.resolve();
// Result = 'bbddefg'
```
There are also before/after pipe hooks and aliases:
```js
const paipu = require('paipu');
paipu
.beforePipe((alias, context) => console.log(`executing '${alias}'...`))
.afterPipe((alias, context) => console.log(`'${alias}' has finished!`))
.pipe('throw in a string', 'abcdefg')
.pipe('cut that goddamn string', async context => context.substr(0, 3))
.resolve();
```
And they will effect nested pipes too!
### Contribution
Any type of feedback, pull request or issue is welcome