Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: about 1 month 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 2 years ago)
- Default Branch: main
- Last Pushed: 2023-07-07T07:29:34.000Z (over 1 year ago)
- Last Synced: 2024-11-14T14:52:24.926Z (about 2 months 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: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# result
[![deno land](http://img.shields.io/badge/available%20on-deno.land/x-lightgrey.svg?logo=deno)](https://deno.land/x/result_js)
[![deno doc](https://doc.deno.land/badge.svg)](https://deno.land/x/result_js?doc)
[![GitHub release (latest by date)](https://img.shields.io/github/v/release/TomokiMiyauci/result)](https://github.com/TomokiMiyauci/result/releases)
[![codecov](https://codecov.io/github/TomokiMiyauci/result/branch/main/graph/badge.svg)](https://codecov.io/github/TomokiMiyauci/result)
[![GitHub](https://img.shields.io/github/license/TomokiMiyauci/result)](LICENSE)[![test](https://github.com/TomokiMiyauci/result/actions/workflows/test.yaml/badge.svg)](https://github.com/TomokiMiyauci/result/actions/workflows/test.yaml)
[![NPM](https://nodei.co/npm/@miyauci/result.png?mini=true)](https://nodei.co/npm/@miyauci/result/)
[![standard-readme compliant](https://img.shields.io/badge/readme%20style-standard-brightgreen.svg)](https://github.com/RichardLitt/standard-readme)
[![semantic-release: angular](https://img.shields.io/badge/semantic--release-angular-e10079?logo=semantic-release)](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