File tree Expand file tree Collapse file tree 3 files changed +37
-21
lines changed Expand file tree Collapse file tree 3 files changed +37
-21
lines changed Original file line number Diff line number Diff line change 1- # pipeline
1+ # pipe
22
3- [ ![ jsr] ( https://jsr.io/badges/@core/pipeline )] ( https://jsr.io/@core/pipeline )
4- [ ![ test] ( https://github.com/jsr-core/pipeline /workflows/Test/badge.svg )] ( https://github.com/jsr-core/pipeline /actions?query=workflow%3ATest )
5- [ ![ codecov] ( https://codecov.io/github/jsr-core/pipeline /graph/badge.svg?token=pfbLRGU5AM )] ( https://codecov.io/github/jsr-core/pipeline )
3+ [ ![ jsr] ( https://jsr.io/badges/@core/pipe )] ( https://jsr.io/@core/pipe )
4+ [ ![ test] ( https://github.com/jsr-core/pipe /workflows/Test/badge.svg )] ( https://github.com/jsr-core/pipe /actions?query=workflow%3ATest )
5+ [ ![ codecov] ( https://codecov.io/github/jsr-core/pipe /graph/badge.svg?token=pfbLRGU5AM )] ( https://codecov.io/github/jsr-core/pipe )
66
7- ## Usage
7+ Performs consecutive operations on a value in TypeScript. An alternative library
8+ of the proposal of [ Pipe Operator (` |> ` ) for JavaScript] . It supports type
9+ inference and type checking of the operator functions.
10+
11+ > [ !NOTE]
12+ >
13+ > When the number of operator functions applied to ` pipe ` get more than twenty,
14+ > the result of type inference of each operator function become ` unknown ` and
15+ > users need to annotate the type explicitly.
816
9- ### pipe
17+ [ Pipe Operator (`|>`) for JavaScript ] : https://github.com/tc39/proposal-pipeline-operator
18+
19+ ## Usage
1020
11- Pipe a value through a series of operatorfunctions .
21+ Pipe a value through a series of operator functions .
1222
1323``` ts
14- import { pipe } from " @core/pipeline " ;
24+ import { pipe } from " @core/pipe " ;
1525
1626const result = pipe (
1727 1 ,
18- (v ) => v + 1 ,
19- (v ) => v * 2 ,
20- (v ) => v .toString (),
28+ (v ) => v + 1 , // inferred as (v: number) => number
29+ (v ) => v * 2 , // inferred as (v: number) => number
30+ (v ) => v .toString (), // inferred as (v: number) => string
2131);
2232console .log (result ); // "4"
2333```
Original file line number Diff line number Diff line change 11{
2- "name" : " @core/pipeline " ,
2+ "name" : " @core/pipe " ,
33 "version" : " 0.0.0" ,
44 "exports" : {
55 "." : " ./mod.ts"
2020 ]
2121 },
2222 "imports" : {
23- "@core/pipeline " : " ./mod.ts" ,
23+ "@core/pipe " : " ./mod.ts" ,
2424 "@std/assert" : " jsr:@std/assert@^1.0.2" ,
2525 "@std/jsonc" : " jsr:@std/jsonc@^1.0.0" ,
2626 "@std/path" : " jsr:@std/path@^1.0.2" ,
Original file line number Diff line number Diff line change @@ -11,21 +11,27 @@ export type LastOperatorReturn<T extends Operator<unknown, unknown>[]> =
1111 : never ;
1212
1313/**
14- * Pipe a value through a series of operatorfunctions.
14+ * Pipes a value through a series of operator functions.
15+ * Supports type inference for both the operator functions and the return value of the final operator.
1516 *
16- * @param value - The value to pipe through the operators.
17- * @param operators - The operators to apply to the value.
18- * @returns The value after it has been piped through all the operators.
17+ * > [!NOTE]
18+ * >
19+ * > If the number of operators exceeds 20, the operator functions' types will default to
20+ * > `Operator<unknown, unknown>`, requiring explicit type annotations.
21+ *
22+ * @param value - The initial value to be processed through the operators.
23+ * @param operators - A sequence of functions to apply to the value.
24+ * @returns The final value after being processed through all the operators.
1925 *
2026 * @example
2127 * ```ts
22- * import { pipe } from "@core/pipeline ";
28+ * import { pipe } from "@core/pipe ";
2329 *
2430 * const result = pipe(
2531 * 1,
26- * (v) => v + 1,
27- * (v) => v * 2,
28- * (v) => v.toString(),
32+ * (v) => v + 1, // inferred as (v: number) => number
33+ * (v) => v * 2, // inferred as (v: number) => number
34+ * (v) => v.toString(), // inferred as (v: number) => string
2935 * );
3036 * console.log(result); // "4"
3137 * ```
You can’t perform that action at this time.
0 commit comments