Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mathieuprog/pipe-pipefy
Combine functions calling each function with the output of the last one
https://github.com/mathieuprog/pipe-pipefy
Last synced: about 2 months ago
JSON representation
Combine functions calling each function with the output of the last one
- Host: GitHub
- URL: https://github.com/mathieuprog/pipe-pipefy
- Owner: mathieuprog
- License: apache-2.0
- Created: 2022-03-02T08:19:51.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-03-14T05:49:43.000Z (almost 3 years ago)
- Last Synced: 2024-08-10T11:29:08.381Z (5 months ago)
- Language: JavaScript
- Size: 204 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# `pipe-pipefy`
`pipe-pipefy` allows to combine functions, calling each function with the output of the last one.
## Usage
```javascript
import { pipe } from 'pipe-pipefy';const getName = (person) => person.name;
const uppercase = (string) => string.toUpperCase();const person = { name: 'Mathieu' };
const result =
pipe(
getName,
uppercase
)(person);expect(result).toBe('MATHIEU');
``````javascript
import { pipe, pipefy } from 'pipe-pipefy';const getName = (person) => person.name;
const uppercase = (string) => string.toUpperCase();
const repeat = (string, n) => string.repeat(n);const person = { name: 'Mathieu' };
const result =
pipe(
getName,
uppercase,
pipefy(repeat, 2)
)(person);expect(result).toBe('MATHIEUMATHIEU');
``````javascript
import { pipe, pipefyIf } from 'pipe-pipefy';const getName = (person) => person.name;
const uppercase = (string) => string.toUpperCase();
const repeat = (string, n) => string.repeat(n);const person = { name: 'Mathieu' };
const someCondition = false;const result =
pipe(
getName,
uppercase,
pipefyIf(someCondition, repeat, 2)
)(person);expect(result).toBe('MATHIEU');
``````javascript
import { pipeAsync } from 'pipe-pipefy';const getName = (person) => person.name;
const uppercase = (string) => string.toUpperCase();const uppercaseAfterTimeout = (string) => {
return new Promise(resolve => setTimeout(() => resolve(uppercase(string)), 50));
};const person = { name: 'Mathieu' };
const result =
await pipeAsync(
getName,
uppercaseAfterTimeout
)(person);expect(result).toBe('MATHIEU');
```## Installation
You can get `pipe-pipefy` via [npm](http://npmjs.com).
```bash
$ npm install pipe-pipefy --save
```