{"id":16548155,"url":"https://github.com/dgraham/option-type","last_synced_at":"2025-10-28T16:31:56.997Z","repository":{"id":57315894,"uuid":"99758962","full_name":"dgraham/option-type","owner":"dgraham","description":"An Option type for Flow, inspired by Rust.","archived":false,"fork":false,"pushed_at":"2020-08-31T01:30:50.000Z","size":159,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-01T16:47:43.430Z","etag":null,"topics":["maybe","optionals","result-type"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/dgraham.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":"2017-08-09T02:58:35.000Z","updated_at":"2022-08-11T06:26:21.000Z","dependencies_parsed_at":"2022-08-25T22:40:51.974Z","dependency_job_id":null,"html_url":"https://github.com/dgraham/option-type","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dgraham%2Foption-type","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dgraham%2Foption-type/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dgraham%2Foption-type/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dgraham%2Foption-type/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dgraham","download_url":"https://codeload.github.com/dgraham/option-type/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238681504,"owners_count":19512792,"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":["maybe","optionals","result-type"],"created_at":"2024-10-11T19:25:10.379Z","updated_at":"2025-10-28T16:31:56.608Z","avatar_url":"https://github.com/dgraham.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Option type\n\nAn [Option][] type for [Flow][], inspired by [Rust][].\n\n[Option]: https://en.wikipedia.org/wiki/Option_type\n[Flow]: https://flow.org\n[Rust]: https://doc.rust-lang.org/std/option/index.html\n\n## Usage\n\n```js\nimport {type Option, Some, None} from 'option-type';\n\nfunction divide(numerator: number, denominator: number): Option\u003cnumber\u003e {\n  if (denominator === 0) {\n    return None;\n  } else {\n    return Some(numerator / denominator);\n  }\n}\n\nconst result = divide(2, 3);\nconst message = result.match({\n  Some: x =\u003e `Result: ${x}`,\n  None: () =\u003e 'Cannot divide by zero'\n});\nconsole.log(message);\n```\n\n## Result\n\nA [`Result`][result] type is also included in this package because it's so\nclosely related to `Option`.\n\n```js\n\nimport {type Result, Ok, Err} from 'option-type';\n\nfunction parse(json: string): Result\u003cObject, Error\u003e {\n  try {\n    return Ok(JSON.parse(json));\n  } catch (e) {\n    return Err(e);\n  }\n}\n\nconst result = parse('{\"name\": \"hubot\"}');\nconst message = result.match({\n  Ok: x =\u003e `Result: ${x.name}`,\n  Err: e =\u003e `Failed to parse JSON text: ${e}`\n});\nconsole.log(message);\n```\n\n[result]: https://doc.rust-lang.org/std/result/enum.Result.html\n\n## Development\n\n```\nnpm install\nnpm test\n```\n\n## License\n\nDistributed under the MIT license. See LICENSE for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdgraham%2Foption-type","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdgraham%2Foption-type","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdgraham%2Foption-type/lists"}