{"id":16641361,"url":"https://github.com/cmstead/matchlight","last_synced_at":"2025-08-23T01:44:26.301Z","repository":{"id":38326062,"uuid":"96913063","full_name":"cmstead/matchlight","owner":"cmstead","description":"A rich pattern matching library to light up your code","archived":false,"fork":false,"pushed_at":"2022-12-06T20:50:57.000Z","size":678,"stargazers_count":1,"open_issues_count":8,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-18T01:49:41.458Z","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/cmstead.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-07-11T16:15:21.000Z","updated_at":"2021-04-15T07:51:56.000Z","dependencies_parsed_at":"2023-01-23T15:01:55.177Z","dependency_job_id":null,"html_url":"https://github.com/cmstead/matchlight","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/cmstead/matchlight","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cmstead%2Fmatchlight","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cmstead%2Fmatchlight/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cmstead%2Fmatchlight/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cmstead%2Fmatchlight/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cmstead","download_url":"https://codeload.github.com/cmstead/matchlight/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cmstead%2Fmatchlight/sbom","scorecard":{"id":294402,"data":{"date":"2025-08-11","repo":{"name":"github.com/cmstead/matchlight","commit":"dd91110aa82e2df64382f9f1a95d582ac71b0769"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":1.3,"checks":[{"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":"Code-Review","score":0,"reason":"Found 0/30 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":"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":"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":"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":"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":"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":"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":"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":"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":"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":"83 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw","Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw","Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92","Warn: Project is vulnerable to: GHSA-qwcr-r2fm-qrc7","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-x9w5-v3q2-3rhw","Warn: Project is vulnerable to: GHSA-wg6g-ppvx-927h","Warn: Project is vulnerable to: GHSA-pxg6-pf52-xh8x","Warn: Project is vulnerable to: GHSA-rq8g-5pc5-wrhr","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-r9p9-mrjm-926w","Warn: Project is vulnerable to: GHSA-434g-2637-qmqr","Warn: Project is vulnerable to: GHSA-49q7-c7j4-3p7m","Warn: Project is vulnerable to: GHSA-977x-g7h5-7qgw","Warn: Project is vulnerable to: GHSA-f7q4-pwc6-w24p","Warn: Project is vulnerable to: GHSA-fc9h-whq2-v747","Warn: Project is vulnerable to: GHSA-vjh7-7g9h-fjfh","Warn: Project is vulnerable to: GHSA-j4f2-536g-r55m","Warn: Project is vulnerable to: GHSA-r7qp-cfhv-p84w","Warn: Project is vulnerable to: GHSA-4gmj-3p3h-gm8h","Warn: Project is vulnerable to: GHSA-qrmc-fj45-qfc2","Warn: Project is vulnerable to: GHSA-fjxv-7rqg-78g4","Warn: Project is vulnerable to: GHSA-qh2h-chj9-jffq","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-6x33-pw7p-hmpq","Warn: Project is vulnerable to: GHSA-4hpf-3wq7-5rpr","Warn: Project is vulnerable to: GHSA-f522-ffg8-j8r6","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-282f-qqgm-c34q","Warn: Project is vulnerable to: GHSA-7x7c-qm48-pq9c","Warn: Project is vulnerable to: GHSA-rc3x-jf5g-xvc5","Warn: Project is vulnerable to: GHSA-jf85-cpcp-j695","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-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-82v2-mx6x-wq7q","Warn: Project is vulnerable to: GHSA-p9wx-2529-fp83","Warn: Project is vulnerable to: GHSA-5v2h-r2cx-5xgj","Warn: Project is vulnerable to: GHSA-rrrm-qjm4-v8hf","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-w9mr-4mfr-499f","Warn: Project is vulnerable to: GHSA-q75g-2496-mxpp","Warn: Project is vulnerable to: GHSA-6fx8-h7jm-663j","Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9","Warn: Project is vulnerable to: GHSA-9wv6-86v2-598j","Warn: Project is vulnerable to: GHSA-h7cp-r72f-jxh6","Warn: Project is vulnerable to: GHSA-v62p-rq8g-8h59","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-g4rg-993r-mgx7","Warn: Project is vulnerable to: GHSA-4rq4-32rv-6wp6","Warn: Project is vulnerable to: GHSA-64g7-mvw6-v9qj","Warn: Project is vulnerable to: GHSA-fxwf-4rqh-v8g3","Warn: Project is vulnerable to: GHSA-25hc-qcg6-38wj","Warn: Project is vulnerable to: GHSA-xfhh-g9f5-x4m4","Warn: Project is vulnerable to: GHSA-qm95-pgcg-qqfq","Warn: Project is vulnerable to: GHSA-cqmj-92xf-r6r9","Warn: Project is vulnerable to: GHSA-2m39-62fm-q8r3","Warn: Project is vulnerable to: GHSA-mf6x-7mm4-x2g7","Warn: Project is vulnerable to: GHSA-4wf5-vphf-c2xc","Warn: Project is vulnerable to: GHSA-52f5-9888-hmc6","Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3","Warn: Project is vulnerable to: GHSA-mgfv-m47x-4wqp","Warn: Project is vulnerable to: GHSA-5v72-xg48-5rpm","Warn: Project is vulnerable to: GHSA-72mh-269x-7mh5","Warn: Project is vulnerable to: GHSA-h4j5-c7cj-74xg"],"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-17T19:07:15.074Z","repository_id":38326062,"created_at":"2025-08-17T19:07:15.074Z","updated_at":"2025-08-17T19:07:15.074Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271731583,"owners_count":24811307,"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-12T07:46:20.753Z","updated_at":"2025-08-23T01:44:26.267Z","avatar_url":"https://github.com/cmstead.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n\u003c!-- GENERATED DOCUMENT! DO NOT EDIT! --\u003e\n# Matchlight #\n#### Pattern matching -- conditional logic for humans ####\n\n[v1 docs can be found here](https://github.com/cmstead/matchlight/tree/v1.2.8)\n\n\n## Table Of Contents ##\n\n- [Section 1: Why Matchlight?](#user-content-why-matchlight?)\n- [Section 2: Installation](#user-content-installation)\n- [Section 3: Setting Up Matchlight](#user-content-setting-up-matchlight)\n- [Section 4: Examples](#user-content-examples)\n- [Section 5: Matchlight API](#user-content-matchlight-api)\n\n## Why Matchlight? ##\n\nJavaScript has a number of useful conditional structures, including if/else structres, switches, and ternary expressions. Functional programming languages have another construct that adds extra power to conditional behaviors -- pattern matching. Matchlight is a pattern matching library for JavaScript that allows the programmer to match conditions based on the shape of data instead of imperative conditional construction.\n\nWhy pattern matching?\n\nWhen conditions are simple, the standard JavaScript conditional behaviors are completely acceptable. Conditionals, however, tend to get muddy and confusing when they start describing the shape of the data that should be acceptable.\n\nImagine if you could simply outline the data and your conditional would do the work of properly comparing the shape to your outline. Perhaps you create a conditional that looks like this:\n\n```javascript\nif (\n    typeof dataBlob?.givenName === \"string\" \u0026\u0026\n    typeof dataBlob?.familyName === \"string\" \u0026\u0026\n    typeof dataBlob?.phoneNumber?.locale === \"string\" \u0026\u0026\n    typeof dataBlob?.address?.postalCode === \"string\"\n) {\n    // do something\n} else {\n    throw new Error(\"Missing data blob information\");\n}\n```\n\nWhat if, instead, you could do something like this:\n\n```javascript\nmatch(dataBlob, function (on, onDefault) {\n    const expectedDataShape = {\n        givenName: STRING,\n        familyName: STRING,\n        phoneNumber: { locale: STRING },\n        address: { postalCode: STRING }\n    };\n\n    on(expecteDataShape, (dataBlob) =\u003e { /* doSomething */ });\n    onDefault(() =\u003e { throw new Error(\"Missing data blob information\"); });\n});\n```\n\nThis is the power that pattern matching offers. You can simply describe the data as it should be, instead of having to laboriously reference each property and sub property, generating a long list of `\u0026\u0026` concatenated boolean expressions. Matchlight lets you write conditions the way people think.\n\nIt's conditional matching for humans.\n\n    \n\n## Installation ##\n\nMatchlight works with Node.js and web projects. Nevertheless, it is recommended that you\nuse npm to install Matchlight in your project so you can easily keep it up to date. Make sure you have Node.js installed on your computer and, from your project file, run the following:\n\n`npm i matchlight`\n\nIf you want to download Matchlight by hand, you can do so from the main repo:\n\n[https://github.com/cmstead/matchlight](https://github.com/cmstead/matchlight)\n\n    \n\n## Setting Up Matchlight ##\n\nFor web projects, Matchlight has a minified web build available in matchlight/dist/. You can either copy it manually to your project folder, or you can add it to your build pipeline. That choice is yours to make and understand.\n\nTo use Matchlight in the browser, simply include it in your page like so:\n\n`\u003cscript src=\"path/to/matchlight/matchlight.js\"\u003e\u003c/script\u003e`\n\nTo use Matchlight in your node application, you can require it this way:\n\n```javascript\nconst { match, matcher } = require('matchlight');\n```\n\nThere are other tools and helpers with Matchlight. They can be destructured during require in the same way:\n\n```javascript\nconst { match, matchArguments, matcher, types } = require('matchlight');\n```\n\n    \n\n## Examples ##\n\nInstead of an exhaustive listing of the Matchlight API, let's take a look at how to use Matchlight through some examples.\n\nSimple pattern matching with values and a default:\n\n```javascript\nfunction fibonacci(n) {\n    return match(n, function(onCase, onDefault) {\n        onCase(0, () =\u003e 1);\n        onCase(1, () =\u003e 1);\n        onDefault(x =\u003e fibonacci(x-1) + fibonacci(x - 2));\n    });\n}\n```\n\nPattern matching using types:\n\n```javascript\nconst { match, types: { NUMBER, STRING } } = require('matchlight');\n\n// parseFloat does this all, already, but it's a handy example\nfunction numberifyFloat(x){\n    return match(x, function(onCase, onDefault){\n        onCase(NUMBER, x =\u003e x);\n        onCase(STRING, x =\u003e parseFloat(x));\n        onDefault(() =\u003e NaN);\n    });\n}\n```\n\nWhere the real power starts to shine...\n\nMatch on data shape:\n\n```javascript\n/*\nIn this example, the array must be exactly 4 elements long\nwith a single number in an array as the final element\n*/\n\nfunction multiplyOnMatch(values) {\n    return match(x, function(onCase, onDefault){\n        onCase([NUMBER, , , [NUMBER]], ([x, , , [y]]) =\u003e x * y);\n        onDefault(() =\u003e 0);\n    });\n}\n```\n\nGet last value from an array (of any length) if it's a number:\n\n```javascript\nconst { match, types: { NUMBER, STRING } } = require('matchlight');\n\nconst last = values =\u003e values[values.length - 1];\n\nfunction getLastNumberOrDefault(values, defaultNumber = 0) {\n    return match(values, function(onCase, onDefault) {\n        onCase([matcher('...'), NUMBER], (values) =\u003e last(values));\n        onDefault(() =\u003e defaultNumber);\n    });\n}\n```\n\nRegular expressions:\n\n```javascript\nfunction getValidationMessage(phoneNumber) {\n    return match(phoneNumber, function(onCase, onDefault){\n        onCase(/\\([0-9]{3}\\) [0-9]{3}-[0-9]{4}/,\n            () =\u003e 'Phone number is an acceptable US format');\n        onDefault(() =\u003e 'Phone number did not match any expected format');\n    });\n}\n```\n\nUser defined functions:\n\n```javascript\nfunction getNumberType(value) {\n    return match(value, function(onCase, onDefault) {\n        onCase(value =\u003e !NUMBER(value), () =\u003e 'nan');\n        onCase(value =\u003e Math.abs(value) === Infinity, () =\u003e 'infinity');\n        onCase(value =\u003e Math.floor(value) === value, () =\u003e 'int');\n        onDefault(() =\u003e 'float');\n    });\n}\n```\n\n    \n\n## Matchlight API ##\n\nMatchlight has a relatively small API footprint. This list will be significantly less useful than the provided examples for learning how to use Matchlight. Instead consider this a reference to generate questions.\n\n### Functions and Properties ###\n\n- `match`\n    - Starts a new match expression\n    - Accepts a value to match on, and a function in which to create cases statements\n- `matchArguments`\n    - Matches on function arguments, specifically to support the `arguments` keyword\n    - Treats arguments as an array -- otherwise behaves identically to `match`\n- `matcher`\n    - Provides access to visually semantic matchers like `...` and `...rest`\n- `types`\n    - An object containing all type definitions supported by Matchlight\n\n### Matchers ###\n\nMatchers are special matching behaviors which allow the user to skip, or capture elements from an array.\n\n- `...`\n    - Seek matcher -- skips all values until next defined matching sequence is found\n- `...rest`\n    - Rest matcher -- acts as a capture matcher for all remaining elements in an array\n    - This will skip matching any elements AFTER the rest matcher. To skip some elements, use the seek matcher\n\n### Types ###\n\nMatchlight supports all of the standard JavaScript types, plus an `ANY` type which will accept any value. All types are available on the `type` property. (see functions and properties API reference) The list is as follows:\n\n- `ANY`\n- `ARRAY`\n- `BIGINT`\n- `BOOLEAN`\n- `FUNCTION`\n- `NULL`\n- `NUMBER`\n- `OBJECT`\n- `STRING`\n- `SYMBOL`\n- `UNDEFINED`\n\n    \n\n\n\u003c!-- GENERATED DOCUMENT! DO NOT EDIT! --\u003e\n    ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcmstead%2Fmatchlight","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcmstead%2Fmatchlight","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcmstead%2Fmatchlight/lists"}