{"id":16085842,"url":"https://github.com/zapolnoch/choose","last_synced_at":"2025-10-09T17:35:41.662Z","repository":{"id":201108022,"uuid":"706824321","full_name":"zapolnoch/choose","owner":"zapolnoch","description":null,"archived":false,"fork":false,"pushed_at":"2023-10-19T02:44:32.000Z","size":4,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-21T14:23:21.683Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/choose-matching","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/zapolnoch.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-10-18T17:28:51.000Z","updated_at":"2023-10-19T02:43:06.000Z","dependencies_parsed_at":null,"dependency_job_id":"faa54742-a2c4-4801-a407-adeb01208223","html_url":"https://github.com/zapolnoch/choose","commit_stats":{"total_commits":5,"total_committers":1,"mean_commits":5.0,"dds":0.0,"last_synced_commit":"5332daacace8014cfa963d181e0817be07ed776d"},"previous_names":["zapolnoch/choose"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/zapolnoch/choose","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zapolnoch%2Fchoose","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zapolnoch%2Fchoose/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zapolnoch%2Fchoose/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zapolnoch%2Fchoose/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zapolnoch","download_url":"https://codeload.github.com/zapolnoch/choose/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zapolnoch%2Fchoose/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279001871,"owners_count":26083197,"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-10-09T02:00:07.460Z","response_time":59,"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-09T13:09:32.770Z","updated_at":"2025-10-09T17:35:41.635Z","avatar_url":"https://github.com/zapolnoch.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"First element matching a boolean condition:\n\n```sh\nnpm i choose-matching\n```\n\n```ts\nconst Component = () =\u003e (\n  \u003csection\u003e\n    \u003cheader\u003e\u003c/header\u003e\n    \u003cnav\u003e\n      {choose(\n        [test === \"blue\", \u003cBlueButton /\u003e],\n        [test === \"green\", \u003cGreenButton /\u003e],\n        [true, \u003cButton /\u003e],\n      )}\n    \u003c/nav\u003e\n  \u003c/section\u003e\n)\n```\n\n## Why?\n\nBecause `if` statement is a statement, but here we expect an expression.\n\n## Alternatives\n\n### Self-invoking function\n\n```jsx\n\u003cdiv\u003e\n  {(() =\u003e {\n    switch (test) {\n      case \"blue\":\n        return \u003cBlueButton /\u003e\n      case \"green\":\n        return \u003cGreenButton /\u003e\n      default:\n        return \u003cButton /\u003e\n    }\n  })()}\n\u003c/div\u003e\n```\n\n### Pattern matching\n\nBased on [TC39 proposal](https://github.com/tc39/proposal-pattern-matching) or [ts-pattern](https://github.com/gvergnaud/ts-pattern):\n\n```js\nmatch (test) {\n  when (\"blue\"): \u003cBlueButton /\u003e\n  when (\"green\"): \u003cGreenButton /\u003e\n  default: \u003cButton /\u003e\n}\n```\n\n### Modern way\n\nUse languages in which `if` and `switch` are expressions, e.g. [Civet](https://github.com/DanielXMoore/Civet).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzapolnoch%2Fchoose","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzapolnoch%2Fchoose","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzapolnoch%2Fchoose/lists"}