{"id":16639336,"url":"https://github.com/orlowdev/or-pipets","last_synced_at":"2025-04-05T01:14:50.254Z","repository":{"id":40122907,"uuid":"294667229","full_name":"orlowdev/or-pipets","owner":"orlowdev","description":"Typed pipeable interface for imperative sequences in FP.","archived":false,"fork":false,"pushed_at":"2023-01-06T14:24:57.000Z","size":1759,"stargazers_count":1,"open_issues_count":9,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-16T13:37:31.073Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/orlowdev.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":".github/contributing.md","funding":".github/funding.yml","license":"license.md","code_of_conduct":".github/code_of_conduct.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/codeowners","security":".github/security.md","support":null},"funding":{"github":null,"patreon":"orlovedev","open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2020-09-11T10:39:48.000Z","updated_at":"2021-04-13T15:50:04.000Z","dependencies_parsed_at":"2023-02-06T05:15:52.658Z","dependency_job_id":null,"html_url":"https://github.com/orlowdev/or-pipets","commit_stats":null,"previous_names":["orlovedev/or-pipets"],"tags_count":4,"template":false,"template_full_name":"orlowdev/template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orlowdev%2For-pipets","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orlowdev%2For-pipets/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orlowdev%2For-pipets/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orlowdev%2For-pipets/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/orlowdev","download_url":"https://codeload.github.com/orlowdev/or-pipets/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247271527,"owners_count":20911587,"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":[],"created_at":"2024-10-12T07:05:45.635Z","updated_at":"2025-04-05T01:14:50.241Z","avatar_url":"https://github.com/orlowdev.png","language":"TypeScript","funding_links":["https://patreon.com/orlovedev"],"categories":[],"sub_categories":[],"readme":"# ||pipets\n\n![or-pipets logo](./images/logo.jpeg)\n\n![lint](https://github.com/orlovedev/or-pipets/workflows/lint/badge.svg)\n![ava](https://github.com/orlovedev/or-pipets/workflows/AVA/badge.svg)\n\n[![Maintainability](https://api.codeclimate.com/v1/badges/0a0a718d9df2943866b4/maintainability)](https://codeclimate.com/github/orlovedev/or-pipets/maintainability)\n[![codecov](https://codecov.io/gh/orlovedev/or-pipets/branch/main/graph/badge.svg)](https://codecov.io/gh/orlovedev/or-pipets)\n\n[![bundlephobia: minzip](https://img.shields.io/bundlephobia/minzip/or-pipets)](https://bundlephobia.com/result?p=or-pipets)\n\n[![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/xojs/xo)\n[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)\n[![versioning: or-release](https://img.shields.io/badge/versioning-%7C%7Cr-E76D83.svg)](https://github.com/orlovedev/or-release)\n\nTyped pipeable interface for imperative sequences in FP.\n\nThis package provides two constructs - `Pipe` and `AsyncPipe`. `AsyncPipe` provides the same methods as `Pipe` but its methods (except for `.concat`) end with **P**, e.g. `.pipeP` instead of `.pipe`. This is done to distinguish in the code when a `Pipe` transforms to an `AsyncPipe`.\n\n- `Pipe.of(func)` and `AsyncPipe.of(asyncFunc)` wrap a function into pipe or async pipe accordingly\n- `Pipe.from(...funcs)` and `AsyncPipe.from(...asyncFuncs)` wrap multiple functions\n- `Pipe.empty()` and `AsyncPipe.empty()` create empty pipes\n\n- `pipe.pipe(func)` extends the sequence with a function\n- `.pipeTap(func)` extends the sequence with a function. The function will be executed but the pipe will ignore its return value and preserve previous context instead\n- `.pipeExtend(func)` extends the sequence with a function. The function will be executed and the return value will be merged with the previous context. _Should only be used with objects_\n- `a.concat(b)` creates a new pipe that contains sequences of both pipes. If either `a` or `b` is an `AsyncPipe`, an `AsyncPipe` is returned, no matter what another pipe was.\n\n## Installation\n\n```sh\nyarn add or-pipets\n```\n\nor\n\n```sh\nnpm i -S or-pipets\n```\n\n## Examples\n\n### Bored\n\nSuggests you ideas in case you get bored.\n\n```typescript\nimport { EventEmitter } from 'events'\n// You also need node-fetch for this to work\nimport fetch, { Response } from 'node-fetch'\nimport { AsyncPipe } from 'or-pipets'\n\nconst emitter = new EventEmitter()\n\nconst getJson = async (response: Response) =\u003e response.json()\n\nconst boredPipe = AsyncPipe.of(() =\u003e 'https://www.boredapi.com/api/activity')\n\t.pipeTapP(() =\u003e console.log('Searching for activities... 🤔'))\n\t.pipeP(fetch)\n\t.pipeP(getJson)\n\t.pipeP((json: { activity: string }) =\u003e json.activity)\n\t.pipeTapP(() =\u003e console.log('Found one 🎉'))\n\t.pipeP((activity) =\u003e `  💡 ${activity}`)\n\t.pipeP(console.log)\n\nemitter.on('bored', boredPipe.processP)\n\nsetTimeout(() =\u003e emitter.emit('bored'), 300)\n```\n\n### Add 10\n\nAdds 10 to the number you provide as a CLI argument.\n\n```typescript\nimport { Pipe } from 'or-pipets'\n\n// Start with removing the first two strings in the argv\nPipe.of((argv: string[]) =\u003e argv.slice(2))\n\t// .pipeTap executes provided function but the return value is\n\t// ignored - the argument is passed to the next function instead\n\t// Log the context to console\n\t.pipeTap((x) =\u003e console.log('\u003e\u003e\u003e', x))\n\t// Get the first item in the array and parse a number, 0 if NaN\n\t.pipe(([numberString]) =\u003e Number.parseInt(numberString, 10) || 0)\n\t// Log the context to console\n\t.pipeTap((x) =\u003e console.log('\u003e\u003e\u003e', x))\n\t// Add 10\n\t.pipe((number) =\u003e number + 10)\n\t// Log the result to console\n\t.pipe((result) =\u003e console.log(`🧮 ${result}`))\n\t// Pass argv to the context of the Pipe\n\t.process(process.argv)\n```\n\n### Welcome to localhost\n\nWelcomes you to localhost:3000.\n\n```typescript\nimport * as express from 'express'\nimport { Pipe } from 'or-pipets'\n\nconst app = express()\n\ninterface ICtx {\n\trequest: express.Request\n\tresponse: express.Response\n}\n\n// Here we start with Pipe.empty() because our first function returns\n// void. If we pass it to Pipe.of, it will pass nothing to the first\n// pipeExtend and the code will fail. This is because pipeExtend\n// manages saving previous context, not the Pipe itself.\nconst getSlashPipeline = Pipe.empty\u003cICtx\u003e()\n\t.pipeExtend(({ response }) =\u003e response.setHeader('X-Powered-By', 'Express with Pipe'))\n\t// Puts the value of the Host header to the context\n\t.pipeExtend(({ request }) =\u003e ({ host: request.header('host') ?? '🤔' }))\n\t// Creates the response string with the host\n\t.pipeExtend(({ host }) =\u003e ({ responseBody: `Welcome to ${host}!` }))\n\t// Wraps the response string into h1\n\t.pipeExtend(({ responseBody }) =\u003e ({ responseBody: `\u003ch1\u003e${responseBody}\u003c/h1\u003e` }))\n\t// Sends the response\n\t.pipe(({ response, responseBody }) =\u003e response.send(responseBody))\n\napp.get('/', (request, response) =\u003e getSlashPipeline.process({ request, response }))\n\napp.listen(3000, () =\u003e {\n\tconsole.log(`Example app listening on port 3000`)\n})\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Forlowdev%2For-pipets","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Forlowdev%2For-pipets","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Forlowdev%2For-pipets/lists"}