Attributes
Includes Deno configuration
Repository
Current version released
a year ago
result
Minimum result type port of Rust.
Option version.
Table of Contents
Install
deno.land:
import * as mod from "https://deno.land/x/result_js/mod.ts";
npm:
npm i @miyauci/result
Usage
Type Result represents an success or failure.
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<number, string> {
if (!denominator) return Err("divide by 0");
return Ok(numerator / denominator);
}
const opt = divide(100, 0);
assertThrows(() => unwrap(opt));
All operators for Result are separated from prototype.
API
All APIs can be found in the deno doc.
Acknowledgements
Contributing
See contribution.
License
MIT © 2023 Tomoki Miyauchi