https://github.com/tomokimiyauci/result
Minimum result type port of Rust
https://github.com/tomokimiyauci/result
container err error match ok result rust
Last synced: 12 months ago
JSON representation
Minimum result type port of Rust
- Host: GitHub
- URL: https://github.com/tomokimiyauci/result
- Owner: TomokiMiyauci
- License: mit
- Created: 2022-09-29T13:01:12.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-07-07T07:29:34.000Z (over 2 years ago)
- Last Synced: 2025-03-10T14:58:28.921Z (about 1 year ago)
- Topics: container, err, error, match, ok, result, rust
- Language: TypeScript
- Homepage: https://deno.land/x/result_js
- Size: 58.6 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# result
[](https://deno.land/x/result_js)
[](https://deno.land/x/result_js?doc)
[](https://github.com/TomokiMiyauci/result/releases)
[](https://codecov.io/github/TomokiMiyauci/result)
[](LICENSE)
[](https://github.com/TomokiMiyauci/result/actions/workflows/test.yaml)
[](https://nodei.co/npm/@miyauci/result/)
[](https://github.com/RichardLitt/standard-readme)
[](https://github.com/semantic-release/semantic-release)
Minimum result type port of Rust.
[Option](https://github.com/TomokiMiyauci/option) version.
## Table of Contents
- [Install](#install)
- [Usage](#usage)
- [API](#api)
- [Acknowledgements](#acknowledgements)
- [Contributing](#contributing)
- [License](#license)
## Install
deno.land:
```ts
import * as mod from "https://deno.land/x/result_js/mod.ts";
```
npm:
```bash
npm i @miyauci/result
```
## Usage
Type [Result](https://deno.land/x/result_js/mod.ts?s=Result) represents an
success or failure.
```ts
import {
Err,
Ok,
type Result,
unwrap,
} from "https://deno.land/x/result_js/mod.ts";
import { assertThrows } from "https://deno.land/std/testing/asserts.ts";
function divide(
numerator: number,
denominator: number,
): Result {
if (!denominator) return Err("divide by 0");
return Ok(numerator / denominator);
}
const opt = divide(100, 0);
assertThrows(() => unwrap(opt));
```
All [operators](https://deno.land/x/result_js/mod.ts#Functions) for
[Result](https://deno.land/x/result_js/mod.ts?s=Result) are separated from
prototype.
## API
All APIs can be found in the [deno doc](https://deno.land/x/result_js?doc).
## Acknowledgements
- [Rust std::result](https://doc.rust-lang.org/std/result/index.html)
## Contributing
See [contribution](CONTRIBUTING.md).
## License
[MIT](LICENSE) © 2023 Tomoki Miyauchi