Skip to content

Commit 579f7fb

Browse files
authored
Merge pull request #1 from jsr-core/rename
refactor!: Rename the library to `@core/pipe`
2 parents 538064e + 6b8570a commit 579f7fb

File tree

3 files changed

+37
-21
lines changed

3 files changed

+37
-21
lines changed

README.md

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,33 @@
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

1626
const 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
);
2232
console.log(result); // "4"
2333
```

deno.jsonc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "@core/pipeline",
2+
"name": "@core/pipe",
33
"version": "0.0.0",
44
"exports": {
55
".": "./mod.ts"
@@ -20,7 +20,7 @@
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",

mod.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff 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
* ```

0 commit comments

Comments
 (0)