@philiprehberger/pipe 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +62 -0
- package/dist/index.cjs +32 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +31 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/package.json +57 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 philiprehberger
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# @philiprehberger/pipe
|
|
2
|
+
|
|
3
|
+
[](https://github.com/philiprehberger/ts-pipe/actions/workflows/ci.yml)
|
|
4
|
+
[](https://www.npmjs.com/package/@philiprehberger/pipe)
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
|
|
7
|
+
Typed functional pipe and compose for TypeScript
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @philiprehberger/pipe
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { pipe, pipeline, pipeAsync } from '@philiprehberger/pipe';
|
|
19
|
+
|
|
20
|
+
const result = pipe(" Hello ", s => s.trim(), s => s.split(" "));
|
|
21
|
+
// string[] — fully inferred
|
|
22
|
+
|
|
23
|
+
const transform = pipeline(s => s.trim(), s => s.toLowerCase());
|
|
24
|
+
transform(" HELLO "); // "hello"
|
|
25
|
+
|
|
26
|
+
const data = await pipeAsync(userId, fetchUser, extractProfile, validate);
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Compose (right-to-left)
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import { compose } from '@philiprehberger/pipe';
|
|
33
|
+
|
|
34
|
+
const format = compose(
|
|
35
|
+
(s: string) => `[${s}]`,
|
|
36
|
+
(s: string) => s.toUpperCase(),
|
|
37
|
+
(s: string) => s.trim(),
|
|
38
|
+
);
|
|
39
|
+
format(" hello "); // "[HELLO]"
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## API
|
|
43
|
+
|
|
44
|
+
| Function | Description |
|
|
45
|
+
|----------|-------------|
|
|
46
|
+
| `pipe(value, ...fns)` | Data-first pipeline, returns final result |
|
|
47
|
+
| `compose(...fns)` | Right-to-left function composition |
|
|
48
|
+
| `pipeline(...fns)` | Left-to-right composition, returns reusable function |
|
|
49
|
+
| `pipeAsync(value, ...fns)` | Async-aware pipeline with await between steps |
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
## Development
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
npm install
|
|
56
|
+
npm run build
|
|
57
|
+
npm test
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## License
|
|
61
|
+
|
|
62
|
+
MIT
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/pipe.ts
|
|
4
|
+
function pipe(value, ...fns) {
|
|
5
|
+
return fns.reduce((acc, fn) => fn(acc), value);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// src/compose.ts
|
|
9
|
+
function compose(...fns) {
|
|
10
|
+
return (arg) => fns.reduceRight((acc, fn) => fn(acc), arg);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// src/pipeline.ts
|
|
14
|
+
function pipeline(...fns) {
|
|
15
|
+
return (arg) => fns.reduce((acc, fn) => fn(acc), arg);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// src/pipe-async.ts
|
|
19
|
+
async function pipeAsync(value, ...fns) {
|
|
20
|
+
let result = value;
|
|
21
|
+
for (const fn of fns) {
|
|
22
|
+
result = await fn(result);
|
|
23
|
+
}
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
exports.compose = compose;
|
|
28
|
+
exports.pipe = pipe;
|
|
29
|
+
exports.pipeAsync = pipeAsync;
|
|
30
|
+
exports.pipeline = pipeline;
|
|
31
|
+
//# sourceMappingURL=index.cjs.map
|
|
32
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/pipe.ts","../src/compose.ts","../src/pipeline.ts","../src/pipe-async.ts"],"names":[],"mappings":";;;AAUO,SAAS,IAAA,CAAK,UAAmB,GAAA,EAA6C;AACnF,EAAA,OAAO,GAAA,CAAI,OAAO,CAAC,GAAA,EAAK,OAAO,EAAA,CAAG,GAAG,GAAG,KAAK,CAAA;AAC/C;;;ACPO,SAAS,WAAW,GAAA,EAA+D;AACxF,EAAA,OAAO,CAAC,GAAA,KAAiB,GAAA,CAAI,WAAA,CAAY,CAAC,KAAK,EAAA,KAAO,EAAA,CAAG,GAAG,CAAA,EAAG,GAAG,CAAA;AACpE;;;ACFO,SAAS,YAAY,GAAA,EAA+D;AACzF,EAAA,OAAO,CAAC,GAAA,KAAiB,GAAA,CAAI,MAAA,CAAO,CAAC,KAAK,EAAA,KAAO,EAAA,CAAG,GAAG,CAAA,EAAG,GAAG,CAAA;AAC/D;;;ACDA,eAAsB,SAAA,CAAU,UAAmB,GAAA,EAAyE;AAC1H,EAAA,IAAI,MAAA,GAAS,KAAA;AACb,EAAA,KAAA,MAAW,MAAM,GAAA,EAAK;AACpB,IAAA,MAAA,GAAS,MAAM,GAAG,MAAM,CAAA;AAAA,EAC1B;AACA,EAAA,OAAO,MAAA;AACT","file":"index.cjs","sourcesContent":["export function pipe<A>(value: A): A;\nexport function pipe<A, B>(value: A, fn1: (a: A) => B): B;\nexport function pipe<A, B, C>(value: A, fn1: (a: A) => B, fn2: (b: B) => C): C;\nexport function pipe<A, B, C, D>(value: A, fn1: (a: A) => B, fn2: (b: B) => C, fn3: (c: C) => D): D;\nexport function pipe<A, B, C, D, E>(value: A, fn1: (a: A) => B, fn2: (b: B) => C, fn3: (c: C) => D, fn4: (d: D) => E): E;\nexport function pipe<A, B, C, D, E, F>(value: A, fn1: (a: A) => B, fn2: (b: B) => C, fn3: (c: C) => D, fn4: (d: D) => E, fn5: (e: E) => F): F;\nexport function pipe<A, B, C, D, E, F, G>(value: A, fn1: (a: A) => B, fn2: (b: B) => C, fn3: (c: C) => D, fn4: (d: D) => E, fn5: (e: E) => F, fn6: (f: F) => G): G;\nexport function pipe<A, B, C, D, E, F, G, H>(value: A, fn1: (a: A) => B, fn2: (b: B) => C, fn3: (c: C) => D, fn4: (d: D) => E, fn5: (e: E) => F, fn6: (f: F) => G, fn7: (g: G) => H): H;\nexport function pipe<A, B, C, D, E, F, G, H, I>(value: A, fn1: (a: A) => B, fn2: (b: B) => C, fn3: (c: C) => D, fn4: (d: D) => E, fn5: (e: E) => F, fn6: (f: F) => G, fn7: (g: G) => H, fn8: (h: H) => I): I;\nexport function pipe<A, B, C, D, E, F, G, H, I, J>(value: A, fn1: (a: A) => B, fn2: (b: B) => C, fn3: (c: C) => D, fn4: (d: D) => E, fn5: (e: E) => F, fn6: (f: F) => G, fn7: (g: G) => H, fn8: (h: H) => I, fn9: (i: I) => J): J;\nexport function pipe(value: unknown, ...fns: ((arg: unknown) => unknown)[]): unknown {\n return fns.reduce((acc, fn) => fn(acc), value);\n}\n","export function compose<A, B>(fn1: (a: A) => B): (a: A) => B;\nexport function compose<A, B, C>(fn2: (b: B) => C, fn1: (a: A) => B): (a: A) => C;\nexport function compose<A, B, C, D>(fn3: (c: C) => D, fn2: (b: B) => C, fn1: (a: A) => B): (a: A) => D;\nexport function compose<A, B, C, D, E>(fn4: (d: D) => E, fn3: (c: C) => D, fn2: (b: B) => C, fn1: (a: A) => B): (a: A) => E;\nexport function compose<A, B, C, D, E, F>(fn5: (e: E) => F, fn4: (d: D) => E, fn3: (c: C) => D, fn2: (b: B) => C, fn1: (a: A) => B): (a: A) => F;\nexport function compose(...fns: ((arg: unknown) => unknown)[]): (arg: unknown) => unknown {\n return (arg: unknown) => fns.reduceRight((acc, fn) => fn(acc), arg);\n}\n","export function pipeline<A, B>(fn1: (a: A) => B): (a: A) => B;\nexport function pipeline<A, B, C>(fn1: (a: A) => B, fn2: (b: B) => C): (a: A) => C;\nexport function pipeline<A, B, C, D>(fn1: (a: A) => B, fn2: (b: B) => C, fn3: (c: C) => D): (a: A) => D;\nexport function pipeline<A, B, C, D, E>(fn1: (a: A) => B, fn2: (b: B) => C, fn3: (c: C) => D, fn4: (d: D) => E): (a: A) => E;\nexport function pipeline<A, B, C, D, E, F>(fn1: (a: A) => B, fn2: (b: B) => C, fn3: (c: C) => D, fn4: (d: D) => E, fn5: (e: E) => F): (a: A) => F;\nexport function pipeline(...fns: ((arg: unknown) => unknown)[]): (arg: unknown) => unknown {\n return (arg: unknown) => fns.reduce((acc, fn) => fn(acc), arg);\n}\n","export function pipeAsync<A>(value: A): Promise<A>;\nexport function pipeAsync<A, B>(value: A, fn1: (a: A) => B | Promise<B>): Promise<B>;\nexport function pipeAsync<A, B, C>(value: A, fn1: (a: A) => B | Promise<B>, fn2: (b: B) => C | Promise<C>): Promise<C>;\nexport function pipeAsync<A, B, C, D>(value: A, fn1: (a: A) => B | Promise<B>, fn2: (b: B) => C | Promise<C>, fn3: (c: C) => D | Promise<D>): Promise<D>;\nexport function pipeAsync<A, B, C, D, E>(value: A, fn1: (a: A) => B | Promise<B>, fn2: (b: B) => C | Promise<C>, fn3: (c: C) => D | Promise<D>, fn4: (d: D) => E | Promise<E>): Promise<E>;\nexport function pipeAsync<A, B, C, D, E, F>(value: A, fn1: (a: A) => B | Promise<B>, fn2: (b: B) => C | Promise<C>, fn3: (c: C) => D | Promise<D>, fn4: (d: D) => E | Promise<E>, fn5: (e: E) => F | Promise<F>): Promise<F>;\nexport async function pipeAsync(value: unknown, ...fns: ((arg: unknown) => unknown | Promise<unknown>)[]): Promise<unknown> {\n let result = value;\n for (const fn of fns) {\n result = await fn(result);\n }\n return result;\n}\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
declare function pipe<A>(value: A): A;
|
|
2
|
+
declare function pipe<A, B>(value: A, fn1: (a: A) => B): B;
|
|
3
|
+
declare function pipe<A, B, C>(value: A, fn1: (a: A) => B, fn2: (b: B) => C): C;
|
|
4
|
+
declare function pipe<A, B, C, D>(value: A, fn1: (a: A) => B, fn2: (b: B) => C, fn3: (c: C) => D): D;
|
|
5
|
+
declare function pipe<A, B, C, D, E>(value: A, fn1: (a: A) => B, fn2: (b: B) => C, fn3: (c: C) => D, fn4: (d: D) => E): E;
|
|
6
|
+
declare function pipe<A, B, C, D, E, F>(value: A, fn1: (a: A) => B, fn2: (b: B) => C, fn3: (c: C) => D, fn4: (d: D) => E, fn5: (e: E) => F): F;
|
|
7
|
+
declare function pipe<A, B, C, D, E, F, G>(value: A, fn1: (a: A) => B, fn2: (b: B) => C, fn3: (c: C) => D, fn4: (d: D) => E, fn5: (e: E) => F, fn6: (f: F) => G): G;
|
|
8
|
+
declare function pipe<A, B, C, D, E, F, G, H>(value: A, fn1: (a: A) => B, fn2: (b: B) => C, fn3: (c: C) => D, fn4: (d: D) => E, fn5: (e: E) => F, fn6: (f: F) => G, fn7: (g: G) => H): H;
|
|
9
|
+
declare function pipe<A, B, C, D, E, F, G, H, I>(value: A, fn1: (a: A) => B, fn2: (b: B) => C, fn3: (c: C) => D, fn4: (d: D) => E, fn5: (e: E) => F, fn6: (f: F) => G, fn7: (g: G) => H, fn8: (h: H) => I): I;
|
|
10
|
+
declare function pipe<A, B, C, D, E, F, G, H, I, J>(value: A, fn1: (a: A) => B, fn2: (b: B) => C, fn3: (c: C) => D, fn4: (d: D) => E, fn5: (e: E) => F, fn6: (f: F) => G, fn7: (g: G) => H, fn8: (h: H) => I, fn9: (i: I) => J): J;
|
|
11
|
+
|
|
12
|
+
declare function compose<A, B>(fn1: (a: A) => B): (a: A) => B;
|
|
13
|
+
declare function compose<A, B, C>(fn2: (b: B) => C, fn1: (a: A) => B): (a: A) => C;
|
|
14
|
+
declare function compose<A, B, C, D>(fn3: (c: C) => D, fn2: (b: B) => C, fn1: (a: A) => B): (a: A) => D;
|
|
15
|
+
declare function compose<A, B, C, D, E>(fn4: (d: D) => E, fn3: (c: C) => D, fn2: (b: B) => C, fn1: (a: A) => B): (a: A) => E;
|
|
16
|
+
declare function compose<A, B, C, D, E, F>(fn5: (e: E) => F, fn4: (d: D) => E, fn3: (c: C) => D, fn2: (b: B) => C, fn1: (a: A) => B): (a: A) => F;
|
|
17
|
+
|
|
18
|
+
declare function pipeline<A, B>(fn1: (a: A) => B): (a: A) => B;
|
|
19
|
+
declare function pipeline<A, B, C>(fn1: (a: A) => B, fn2: (b: B) => C): (a: A) => C;
|
|
20
|
+
declare function pipeline<A, B, C, D>(fn1: (a: A) => B, fn2: (b: B) => C, fn3: (c: C) => D): (a: A) => D;
|
|
21
|
+
declare function pipeline<A, B, C, D, E>(fn1: (a: A) => B, fn2: (b: B) => C, fn3: (c: C) => D, fn4: (d: D) => E): (a: A) => E;
|
|
22
|
+
declare function pipeline<A, B, C, D, E, F>(fn1: (a: A) => B, fn2: (b: B) => C, fn3: (c: C) => D, fn4: (d: D) => E, fn5: (e: E) => F): (a: A) => F;
|
|
23
|
+
|
|
24
|
+
declare function pipeAsync<A>(value: A): Promise<A>;
|
|
25
|
+
declare function pipeAsync<A, B>(value: A, fn1: (a: A) => B | Promise<B>): Promise<B>;
|
|
26
|
+
declare function pipeAsync<A, B, C>(value: A, fn1: (a: A) => B | Promise<B>, fn2: (b: B) => C | Promise<C>): Promise<C>;
|
|
27
|
+
declare function pipeAsync<A, B, C, D>(value: A, fn1: (a: A) => B | Promise<B>, fn2: (b: B) => C | Promise<C>, fn3: (c: C) => D | Promise<D>): Promise<D>;
|
|
28
|
+
declare function pipeAsync<A, B, C, D, E>(value: A, fn1: (a: A) => B | Promise<B>, fn2: (b: B) => C | Promise<C>, fn3: (c: C) => D | Promise<D>, fn4: (d: D) => E | Promise<E>): Promise<E>;
|
|
29
|
+
declare function pipeAsync<A, B, C, D, E, F>(value: A, fn1: (a: A) => B | Promise<B>, fn2: (b: B) => C | Promise<C>, fn3: (c: C) => D | Promise<D>, fn4: (d: D) => E | Promise<E>, fn5: (e: E) => F | Promise<F>): Promise<F>;
|
|
30
|
+
|
|
31
|
+
export { compose, pipe, pipeAsync, pipeline };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
declare function pipe<A>(value: A): A;
|
|
2
|
+
declare function pipe<A, B>(value: A, fn1: (a: A) => B): B;
|
|
3
|
+
declare function pipe<A, B, C>(value: A, fn1: (a: A) => B, fn2: (b: B) => C): C;
|
|
4
|
+
declare function pipe<A, B, C, D>(value: A, fn1: (a: A) => B, fn2: (b: B) => C, fn3: (c: C) => D): D;
|
|
5
|
+
declare function pipe<A, B, C, D, E>(value: A, fn1: (a: A) => B, fn2: (b: B) => C, fn3: (c: C) => D, fn4: (d: D) => E): E;
|
|
6
|
+
declare function pipe<A, B, C, D, E, F>(value: A, fn1: (a: A) => B, fn2: (b: B) => C, fn3: (c: C) => D, fn4: (d: D) => E, fn5: (e: E) => F): F;
|
|
7
|
+
declare function pipe<A, B, C, D, E, F, G>(value: A, fn1: (a: A) => B, fn2: (b: B) => C, fn3: (c: C) => D, fn4: (d: D) => E, fn5: (e: E) => F, fn6: (f: F) => G): G;
|
|
8
|
+
declare function pipe<A, B, C, D, E, F, G, H>(value: A, fn1: (a: A) => B, fn2: (b: B) => C, fn3: (c: C) => D, fn4: (d: D) => E, fn5: (e: E) => F, fn6: (f: F) => G, fn7: (g: G) => H): H;
|
|
9
|
+
declare function pipe<A, B, C, D, E, F, G, H, I>(value: A, fn1: (a: A) => B, fn2: (b: B) => C, fn3: (c: C) => D, fn4: (d: D) => E, fn5: (e: E) => F, fn6: (f: F) => G, fn7: (g: G) => H, fn8: (h: H) => I): I;
|
|
10
|
+
declare function pipe<A, B, C, D, E, F, G, H, I, J>(value: A, fn1: (a: A) => B, fn2: (b: B) => C, fn3: (c: C) => D, fn4: (d: D) => E, fn5: (e: E) => F, fn6: (f: F) => G, fn7: (g: G) => H, fn8: (h: H) => I, fn9: (i: I) => J): J;
|
|
11
|
+
|
|
12
|
+
declare function compose<A, B>(fn1: (a: A) => B): (a: A) => B;
|
|
13
|
+
declare function compose<A, B, C>(fn2: (b: B) => C, fn1: (a: A) => B): (a: A) => C;
|
|
14
|
+
declare function compose<A, B, C, D>(fn3: (c: C) => D, fn2: (b: B) => C, fn1: (a: A) => B): (a: A) => D;
|
|
15
|
+
declare function compose<A, B, C, D, E>(fn4: (d: D) => E, fn3: (c: C) => D, fn2: (b: B) => C, fn1: (a: A) => B): (a: A) => E;
|
|
16
|
+
declare function compose<A, B, C, D, E, F>(fn5: (e: E) => F, fn4: (d: D) => E, fn3: (c: C) => D, fn2: (b: B) => C, fn1: (a: A) => B): (a: A) => F;
|
|
17
|
+
|
|
18
|
+
declare function pipeline<A, B>(fn1: (a: A) => B): (a: A) => B;
|
|
19
|
+
declare function pipeline<A, B, C>(fn1: (a: A) => B, fn2: (b: B) => C): (a: A) => C;
|
|
20
|
+
declare function pipeline<A, B, C, D>(fn1: (a: A) => B, fn2: (b: B) => C, fn3: (c: C) => D): (a: A) => D;
|
|
21
|
+
declare function pipeline<A, B, C, D, E>(fn1: (a: A) => B, fn2: (b: B) => C, fn3: (c: C) => D, fn4: (d: D) => E): (a: A) => E;
|
|
22
|
+
declare function pipeline<A, B, C, D, E, F>(fn1: (a: A) => B, fn2: (b: B) => C, fn3: (c: C) => D, fn4: (d: D) => E, fn5: (e: E) => F): (a: A) => F;
|
|
23
|
+
|
|
24
|
+
declare function pipeAsync<A>(value: A): Promise<A>;
|
|
25
|
+
declare function pipeAsync<A, B>(value: A, fn1: (a: A) => B | Promise<B>): Promise<B>;
|
|
26
|
+
declare function pipeAsync<A, B, C>(value: A, fn1: (a: A) => B | Promise<B>, fn2: (b: B) => C | Promise<C>): Promise<C>;
|
|
27
|
+
declare function pipeAsync<A, B, C, D>(value: A, fn1: (a: A) => B | Promise<B>, fn2: (b: B) => C | Promise<C>, fn3: (c: C) => D | Promise<D>): Promise<D>;
|
|
28
|
+
declare function pipeAsync<A, B, C, D, E>(value: A, fn1: (a: A) => B | Promise<B>, fn2: (b: B) => C | Promise<C>, fn3: (c: C) => D | Promise<D>, fn4: (d: D) => E | Promise<E>): Promise<E>;
|
|
29
|
+
declare function pipeAsync<A, B, C, D, E, F>(value: A, fn1: (a: A) => B | Promise<B>, fn2: (b: B) => C | Promise<C>, fn3: (c: C) => D | Promise<D>, fn4: (d: D) => E | Promise<E>, fn5: (e: E) => F | Promise<F>): Promise<F>;
|
|
30
|
+
|
|
31
|
+
export { compose, pipe, pipeAsync, pipeline };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// src/pipe.ts
|
|
2
|
+
function pipe(value, ...fns) {
|
|
3
|
+
return fns.reduce((acc, fn) => fn(acc), value);
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
// src/compose.ts
|
|
7
|
+
function compose(...fns) {
|
|
8
|
+
return (arg) => fns.reduceRight((acc, fn) => fn(acc), arg);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// src/pipeline.ts
|
|
12
|
+
function pipeline(...fns) {
|
|
13
|
+
return (arg) => fns.reduce((acc, fn) => fn(acc), arg);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// src/pipe-async.ts
|
|
17
|
+
async function pipeAsync(value, ...fns) {
|
|
18
|
+
let result = value;
|
|
19
|
+
for (const fn of fns) {
|
|
20
|
+
result = await fn(result);
|
|
21
|
+
}
|
|
22
|
+
return result;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { compose, pipe, pipeAsync, pipeline };
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
27
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/pipe.ts","../src/compose.ts","../src/pipeline.ts","../src/pipe-async.ts"],"names":[],"mappings":";AAUO,SAAS,IAAA,CAAK,UAAmB,GAAA,EAA6C;AACnF,EAAA,OAAO,GAAA,CAAI,OAAO,CAAC,GAAA,EAAK,OAAO,EAAA,CAAG,GAAG,GAAG,KAAK,CAAA;AAC/C;;;ACPO,SAAS,WAAW,GAAA,EAA+D;AACxF,EAAA,OAAO,CAAC,GAAA,KAAiB,GAAA,CAAI,WAAA,CAAY,CAAC,KAAK,EAAA,KAAO,EAAA,CAAG,GAAG,CAAA,EAAG,GAAG,CAAA;AACpE;;;ACFO,SAAS,YAAY,GAAA,EAA+D;AACzF,EAAA,OAAO,CAAC,GAAA,KAAiB,GAAA,CAAI,MAAA,CAAO,CAAC,KAAK,EAAA,KAAO,EAAA,CAAG,GAAG,CAAA,EAAG,GAAG,CAAA;AAC/D;;;ACDA,eAAsB,SAAA,CAAU,UAAmB,GAAA,EAAyE;AAC1H,EAAA,IAAI,MAAA,GAAS,KAAA;AACb,EAAA,KAAA,MAAW,MAAM,GAAA,EAAK;AACpB,IAAA,MAAA,GAAS,MAAM,GAAG,MAAM,CAAA;AAAA,EAC1B;AACA,EAAA,OAAO,MAAA;AACT","file":"index.js","sourcesContent":["export function pipe<A>(value: A): A;\nexport function pipe<A, B>(value: A, fn1: (a: A) => B): B;\nexport function pipe<A, B, C>(value: A, fn1: (a: A) => B, fn2: (b: B) => C): C;\nexport function pipe<A, B, C, D>(value: A, fn1: (a: A) => B, fn2: (b: B) => C, fn3: (c: C) => D): D;\nexport function pipe<A, B, C, D, E>(value: A, fn1: (a: A) => B, fn2: (b: B) => C, fn3: (c: C) => D, fn4: (d: D) => E): E;\nexport function pipe<A, B, C, D, E, F>(value: A, fn1: (a: A) => B, fn2: (b: B) => C, fn3: (c: C) => D, fn4: (d: D) => E, fn5: (e: E) => F): F;\nexport function pipe<A, B, C, D, E, F, G>(value: A, fn1: (a: A) => B, fn2: (b: B) => C, fn3: (c: C) => D, fn4: (d: D) => E, fn5: (e: E) => F, fn6: (f: F) => G): G;\nexport function pipe<A, B, C, D, E, F, G, H>(value: A, fn1: (a: A) => B, fn2: (b: B) => C, fn3: (c: C) => D, fn4: (d: D) => E, fn5: (e: E) => F, fn6: (f: F) => G, fn7: (g: G) => H): H;\nexport function pipe<A, B, C, D, E, F, G, H, I>(value: A, fn1: (a: A) => B, fn2: (b: B) => C, fn3: (c: C) => D, fn4: (d: D) => E, fn5: (e: E) => F, fn6: (f: F) => G, fn7: (g: G) => H, fn8: (h: H) => I): I;\nexport function pipe<A, B, C, D, E, F, G, H, I, J>(value: A, fn1: (a: A) => B, fn2: (b: B) => C, fn3: (c: C) => D, fn4: (d: D) => E, fn5: (e: E) => F, fn6: (f: F) => G, fn7: (g: G) => H, fn8: (h: H) => I, fn9: (i: I) => J): J;\nexport function pipe(value: unknown, ...fns: ((arg: unknown) => unknown)[]): unknown {\n return fns.reduce((acc, fn) => fn(acc), value);\n}\n","export function compose<A, B>(fn1: (a: A) => B): (a: A) => B;\nexport function compose<A, B, C>(fn2: (b: B) => C, fn1: (a: A) => B): (a: A) => C;\nexport function compose<A, B, C, D>(fn3: (c: C) => D, fn2: (b: B) => C, fn1: (a: A) => B): (a: A) => D;\nexport function compose<A, B, C, D, E>(fn4: (d: D) => E, fn3: (c: C) => D, fn2: (b: B) => C, fn1: (a: A) => B): (a: A) => E;\nexport function compose<A, B, C, D, E, F>(fn5: (e: E) => F, fn4: (d: D) => E, fn3: (c: C) => D, fn2: (b: B) => C, fn1: (a: A) => B): (a: A) => F;\nexport function compose(...fns: ((arg: unknown) => unknown)[]): (arg: unknown) => unknown {\n return (arg: unknown) => fns.reduceRight((acc, fn) => fn(acc), arg);\n}\n","export function pipeline<A, B>(fn1: (a: A) => B): (a: A) => B;\nexport function pipeline<A, B, C>(fn1: (a: A) => B, fn2: (b: B) => C): (a: A) => C;\nexport function pipeline<A, B, C, D>(fn1: (a: A) => B, fn2: (b: B) => C, fn3: (c: C) => D): (a: A) => D;\nexport function pipeline<A, B, C, D, E>(fn1: (a: A) => B, fn2: (b: B) => C, fn3: (c: C) => D, fn4: (d: D) => E): (a: A) => E;\nexport function pipeline<A, B, C, D, E, F>(fn1: (a: A) => B, fn2: (b: B) => C, fn3: (c: C) => D, fn4: (d: D) => E, fn5: (e: E) => F): (a: A) => F;\nexport function pipeline(...fns: ((arg: unknown) => unknown)[]): (arg: unknown) => unknown {\n return (arg: unknown) => fns.reduce((acc, fn) => fn(acc), arg);\n}\n","export function pipeAsync<A>(value: A): Promise<A>;\nexport function pipeAsync<A, B>(value: A, fn1: (a: A) => B | Promise<B>): Promise<B>;\nexport function pipeAsync<A, B, C>(value: A, fn1: (a: A) => B | Promise<B>, fn2: (b: B) => C | Promise<C>): Promise<C>;\nexport function pipeAsync<A, B, C, D>(value: A, fn1: (a: A) => B | Promise<B>, fn2: (b: B) => C | Promise<C>, fn3: (c: C) => D | Promise<D>): Promise<D>;\nexport function pipeAsync<A, B, C, D, E>(value: A, fn1: (a: A) => B | Promise<B>, fn2: (b: B) => C | Promise<C>, fn3: (c: C) => D | Promise<D>, fn4: (d: D) => E | Promise<E>): Promise<E>;\nexport function pipeAsync<A, B, C, D, E, F>(value: A, fn1: (a: A) => B | Promise<B>, fn2: (b: B) => C | Promise<C>, fn3: (c: C) => D | Promise<D>, fn4: (d: D) => E | Promise<E>, fn5: (e: E) => F | Promise<F>): Promise<F>;\nexport async function pipeAsync(value: unknown, ...fns: ((arg: unknown) => unknown | Promise<unknown>)[]): Promise<unknown> {\n let result = value;\n for (const fn of fns) {\n result = await fn(result);\n }\n return result;\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@philiprehberger/pipe",
|
|
3
|
+
"version": "0.1.4",
|
|
4
|
+
"description": "Typed functional pipe and compose for TypeScript",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./dist/index.d.cts",
|
|
17
|
+
"default": "./dist/index.cjs"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "tsup",
|
|
26
|
+
"dev": "tsup --watch",
|
|
27
|
+
"typecheck": "tsc --noEmit",
|
|
28
|
+
"prepublishOnly": "npm run build",
|
|
29
|
+
"test": "node --test"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"tsup": "^8.0.0",
|
|
33
|
+
"typescript": "^5.0.0"
|
|
34
|
+
},
|
|
35
|
+
"keywords": [
|
|
36
|
+
"pipe",
|
|
37
|
+
"compose",
|
|
38
|
+
"pipeline",
|
|
39
|
+
"functional",
|
|
40
|
+
"chain",
|
|
41
|
+
"transform"
|
|
42
|
+
],
|
|
43
|
+
"license": "MIT",
|
|
44
|
+
"repository": {
|
|
45
|
+
"type": "git",
|
|
46
|
+
"url": "git+https://github.com/philiprehberger/ts-pipe.git"
|
|
47
|
+
},
|
|
48
|
+
"homepage": "https://github.com/philiprehberger/ts-pipe#readme",
|
|
49
|
+
"bugs": {
|
|
50
|
+
"url": "https://github.com/philiprehberger/ts-pipe/issues"
|
|
51
|
+
},
|
|
52
|
+
"author": "Philip Rehberger",
|
|
53
|
+
"engines": {
|
|
54
|
+
"node": ">=18.0.0"
|
|
55
|
+
},
|
|
56
|
+
"sideEffects": false
|
|
57
|
+
}
|