Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/afeiship/pipe
Pipe is a lightweight JavaScript library for function composition and execution.
https://github.com/afeiship/pipe
compose fn pipe
Last synced: 24 days ago
JSON representation
Pipe is a lightweight JavaScript library for function composition and execution.
- Host: GitHub
- URL: https://github.com/afeiship/pipe
- Owner: afeiship
- License: mit
- Created: 2019-08-25T00:58:00.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-07-16T00:47:31.000Z (over 1 year ago)
- Last Synced: 2024-10-05T19:41:12.645Z (about 2 months ago)
- Topics: compose, fn, pipe
- Language: TypeScript
- Homepage:
- Size: 462 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# pipe
> Pipe is a lightweight JavaScript library for function composition and execution.[![version][version-image]][version-url]
[![license][license-image]][license-url]
[![size][size-image]][size-url]
[![download][download-image]][download-url]## installation
```shell
npm install @jswork/pipe
```## methods
- [x] pipe === pipe.sync
- [x] pipe.sync (default)
- [x] pipe.async## usage
```js
import pipe from '@jswork/pipe';// fns
function addOne(n: number): number {
return n + 1;
}function double(n: number): number {
return n * 2;
}function divide(n: number): number {
if (n === 0) {
throw new Error('Divide by zero error.');
}
return 10 / n;
}// use pipe
const calculate = pipe(
addOne,
double,
divide,
addOne
);const result1 = calculate(3);
const result2 = calculate(-1);// has result, without log
console.log('Result1:', result1); // 10 / (3 + 1)*2 + 1
// has result, but with warning log
console.log('Result2:', result2); // 10 / (-1+1)*2 + 1
```## license
Code released under [the MIT license](https://github.com/afeiship/pipe/blob/master/LICENSE.txt).[version-image]: https://img.shields.io/npm/v/@jswork/pipe
[version-url]: https://npmjs.org/package/@jswork/pipe[license-image]: https://img.shields.io/npm/l/@jswork/pipe
[license-url]: https://github.com/afeiship/pipe/blob/master/LICENSE.txt[size-image]: https://img.shields.io/bundlephobia/minzip/@jswork/pipe
[size-url]: https://github.com/afeiship/pipe/blob/master/dist/pipe.min.js[download-image]: https://img.shields.io/npm/dm/@jswork/pipe
[download-url]: https://www.npmjs.com/package/@jswork/pipe