{"id":39584763,"url":"https://github.com/garrettm/tsum","last_synced_at":"2026-01-26T15:01:21.543Z","repository":{"id":57381870,"uuid":"104601286","full_name":"garrettm/tsum","owner":"garrettm","description":"Typescript sum types with pattern matching, using multimethods","archived":false,"fork":false,"pushed_at":"2017-11-05T22:32:59.000Z","size":13,"stargazers_count":17,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-09-07T10:32:41.584Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/garrettm.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-09-23T21:49:52.000Z","updated_at":"2024-02-26T18:30:33.000Z","dependencies_parsed_at":"2022-09-13T11:31:15.579Z","dependency_job_id":null,"html_url":"https://github.com/garrettm/tsum","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/garrettm/tsum","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/garrettm%2Ftsum","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/garrettm%2Ftsum/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/garrettm%2Ftsum/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/garrettm%2Ftsum/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/garrettm","download_url":"https://codeload.github.com/garrettm/tsum/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/garrettm%2Ftsum/sbom","scorecard":{"id":419101,"data":{"date":"2025-08-11","repo":{"name":"github.com/garrettm/tsum","commit":"dabfe304e85d28bf40839d71f21401249168fb40"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.6,"checks":[{"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":"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":"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":"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":"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":"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":"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":"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":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"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"}}]},"last_synced_at":"2025-08-19T00:43:05.091Z","repository_id":57381870,"created_at":"2025-08-19T00:43:05.091Z","updated_at":"2025-08-19T00:43:05.091Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28781308,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-26T13:55:28.044Z","status":"ssl_error","status_checked_at":"2026-01-26T13:55:26.068Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":"2026-01-18T07:35:27.100Z","updated_at":"2026-01-26T15:01:21.536Z","avatar_url":"https://github.com/garrettm.png","language":"TypeScript","readme":"# tsum\nTypescript sum types with pattern matching, using multimethods\n\n## Install\n`npm install --save tsum`\n\n`yarn add tsum`\n\n## Motivation\nBeing able to simply represent, manipulate, and pattern match on immutable values is one of the most important things a programming language can provide.\n\nTypescript offers two built-in solutions:\n1. Add a 'type' field to all your data, and switch on it.  This is verbose, requires explicit serialize/deserialize, and error prone when specifying literal data.  Additionally, switch offers no exhaustiveness guarantee, and is a statement rather than an expression.\n2. Put your data into classes.  This is verbose, requires explicit serialize/deserialize and lacks named fields:  \n`new Person('Garrett')` vs `{name: 'Garrett'}`  \nMost importantly, you lose the ability to easily make new immutable values from previous values.\n\nUsing plain data structures solves many of these problems, and improves notation:\n- Values are trivial to persist or send over a wire, and trivial to read when receiving data from the wire or disk\n- Data definitions are as terse and straightforward as possible in Typescript\n- Fields are named\n- Open system, as long as a piece of data matches one of these interfaces, it can participate in this polymorphism (unlike classes)\n- Matching every possible case is enforced by the compiler, and matches are expressions which return a value\n- Critically, you gain the ability to use spread notation to flexibly produce new values:  \n`const olderPerson = {...person, age: person.age + 1}`  \nClasses offer no equivalent to this\n\n## Example\n```ts\nimport Sum from 'tsum'\n```\n\n\nDescribe each of your types:\n```ts\ninterface Dog {\n  name: string\n  color: string\n}\n\ninterface Cat {\n  name: string \n  dogFriendly: boolean\n}\n\ninterface Chicken {\n  eggsLaid: number\n}\n\ninterface Cow {\n  mooVolume: number\n}\n```\n\nPut them together:\n```ts\ninterface Animals {\n  Dog: Dog\n  Cat: Cat\n  Chicken: Chicken\n  Cow: Cow\n}\n```\n\nProvide the Animals interface, along with a set of predicates to determine the type of an arbitrary Animal:\n```ts\nconst Animal = Sum\u003cAnimals\u003e({\n  predicates: ({isString, isBoolean, isNumber}) =\u003e ({\n    Dog:     _ =\u003e isString(_.color),\n    Cat:     _ =\u003e isBoolean(_.dogFriendly),\n    Chicken: _ =\u003e isNumber(_.eggsLaid),\n    Cow:     _ =\u003e isNumber(_.mooVolume)\n  })\n})\n```\n\n\nCreate functions that act on any Animal:\n```ts\n// The type of describe is: (animal: Animal) =\u003e string\nconst describe = Animal.f({\n  // Typescript knows the type in each branch, and makes sure you cover all cases\n  Dog: dog =\u003e `a ${dog.color} dog named ${dog.name}`,\n  Cat: cat =\u003e cat.dogFriendly ? `a cat named ${cat.name} (dog-friendly)` : `a cat named ${cat.name} (not dog-friendly)`,\n  Chicken: chicken =\u003e `a chicken who has laid ${chicken.eggsLaid} eggs`,\n  Cow: cow =\u003e cow.mooVolume \u003e 5 ? 'a loud cow' : 'a quiet cow'\n})\n\nconst dog = {name: 'Zorro', color: 'grey'}\nconst cat = {name: 'Oberyn', dogFriendly: false}\nconst chicken = {eggsLaid: 13}\nconst cow = {mooVolume: 6}\n\nconsole.log(describe(dog))     // a grey dog named Zorro\nconsole.log(describe(cat))     // a cat named Oberyn (not dog-friendly)\nconsole.log(describe(chicken)) // a chicken who has laid 13 eggs\nconsole.log(describe(cow))     // a loud cow\n```\n\nOr match inline:\n```ts\nconst cat = {name: 'Oberyn', dogFriendly: false}\nconst cost = Animal.match(cat, {\n  Dog: dog =\u003e dog.name === 'Zorro' ? 99999 : 300,\n  Cat: cat =\u003e cat.name === 'Oberyn' ? 99999 : 800,\n  Chicken: chicken =\u003e chicken.eggsLaid * 10,\n  Cow: cow =\u003e cow.mooVolume \u003e 5 ? 5000 : 6000\n})\nconsole.log(cost) // 99999\n```\n\nConvenience to avoid repeating yourself:\n```ts\n// Evaluates to Dog | Cat | Chicken | Cow\ntype Animal = typeof Animal.types\n```\n\n## Thanks to:\n[The Value of Values](https://www.youtube.com/watch?v=-6BsiVyC1kM)\n","funding_links":[],"categories":["\u003ca name=\"TypeScript\"\u003e\u003c/a\u003eTypeScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgarrettm%2Ftsum","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgarrettm%2Ftsum","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgarrettm%2Ftsum/lists"}