{"id":16234114,"url":"https://github.com/zackify/match","last_synced_at":"2025-03-16T12:32:22.579Z","repository":{"id":57355849,"uuid":"50076457","full_name":"zackify/match","owner":"zackify","description":"a port of Rust's match in JS","archived":false,"fork":false,"pushed_at":"2017-03-28T18:40:44.000Z","size":12,"stargazers_count":77,"open_issues_count":2,"forks_count":7,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-27T08:54:38.853Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/zackify.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}},"created_at":"2016-01-21T02:33:18.000Z","updated_at":"2023-05-04T03:33:18.000Z","dependencies_parsed_at":"2022-09-05T21:30:24.486Z","dependency_job_id":null,"html_url":"https://github.com/zackify/match","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zackify%2Fmatch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zackify%2Fmatch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zackify%2Fmatch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zackify%2Fmatch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zackify","download_url":"https://codeload.github.com/zackify/match/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243814880,"owners_count":20352037,"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-10T13:15:03.599Z","updated_at":"2025-03-16T12:32:22.271Z","avatar_url":"https://github.com/zackify.png","language":"JavaScript","readme":"[![Build Status](https://circleci.com/gh/zackify/match.svg?style=shield\u0026circle-token=443316526a6b5f0ed82f7b64307c6c5914f79ad5)](https://circleci.com/gh/zackify/match)\n\n## Match\n\nA basic port of [Rust's match](https://doc.rust-lang.org/book/match.html) function.\n\n## Install\n\n```js\nnpm install rust-match --save\n\nimport match from 'rust-match'\n```\n\nYou can get the UMD build from `/umd`, or use it in a script tag from unpkg:\n\n```\n\u003cscript src=\"https://unpkg.com/rust-match/umd/match.min.js\"\u003e\u003c/script\u003e\n```\n\n\n## Examples\n\n#### [Play around on JSFiddle](https://jsfiddle.net/2ct8d7r9/10/)\n\n```js\n\nlet message = 'hello'\nlet response = match(message, [\n  hello =\u003e 'the value is hello',\n  goodbye =\u003e 'hello to you too!',\n  _ =\u003e 'something else'\n])\n\nconsole.log(response) // prints 'the value is hello'\n\n//numbers and spaces are more verbose\nlet number = '26'\nmatch(number, {\n  5: () =\u003e console.log('the value is hi'),\n  'test word': () =\u003e console.log('the value is test word'),\n  _: (value) =\u003e console.log(`you chose ${value}!`)\n})\n\n```\n\nIt is [a LOT slower](http://jsperf.com/match-vs-switch/11) than a switch statement though.\n\n## Exhaustive Checking\n\n```js\nmatch('test', [\n  awesome =\u003e console.log('awesome')\n])\n\n//throws: error: non-exhaustive patterns: `_` not covered, just like rust!\n```\n\n## Usage with Redux\n\nThis also turns out to be a nice alternative to using switch statements in redux!\n\n```js\nexport default (state = Immutable.Map, action) =\u003e {\n  return match(action.type, [\n    authenticate =\u003e state.merge(action),\n    setToken =\u003e state.set('token', 'test'),\n    _ =\u003e state\n  ])\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzackify%2Fmatch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzackify%2Fmatch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzackify%2Fmatch/lists"}