{"id":34786816,"url":"https://github.com/lleaff/match-expression","last_synced_at":"2026-05-25T02:04:12.461Z","repository":{"id":57291832,"uuid":"93178017","full_name":"lleaff/match-expression","owner":"lleaff","description":"Switch/match expression for Javascript.","archived":false,"fork":false,"pushed_at":"2017-10-25T14:34:18.000Z","size":29,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-05-19T10:59:19.604Z","etag":null,"topics":["functional-programming","javascript","match","switch"],"latest_commit_sha":null,"homepage":"","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/lleaff.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":"2017-06-02T15:15:12.000Z","updated_at":"2017-06-12T21:35:10.000Z","dependencies_parsed_at":"2022-08-27T12:20:32.344Z","dependency_job_id":null,"html_url":"https://github.com/lleaff/match-expression","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/lleaff/match-expression","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lleaff%2Fmatch-expression","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lleaff%2Fmatch-expression/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lleaff%2Fmatch-expression/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lleaff%2Fmatch-expression/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lleaff","download_url":"https://codeload.github.com/lleaff/match-expression/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lleaff%2Fmatch-expression/sbom","scorecard":{"id":595339,"data":{"date":"2025-08-11","repo":{"name":"github.com/lleaff/match-expression","commit":"0e07a527e49fbdec56443cb68396e28f3abc5979"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":1.3,"checks":[{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Code-Review","score":0,"reason":"Found 0/12 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"License","score":0,"reason":"license file not detected","details":["Warn: project does not have a license file"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":0,"reason":"57 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw","Warn: Project is vulnerable to: GHSA-fwr7-v2mv-hh25","Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-cwfw-4gq5-mrqx","Warn: Project is vulnerable to: GHSA-g95f-p29q-9xw4","Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg","Warn: Project is vulnerable to: GHSA-9vvw-cc9w-f27h","Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c","Warn: Project is vulnerable to: GHSA-h6ch-v84p-w6p9","Warn: Project is vulnerable to: GHSA-qrmc-fj45-qfc2","Warn: Project is vulnerable to: GHSA-fjxv-7rqg-78g4","Warn: Project is vulnerable to: GHSA-q42p-pg8m-cqh6","Warn: Project is vulnerable to: GHSA-w457-6q6x-cgp9","Warn: Project is vulnerable to: GHSA-62gr-4qp9-h98f","Warn: Project is vulnerable to: GHSA-f52g-6jhx-586p","Warn: Project is vulnerable to: GHSA-2cf5-4w76-r9qv","Warn: Project is vulnerable to: GHSA-3cqr-58rm-57f8","Warn: Project is vulnerable to: GHSA-g9r4-xpmj-mj65","Warn: Project is vulnerable to: GHSA-q2c6-c6pm-g3gh","Warn: Project is vulnerable to: GHSA-765h-qjxv-5f44","Warn: Project is vulnerable to: GHSA-f2jv-r9rf-7988","Warn: Project is vulnerable to: GHSA-44pw-h2cw-w3vq","Warn: Project is vulnerable to: GHSA-jp4x-w63m-7wgm","Warn: Project is vulnerable to: GHSA-c429-5p7v-vgjp","Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj","Warn: Project is vulnerable to: GHSA-2pr6-76vf-7546","Warn: Project is vulnerable to: GHSA-8j8c-7jfh-h6hx","Warn: Project is vulnerable to: GHSA-896r-f27r-55mw","Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h","Warn: Project is vulnerable to: GHSA-fvqr-27wr-82fm","Warn: Project is vulnerable to: GHSA-4xc9-xhrj-v574","Warn: Project is vulnerable to: GHSA-x5rq-j2xg-h7qm","Warn: Project is vulnerable to: GHSA-jf85-cpcp-j695","Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw","Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9","Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm","Warn: Project is vulnerable to: GHSA-f9cm-qmx5-m98h","Warn: Project is vulnerable to: GHSA-7wpw-2hjm-89gp","Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv","Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3","Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m","Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h","Warn: Project is vulnerable to: GHSA-5fw9-fq32-wv5p","Warn: Project is vulnerable to: GHSA-6394-6h9h-cfjg","Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9","Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp","Warn: Project is vulnerable to: GHSA-6g33-f262-xjp4","Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6","Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw","Warn: Project is vulnerable to: GHSA-2m39-62fm-q8r3","Warn: Project is vulnerable to: GHSA-mf6x-7mm4-x2g7","Warn: Project is vulnerable to: GHSA-jgrx-mgxx-jf9v","Warn: Project is vulnerable to: GHSA-g7q5-pjjr-gqvp","Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3","Warn: Project is vulnerable to: GHSA-c4w7-xm78-47vh","Warn: Project is vulnerable to: GHSA-p9pc-299p-vxgp"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-20T23:02:35.337Z","repository_id":57291832,"created_at":"2025-08-20T23:02:35.337Z","updated_at":"2025-08-20T23:02:35.337Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33457339,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-24T19:21:36.376Z","status":"online","status_checked_at":"2026-05-25T02:00:05.812Z","response_time":57,"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":["functional-programming","javascript","match","switch"],"created_at":"2025-12-25T09:27:49.961Z","updated_at":"2026-05-25T02:04:12.454Z","avatar_url":"https://github.com/lleaff.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Match expression\n[![npm](https://img.shields.io/npm/v/match-expression.svg)](https://www.npmjs.com/package/match-expression)\n[![Build Status](https://travis-ci.org/lleaff/match-expression.svg?branch=master)](https://travis-ci.org/lleaff/match-expression)\n\nA flexible switch/match expression utility for Javascript.\n\n```javascript\nimport match from 'match-expression'\n\nconst x = match('bar')\n  .case('foo')\n    .then(() =\u003e 'FOO')\n  .case('bar')\n  .case('baz')\n    .then(() =\u003e 'BARBAZ')\n  .default(() =\u003e 'DEFAULT')\n\n// x === 'BARBAZ'\n```\n\n### Custom comparison function\n\nApply and get regular expression capture group matches in one go:\n\n```javascript\nconst inputUrl = \"http://eat-frogs.io/dishes/parmigiana-di-rana\"\n\nfunction regexMatch(str, regex) { return regex.exec(str) }\n\nconst httpsUrl = match(inputUrl, regexMatch)\n  .case(/^http:\\/\\/(.*)/)\n    .then((url, _, [, noprotocol]) =\u003e `https://${noprotocol}`)\n  .case(/^\\//)\n    .then(url =\u003e `https://${DOMAIN}${url}`)\n  .default(url =\u003e url)\n\n// httpsUrl === \"https://eat-frogs.io/dishes/parmigiana-di-rana\"\n```\n\n### No default clause\n\nExecute the function returned by `then` to resolve to a value without having to use a `default` clause.\n\n```javascript\nmatch(person.type)\n  .case('HUMAN').then(() =\u003e greet(person))\n  .case('NOT_HUMAN').then(() =\u003e eat(person))()\n```\n\n### [Interactive examples](https://npm.runkit.com/match-expression)\n\n## API\n\n### `match( value [, comparisonFunction] )`\n**`value`**`: any`  \n  The *value* to be matched against the subsequent *case*s.  \n**`comparisonFunction`**`: (value, caseValue) =\u003e any` (*optional*)  \n   Defaults to strict equality (`===`).  \n   It is passed the initial value as first argument and the comparing value as second. If its result is truthy, then the initial value is interpreted as matching the comparing value.  \n   Its result with the matching value is used a the third argument to the matching `then` clause.  \n   Once a value has matched, the comparison function is not called anymore.  \n**Returns**`: { case }`  \n   An object with a `.case` method.\n\n### `.case( comparisonValue [, ...] )`\n_Available after `match` and `case` clauses._  \n**`comparisonValue`**`: any`  \n  The value(s) to compare with the initial value provided to `match`. The actual matched value will be passed as second argument to `then` handler.  \n**Returns**`: { then, case }`  \n   An object with `.then` and `.case` methods.  \n  \n### `.then( callback )`\n_Available after `case` clauses._  \n**`callback`**`: (value, matchedValue, comparisonFunctionResult) =\u003e any`  \n  Executed only if a previous `case` clause matched, in which case its return value will be used as the return value of the match expression.  \n  The first argument is the initial value, the second is the matching *case* value, the third one is the result of the call to the comparison function with the two previous arguments (defaults to `true` if no custom `comparisonFunction` was provided).  \n**Returns**`: [Callable: () =\u003e result]{ case, default }`  \n  A callable object with `.case` and `.default` methods.  \n  The function can be called to resolve the match directly, without a \"`default`\" clause.\n  \n### `.default( callback )`\n_Available after `then` clauses._  \n**`callback`**`: (value) =\u003e any`  \n  Executed only if no previous `case` clause matched, in which case its return value will be used as the return value of the match expression. \n  The first argument is the initial value.  \n**Returns**`: any`  \n  Returns resolved value from `then` clause callback corresponding to the matched `case` clause, or from its own callback if no `case` matched.\n  \n## Notes\n\n* Checkout [`./test.js`](test.js) for an exhaustive spec.\n* Before writing this package I wasn't particularly fond of the builder-style API, so I wrote another match expression module that had a more data-oriented API. The configuration was made through a big array passed to `match`:  \n  `match: (value, [ ...cases, default ])`  \n  where `cases: [ [ ...caseValues, callback ] ]` and `default: [ callback ]`.  \n  Turns out that it's very unreadable for anything non-trivial. So in case the builder style API is an initial turn off for you, put yourself in the shoes of someone reading your code: the _case_, _then_ and _default_ visual keywords are very helpful in making the code more understandable.\n* Related: [if-exp](https://www.npmjs.com/package/if-exp)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flleaff%2Fmatch-expression","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flleaff%2Fmatch-expression","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flleaff%2Fmatch-expression/lists"}