{"id":18552440,"url":"https://github.com/andrejewski/result","last_synced_at":"2025-09-07T07:32:42.350Z","repository":{"id":57097473,"uuid":"396188093","full_name":"andrejewski/result","owner":"andrejewski","description":"Typescript result type","archived":false,"fork":false,"pushed_at":"2021-08-16T06:48:32.000Z","size":36,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-09-07T07:32:18.037Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/andrejewski.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":"2021-08-15T02:10:50.000Z","updated_at":"2021-08-16T20:01:41.000Z","dependencies_parsed_at":"2022-08-20T18:10:23.433Z","dependency_job_id":null,"html_url":"https://github.com/andrejewski/result","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/andrejewski/result","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrejewski%2Fresult","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrejewski%2Fresult/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrejewski%2Fresult/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrejewski%2Fresult/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andrejewski","download_url":"https://codeload.github.com/andrejewski/result/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrejewski%2Fresult/sbom","scorecard":{"id":192848,"data":{"date":"2025-08-11","repo":{"name":"github.com/andrejewski/result","commit":"6459b6c45ec1783869fd35f33458d0cc92f5ec4a"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":1.7,"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":"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":"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":"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/4 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":"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":"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":"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":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"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 'main'"],"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":"11 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg","Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275","Warn: Project is vulnerable to: GHSA-pfrx-2q88-qq97","Warn: Project is vulnerable to: GHSA-rc47-6667-2j5j","Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv","Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3","Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h","Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw","Warn: Project is vulnerable to: GHSA-38fc-wpqx-33j7"],"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-16T21:09:04.207Z","repository_id":57097473,"created_at":"2025-08-16T21:09:04.208Z","updated_at":"2025-08-16T21:09:04.208Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274010103,"owners_count":25206763,"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-09-07T02:00:09.463Z","response_time":67,"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-11-06T21:14:13.454Z","updated_at":"2025-09-07T07:32:42.293Z","avatar_url":"https://github.com/andrejewski.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @andrejewski/result\n\nA result type written in TypeScript\n\n```sh\nnpm install @andrejewski/result\n```\n\n```ts\nimport { Result, ok, err } from '@andrejewski/result'\n\nfunction parseJSON (json: string): Result\u003cunknown, SyntaxError\u003e {\n  try {\n    return ok(JSON.parse(json))\n  } catch (error) {\n    if (error instanceof SyntaxError) {\n      return err(error)\n    }\n\n    throw error\n  }\n}\n\nconst parseResult = parseJSON('{\"foo\": \"bar\"}')\nconst fooResult = parseResult.andThen(value =\u003e {\n  if (!(value \u0026\u0026 value.foo \u0026\u0026 typeof value.foo === 'string')) {\n    err(new Error('Field `foo` must be of type string'))\n  }\n\n  return ok(value.foo)\n})\n\nconst foo = fooResult.match({\n  ok (value) {\n    return value\n  },\n  err (error) {\n    throw error\n  }\n})\n```\n\n## Documentation\n\nSee the type definitions and code comments for detailed documentation.\n\n## Cool features\n\n### Limited constructors\n\nThere's only two ways to create result types: `ok` and `err`.\nNice and short: no need to use `new Result(x, y)`, `new Ok(x)`, etc.\n\n### Type narrowing\n\nTo let Typescript help us, we enable type guards via discriminated unions on multiple fields, so we can write clean branches:\n\n```ts\nimport { Result, ok } from '@andrejewski/result'\n\nconst result = ok(1) as Result\u003cnumber, never\u003e\n\n// Type guard using `type` property\nif (result.type === 'ok') {\n  // We can now access `value`\n  console.log(result.value)\n} else {\n  // We can now access `error`\n  console.log(result.error)\n}\n\n// Type guard using `isOk` property\nif (result.isOk) {\n  // We can now access `value`\n  console.log(result.value)\n} else {\n  // We can now access `error`\n  console.log(result.error)\n}\n\n// Type guard using `isErr` property\nif (result.isErr) {\n  // We can now access `error`\n  console.log(result.error)\n} else {\n  // We can now access `value`\n  console.log(result.value)\n}\n```\n\n### A lack of features\n\nHey now, lack of features is totally a feature!\n\n#### No `unwrap`\n\nYou'll notice I didn't add some \"niceties\" like `Result#unwrap`, which throws the err component and returns the ok component of a result.\nIncluding those methods makes it too easy to use them internally whereas they should really only be used, if at all, at the edges of a system.\nFolks can build there own on top but the friction of doing so is a feature.\n\n#### No `toJSON`\n\nWe don't provide any common mechanism for JSON de/serialization because it has many quirks. These can be built on top but don't need to be in this package.\n\n#### No `try` sugar\n\nIf you are coming from Rust, you'll have loved the `result?` unwrapping sugar. Unfortunately that type of sugar, even as written as `unwrap(result)` instead of a macro, is not going to be helped by TypeScript. Simply put, there's no good way to have a good error type derived from successive calls of a function:\n\n```ts\nconst result = Result.try(unwrap =\u003e {\n  const a = unwrap(fnErrorsA())\n  const b = unwrap(fnErrorsB(a))\n  return ok(nonResultFn(b))\n})\n```\n\nHere, the best we could do is `result` having type `Result\u003ctypeof b, unknown\u003e` but that's not good enough!\nI don't wanna have to re-check for all the potential errors.  \nSo we don't include any syntactic sugar to make this easier, preferring correctness and precise types.\n\n## Why not use X?\n\nThere are alternatives to this package's take on result type.\nHere are some and why I'm not using them:\n\n### [`result`](https://www.npmjs.com/package/result):\n\n- Large surface area: tons of methods that aren't necessary\n- `.then` and `.node` smatter against Promise and callback asynchrony\n- No TypeScript types\n\n### [`result-js`](https://www.npmjs.com/package/result-js)\n\n- No TypeScript types\n- Verbose methods for checking type e.g. `result.isOk()` that can't type guard\n- Verbose constructors `fromSuccess` and `fromError` which mismatch `ok`/`err` naming\n- Many `unwrap*` methods which make it too easy to use exceptions\n\n### [`typescript-result`](https://www.npmjs.com/package/typescript-result)\n\n- Poor Typescript types\n- Couples the `err` type to `Error` which need not be the case\n- Puts the `err` type on the leftmost type parameter which is very confusing to read\n- Provides weird `Result.safe` method\n\n### [`ts-results`](https://www.npmjs.com/package/ts-results)\n\n- Includes an `Option` type which isn't needed in JavaScript/Typescript\n- Member `ok.val` is the same in `err.val` meaning you don't need to narrow the type to access the value, and you might forget to do that\n- Includes `expect` and `unwrap` methods which encourage exceptions\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrejewski%2Fresult","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandrejewski%2Fresult","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrejewski%2Fresult/lists"}