Skip to content

Latest commit

 

History

History
37 lines (31 loc) · 811 Bytes

README.md

File metadata and controls

37 lines (31 loc) · 811 Bytes

errd

Collection of error handling utilities for JavaScript and TypeScript.

Usage

import { Ok /* Err, type Result */ } from "errd/result";
const result = Ok(42);
if (result.isOk()) console.log(result.unwrap());
else console.error(result.unwrapErr());
import { Some /* None, type Option */ } from "errd/option";
const maybe = Some(1);
if (maybe.isSome()) console.log(result.unwrap());
else console.log("none");
import { Try } from "errd/try";
const [err, result] = Try.from(() => 42);
const [err2, result2] = Try.fromAsync(() => fetch("https://..."));
import {
  normalizeError /* isError, isErrnoException, isErrorLike, */,
} from "errd/util";
try {
  throw new Error("oops");
} catch (error) {
  normalized = normalizeError(error);
  console.error(error);
}