{"id":17750548,"url":"https://github.com/nuintun/switch-stream","last_synced_at":"2025-09-10T00:48:02.246Z","repository":{"id":57132368,"uuid":"44357987","full_name":"nuintun/switch-stream","owner":"nuintun","description":"A stream condition for switch/case","archived":false,"fork":false,"pushed_at":"2019-02-27T03:16:05.000Z","size":61,"stargazers_count":1,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-17T04:37:57.889Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/nuintun.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-10-16T02:37:02.000Z","updated_at":"2020-05-19T03:21:38.000Z","dependencies_parsed_at":"2022-09-02T11:10:25.107Z","dependency_job_id":null,"html_url":"https://github.com/nuintun/switch-stream","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/nuintun/switch-stream","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nuintun%2Fswitch-stream","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nuintun%2Fswitch-stream/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nuintun%2Fswitch-stream/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nuintun%2Fswitch-stream/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nuintun","download_url":"https://codeload.github.com/nuintun/switch-stream/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nuintun%2Fswitch-stream/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271574431,"owners_count":24783319,"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","status":"online","status_checked_at":"2025-08-22T02:00:08.480Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-26T12:22:33.052Z","updated_at":"2025-08-22T02:09:57.101Z","avatar_url":"https://github.com/nuintun.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# switch-stream\n\n\u003e A stream condition for switch/case\n\u003e\n\u003e [![NPM Version][npm-image]][npm-url]\n\u003e [![Download Status][download-image]][npm-url]\n\u003e [![Dependencies][david-image]][david-url]\n\n### Usage\n\n![switch.png](https://raw.githubusercontent.com/nuintun/switch-stream/master/images/switch.png)\n\n```js\nconst switchStream = require('switch-stream');\n\nprocess.in\n  .pipe(\n    switchStream(\n      buf =\u003e {\n        if (buf \u003e 0) {\n          return 'case1';\n        } else if (buf \u003c 0) {\n          return 'case2';\n        }\n      },\n      {\n        case1: streamA,\n        case2: streamB\n      }\n    )\n  )\n  .pipe(process.stdout);\n```\n\nIf buf great than 0, then pipe to streamA. If buf less than 0, then pipe to streamB. Otherwise buf equal to 0, pipe to output directly.\n\n### API\n\n#### switchStream(switch, cases, options)\n\n* switch\n\n  Switch condition determine which case will be choose.\n  Switch can be any type, if switch is function, it will be called.\n\n* cases\n\n  Choose which stream will be piped to by key switch return.\n\n* options\n  The stream options settings.\n\n### Reference\n\nModify from popomore's [stream-switch](https://github.com/popomore/stream-switch), but use stream3.\n\n[npm-image]: https://img.shields.io/npm/v/@nuintun/switch-stream.svg?style=flat-square\n[npm-url]: https://www.npmjs.org/package/@nuintun/switch-stream\n[download-image]: https://img.shields.io/npm/dm/@nuintun/switch-stream.svg?style=flat-square\n[david-image]: http://img.shields.io/david/nuintun/switch-stream.svg?style=flat-square\n[david-url]: https://david-dm.org/nuintun/switch-stream\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnuintun%2Fswitch-stream","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnuintun%2Fswitch-stream","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnuintun%2Fswitch-stream/lists"}