{"id":13431458,"url":"https://github.com/ajoslin/switch-fn","last_synced_at":"2025-07-31T05:10:09.816Z","repository":{"id":65510398,"uuid":"51715946","full_name":"ajoslin/switch-fn","owner":"ajoslin","description":"Write a functional switch statement.","archived":false,"fork":false,"pushed_at":"2017-07-25T14:45:25.000Z","size":7,"stargazers_count":43,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-07-05T03:03:41.198Z","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/ajoslin.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":"2016-02-14T21:52:03.000Z","updated_at":"2024-11-14T03:10:17.000Z","dependencies_parsed_at":"2023-01-26T17:55:11.665Z","dependency_job_id":null,"html_url":"https://github.com/ajoslin/switch-fn","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/ajoslin/switch-fn","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajoslin%2Fswitch-fn","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajoslin%2Fswitch-fn/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajoslin%2Fswitch-fn/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajoslin%2Fswitch-fn/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ajoslin","download_url":"https://codeload.github.com/ajoslin/switch-fn/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajoslin%2Fswitch-fn/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267989064,"owners_count":24177020,"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-07-31T02:00:08.723Z","response_time":66,"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-07-31T02:01:03.225Z","updated_at":"2025-07-31T05:10:09.781Z","avatar_url":"https://github.com/ajoslin.png","language":"JavaScript","readme":"# switch-fn [![Build Status](https://travis-ci.org/ajoslin/switch-fn.svg?branch=master)](https://travis-ci.org/ajoslin/switch-fn)\n\n\u003e Write a functional switch statement.\n\n## Install\n\n```\n$ npm install --save switch-fn\n```\n\n## Usage\n\n```js\nvar Switch = require('switch-fn')\n\nvar fn = Switch({\n  a: actionA,\n  b: actionB,\n  default: defaultAction\n})\n\nvar result = fn('a') // =\u003e calls actionA with 'a' and gives back actionA's return value\n```\n\n## API\n\n#### `Switch(cases)` -\u003e `function`\n\n##### cases\n\n*Required*\nType: `object`\n\nAn object, with keys being the 'cases' to match against and values being the function to call in each case.\n\nIf no case matching the input is found and a 'default' case is given, it will be used.\n\n# More Examples\n\n#### With a \"property getter\" for more complicated objects\n\n```js\nconst Switch = require('switch-fn')\nconst pipe = require('value-pipe')\n\nconst mySwitch = pipe(\n  value =\u003e value.username.toLowerCase(),\n  Switch({\n    alice: () =\u003e 'hello, alice',\n    john: () =\u003e 'hello, john'\n  })\n)\n\nmySwitch({ username: 'Alice' }) // =\u003e 'hello, alice'\n```\n\n#### Pass in an array for numbers only\n\n```js\nvar Switch = require('switch-fn')\n\nvar fn = Switch([onZero, onOne])\n\nfn(0)\n```\n\n#### Fibonacci\n\n```es6\nvar fib = Switch({\n  0: (n) =\u003e n,\n  1: (n) =\u003e n,\n  default: (n) =\u003e fib(n - 1) + fib(n - 2)\n});\n\nfib(10) // =\u003e 55\n```\n\n## License\n\nMIT © [Andrew Joslin](http://ajoslin.com)\n","funding_links":[],"categories":["JavaScript","Libraries"],"sub_categories":["[Javascript](https://developer.mozilla.org/en-US/docs/Web/JavaScript)"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fajoslin%2Fswitch-fn","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fajoslin%2Fswitch-fn","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fajoslin%2Fswitch-fn/lists"}