mayfail
v1.1.2
Published
A tiny, dependency-free Result tuple helper for synchronous and asynchronous functions
Maintainers
Readme
mayfail
Tiny, dependency-free error handling for synchronous and asynchronous JavaScript and TypeScript functions.
Install
npm install mayfailHow it works
Synchronous callbacks return a tuple immediately:
import { mayfail } from "mayfail";
const [value, error] = mayfail(() => JSON.parse(input));Async callbacks return a promise of the same tuple:
const [user, error] = await mayfail(() => fetch("/api/me").then((response) => response.json()));Success returns [value, null]; thrown errors and rejected promises return [null, error]. Unknown thrown values are normalized to Error instances.
See the documentation site for the full API.
License
MIT
