{"id":20253960,"url":"https://github.com/frectonz/optionem","last_synced_at":"2026-05-07T20:48:56.608Z","repository":{"id":57315885,"uuid":"395633786","full_name":"frectonz/optionem","owner":"frectonz","description":"A library for people with options and results.","archived":false,"fork":false,"pushed_at":"2022-01-18T20:08:14.000Z","size":256,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-14T05:05:10.696Z","etag":null,"topics":["either","option","result"],"latest_commit_sha":null,"homepage":"","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/frectonz.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-13T11:45:26.000Z","updated_at":"2024-08-18T02:44:08.000Z","dependencies_parsed_at":"2022-08-25T22:40:51.890Z","dependency_job_id":null,"html_url":"https://github.com/frectonz/optionem","commit_stats":null,"previous_names":["fraol0912/optionem"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frectonz%2Foptionem","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frectonz%2Foptionem/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frectonz%2Foptionem/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frectonz%2Foptionem/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/frectonz","download_url":"https://codeload.github.com/frectonz/optionem/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241705915,"owners_count":20006396,"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","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":["either","option","result"],"created_at":"2024-11-14T10:28:57.373Z","updated_at":"2026-05-07T20:48:51.586Z","avatar_url":"https://github.com/frectonz.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Optionem\n\n![npm](https://img.shields.io/npm/v/optionem)\n![npm bundle size](https://img.shields.io/bundlephobia/min/optionem)\n![NPM](https://img.shields.io/npm/l/optionem)\n![npm](https://img.shields.io/npm/dt/optionem)\n\nA library for people with options and results.\n\n![Optionem](/optionem.png)\n\n## Install\n\n```sh\nnpm install optionem\nyarn add optionem\n```\n\n### Library Name\n\n**Optionem** = **Option in Latin**\n\n## Example\n\nUsing option\n\n```typescript\nimport { Option, None, Some } from \"optionem\";\n\nfunction divide(numerator: number, denominator: number): Option\u003cnumber\u003e {\n  if (denominator === 0) {\n    return new None();\n  } else {\n    return new Some(numerator / denominator);\n  }\n}\n\nconst result = divide(\n  Math.floor(Math.random() * 10),\n  Math.floor(Math.random() * 10)\n);\n\nresult.match({\n  Some(x) {\n    console.log(\"Result \", x);\n  },\n  None() {\n    console.log(\"Can not divide by\", 0);\n  },\n});\n```\n\nUsing result\n\n```typescript\nimport { Result, Err, Ok } from \"optionem\";\n\nfunction divide(\n  numerator: number,\n  denominator: number\n): Result\u003cnumber, string\u003e {\n  if (denominator === 0) {\n    return new Err(\"divide by zero error\");\n  } else {\n    return new Ok(numerator / denominator);\n  }\n}\n\nconst result = divide(\n  Math.floor(Math.random() * 10),\n  Math.floor(Math.random() * 10)\n);\n\nresult.match({\n  Ok(x) {\n    console.log(\"Result \", x);\n  },\n  Err(err) {\n    console.log(\"ERROR\", err);\n  },\n});\n```\n\nThe api of this library is made to resemble the one in rust.\n\nThis library can be used for\n\n- Network Requests\n- Database Gateways\n- etc\n\nThis can be used in places where in normal circumstances you would use `null` or `undefined`. Null is bad enough but in javascript we also have `undefined`. It is time to eliminate `null` and `undefined` checks from your codebase.\n\n## Option\n\nAn option has two variants that implement the `Option\u003cT\u003e` interface\n\n- Some\n- None\n\n## Result\n\nA result has two variants that implement the `Result\u003cT, E\u003e` interface\n\n- Ok\n- Err\n\n## API\n\n[Check out the API](/docs)\n\n## License\n\nThis project is licensed under the [MIT](/LICENSE) license.\n\n## Todo\n\n- [x] Implement Option\n- [ ] Support async functions in methods of option\n- [x] Implement Result\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffrectonz%2Foptionem","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffrectonz%2Foptionem","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffrectonz%2Foptionem/lists"}