{"id":21507712,"url":"https://github.com/jsr-core/pipe","last_synced_at":"2025-04-09T15:50:29.436Z","repository":{"id":252574579,"uuid":"840827955","full_name":"jsr-core/pipe","owner":"jsr-core","description":"Performs consecutive operations on a value in TypeScript","archived":false,"fork":false,"pushed_at":"2024-10-27T14:20:39.000Z","size":36,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-23T18:04:42.155Z","etag":null,"topics":["javascript","jsr","pipe","pipeline","typescript"],"latest_commit_sha":null,"homepage":"https://jsr.io/@core/pipe","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jsr-core.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["lambdalisue"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"lfx_crowdfunding":null,"polar":null,"buy_me_a_coffee":null,"custom":null}},"created_at":"2024-08-10T20:06:19.000Z","updated_at":"2024-10-27T14:20:04.000Z","dependencies_parsed_at":"2024-10-27T15:38:23.661Z","dependency_job_id":"e13e4e73-3b6b-49b1-96c4-ae58c649f3b7","html_url":"https://github.com/jsr-core/pipe","commit_stats":null,"previous_names":["jsr-core/pipeline","jsr-core/pipe"],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsr-core%2Fpipe","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsr-core%2Fpipe/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsr-core%2Fpipe/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsr-core%2Fpipe/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jsr-core","download_url":"https://codeload.github.com/jsr-core/pipe/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248063814,"owners_count":21041853,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascript","jsr","pipe","pipeline","typescript"],"created_at":"2024-11-23T20:38:07.735Z","updated_at":"2025-04-09T15:50:29.418Z","avatar_url":"https://github.com/jsr-core.png","language":"TypeScript","funding_links":["https://github.com/sponsors/lambdalisue"],"categories":[],"sub_categories":[],"readme":"# pipe\n\n[![jsr](https://jsr.io/badges/@core/pipe)](https://jsr.io/@core/pipe)\n[![test](https://github.com/jsr-core/pipe/workflows/Test/badge.svg)](https://github.com/jsr-core/pipe/actions?query=workflow%3ATest)\n[![codecov](https://codecov.io/github/jsr-core/pipe/graph/badge.svg?token=pfbLRGU5AM)](https://codecov.io/github/jsr-core/pipe)\n\nPerforms consecutive operations on a value in TypeScript. An alternative library\nof the proposal of [Pipe Operator (`|\u003e`) for JavaScript]. It supports type\ninference and type checking of the operator functions.\n\n\u003e [!NOTE]\n\u003e\n\u003e When the number of operator functions applied to `pipe` get more than twenty,\n\u003e the result of type inference of each operator function become `unknown` and\n\u003e users need to annotate the type explicitly.\n\n[Pipe Operator (`|\u003e`) for JavaScript]: https://github.com/tc39/proposal-pipeline-operator\n\n## Usage\n\nPipe a value through a series of operator functions.\n\n```ts\nimport { pipe } from \"@core/pipe/pipe\";\n\nconst result = pipe(\n  1,\n  (v) =\u003e v + 1, // inferred as (v: number) =\u003e number\n  (v) =\u003e v * 2, // inferred as (v: number) =\u003e number\n  (v) =\u003e v.toString(), // inferred as (v: number) =\u003e string\n);\nconsole.log(result); // \"4\"\n```\n\nOr use `async` module to pipe a value through a series of asynchronous operator\nfunctions.\n\n```ts\nimport { pipe } from \"@core/pipe/async/pipe\";\n\nconst result = await pipe(\n  1,\n  (v) =\u003e Promise.resolve(v + 1), // inferred as (v: number) =\u003e number | Promise\u003cnumber\u003e\n  (v) =\u003e Promise.resolve(v * 2), // inferred as (v: number) =\u003e number | Promise\u003cnumber\u003e\n  (v) =\u003e Promise.resolve(v.toString()), // inferred as (v: number) =\u003e string | Promise\u003cstring\u003e\n);\nconsole.log(result); // \"4\"\n```\n\nIf you want to create a new function that composes multiple operators, use\n`compose` like below.\n\n```ts\nimport { compose } from \"@core/pipe/compose\";\n\nconst operator = compose(\n  (v: number) =\u003e v + 1, // The first operator must be typed explicitly\n  (v) =\u003e v * 2, // inferred as (v: number) =\u003e number\n  (v) =\u003e v.toString(), // inferred as (v: number) =\u003e string\n);\nconsole.log(operator(1)); // \"4\"\n```\n\nOr use `async` module to compose multiple asynchronous operators.\n\n```ts\nimport { compose } from \"@core/pipe/async/compose\";\n\nconst operator = compose(\n  (v: number) =\u003e Promise.resolve(v + 1), // The first operator must be typed explicitly\n  (v) =\u003e Promise.resolve(v * 2), // inferred as (v: number) =\u003e number | Promise\u003cnumber\u003e\n  (v) =\u003e Promise.resolve(v.toString()), // inferred as (v: number) =\u003e string | Promise\u003cstring\u003e\n);\nconsole.log(await operator(1)); // \"4\"\n```\n\n## Difference\n\nThe `pipe` function in the root module is equivalent to function calls without\n`await` like below.\n\n```ts\nimport { pipe } from \"@core/pipe/pipe\";\n\nconst a = (v: unknown) =\u003e v;\nconst b = (v: unknown) =\u003e v;\nconst c = (v: unknown) =\u003e v;\n\n// Equivalent\nconsole.log(pipe(1, a, b, c)); // 1\nconsole.log(c(b(a(1)))); // 1\n```\n\nThe `pipe` function in the `async` module is equivalent to function calls with\n`await` like below.\n\n```ts\nimport { pipe } from \"@core/pipe/async/pipe\";\n\nconst a = (v: unknown) =\u003e Promise.resolve(v);\nconst b = (v: unknown) =\u003e Promise.resolve(v);\nconst c = (v: unknown) =\u003e Promise.resolve(v);\n\n// Equivalent\nconsole.log(await pipe(1, a, b, c)); // 1\nconsole.log(await c(await b(await a(1)))); // 1\n```\n\n## License\n\nThe code follows MIT license written in [LICENSE](./LICENSE). Contributors need\nto agree that any modifications sent in this repository follow the license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjsr-core%2Fpipe","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjsr-core%2Fpipe","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjsr-core%2Fpipe/lists"}