{"id":15304545,"url":"https://github.com/monkeymars/pipa-fns","last_synced_at":"2025-04-09T14:24:27.607Z","repository":{"id":187520902,"uuid":"677069026","full_name":"monkeymars/pipa-fns","owner":"monkeymars","description":"a pipe function is a utility function that allows you to compose a series of functions together, where the output of one function becomes the input of the next function.","archived":false,"fork":false,"pushed_at":"2023-08-15T02:18:12.000Z","size":16740,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-31T23:33:41.906Z","etag":null,"topics":["function-composition","pipe-function"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/monkeymars.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2023-08-10T16:57:42.000Z","updated_at":"2023-08-13T15:14:07.000Z","dependencies_parsed_at":"2024-10-11T09:30:26.164Z","dependency_job_id":"adfb93b2-ef52-4cb5-9370-88e3433ee4a9","html_url":"https://github.com/monkeymars/pipa-fns","commit_stats":{"total_commits":46,"total_committers":2,"mean_commits":23.0,"dds":"0.15217391304347827","last_synced_commit":"1d3b79a06c8e4590ea8320aa411a61a384a03790"},"previous_names":["monkeymars/pipe-fn"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/monkeymars%2Fpipa-fns","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/monkeymars%2Fpipa-fns/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/monkeymars%2Fpipa-fns/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/monkeymars%2Fpipa-fns/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/monkeymars","download_url":"https://codeload.github.com/monkeymars/pipa-fns/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248054395,"owners_count":21039997,"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":["function-composition","pipe-function"],"created_at":"2024-10-01T07:56:54.851Z","updated_at":"2025-04-09T14:24:27.577Z","avatar_url":"https://github.com/monkeymars.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Function: pipa-fns\n[![Build \u0026 Test](https://github.com/monkeymars/pipa-fns/actions/workflows/node-ci.yml/badge.svg)](https://github.com/monkeymars/pipa-fns/actions/workflows/node-ci.yml)\n[![CodeQL](https://github.com/monkeymars/pipa-fns/actions/workflows/codeql.yml/badge.svg)](https://github.com/monkeymars/pipa-fns/actions/workflows/codeql.yml)\n\n\nThe **pipa** - _pipe function_, is a utility function that allows you to compose a series of functions together, where the output of one function becomes the input of the next function. It takes in an array of functions and returns a new function that can be invoked with an argument. The functions can be synchronous or asynchronous, and the output can be a value or a promise.\n\n#### Installation\n\nTo use the pipe function, you need to have Node.js installed on your machine. You can then install it as a dependency in your project using npm or yarn.\n\n##### Using npm:\n\n```bash\nnpm install --save pipa-fns\n```\n\n##### Using yarn:\n\n```bash\nyarn add pipa-fns\n```\n\n## Usage\n\nTo use the pipe function, you need to import it into your code.\n\n```javascript\nimport pipa from 'pipa-fns';\n```\n\n#### **Example 1**: Composing synchronous functions\n\n```javascript\nconst addOne = (num: number) =\u003e num + 1;\nconst multiplyByTwo = (num: number) =\u003e num * 2;\nconst subtractThree = (num: number) =\u003e num - 3;\n\nconst pipedFn = await pipa(addOne, multiplyByTwo, subtractThree);\nconst result = await pipedFn(5);\nconsole.log(result); // Output: 6\n```\n\nIn this example, we define three synchronous functions: add, multiply, and subtract. We then use the pipe function to compose these functions together. The calculate function is the result of the composition, and we can invoke it with an argument (3 in this case) to get the final result.\n\n#### **Example 2**: Composing asynchronous functions\n\n```javascript\nconst fetchData = async (url) =\u003e {\n  const response = await fetch(url);\n  const data = await response.json();\n  return data;\n};\n\nconst processData = (data) =\u003e {\n  // process the data\n  return data;\n};\nconst displayData = (data) =\u003e {\n  // display the data\n  return data;\n};\n\nconst fetchAndProcessData = await pipa(fetchData, processData, displayData);\nconst response = await fetchAndProcessData('https://dummyjson.com/products');\n\nconsole.log(response); // dummy products\n```\n\nIn this example, we have three functions: fetchData, processData, and displayData. The fetchData function is asynchronous and fetches data from a given URL. The processData function processes the fetched data, and the displayData function displays the processed data. We use the pipe function to compose these functions together, creating the fetchAndProcessData function. We can then invoke fetchAndProcessData with a URL to fetch, process, and display the data.\n\nNote: Make sure to handle any errors that may occur during the execution of asynchronous functions.\n\n## Contributing\n\nPull requests are welcome. For major changes, please open an issue first\nto discuss what you would like to change.\n\nPlease make sure to update tests as appropriate.\n\n## License\n\n[MIT](https://choosealicense.com/licenses/mit/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmonkeymars%2Fpipa-fns","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmonkeymars%2Fpipa-fns","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmonkeymars%2Fpipa-fns/lists"}