Built and signed on GitHub ActionsBuilt and signed on GitHub Actions
Performs consecutive operations on a value in TypeScript
pipe
Performs consecutive operations on a value in TypeScript. An alternative library
of the proposal of Pipe Operator (|>) for JavaScript. It supports type
inference and type checking of the operator functions.
When the number of operator functions applied to pipe get more than twenty,
the result of type inference of each operator function become unknown and
users need to annotate the type explicitly.
Usage
Pipe a value through a series of operator functions.
import { pipe } from "@core/pipe"; const result = pipe( 1, (v) => v + 1, // inferred as (v: number) => number (v) => v * 2, // inferred as (v: number) => number (v) => v.toString(), // inferred as (v: number) => string ); console.log(result); // "4"
Or use async module to pipe a value through a series of asynchronous operator
functions.
import { pipe } from "@core/pipe/async"; const result = await pipe( 1, (v) => Promise.resolve(v + 1), // inferred as (v: number) => number | Promise<number> (v) => Promise.resolve(v * 2), // inferred as (v: number) => number | Promise<number> (v) => Promise.resolve(v.toString()), // inferred as (v: number) => string | Promise<string> ); console.log(result); // "4"
License
The code follows MIT license written in LICENSE. Contributors need to agree that any modifications sent in this repository follow the license.
Add Package
deno add jsr:@core/pipe
Import symbol
import * as pipe from "@core/pipe";
Import directly with a jsr specifier
import * as pipe from "jsr:@core/pipe";
Add Package
pnpm i jsr:@core/pipe
pnpm dlx jsr add @core/pipe
Import symbol
import * as pipe from "@core/pipe";
Add Package
yarn add jsr:@core/pipe
yarn dlx jsr add @core/pipe
Import symbol
import * as pipe from "@core/pipe";
Add Package
vlt install jsr:@core/pipe
Import symbol
import * as pipe from "@core/pipe";
Add Package
npx jsr add @core/pipe
Import symbol
import * as pipe from "@core/pipe";