npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

evercatch

v0.11.0

Published

No more uncaught errors

Readme

Evercatch

Version Downloads Minzipped size

No more uncaught errors!

Evercatch is a tiny, dependency-free TypeScript library that turns thrown errors into values. Errors become part of a function's return type, so the compiler tells you where they are and refuses to let you read a value you haven't checked for yet.

npm install evercatch
# or
yarn add evercatch
# or
pnpm add evercatch

The result tuple

Everything is built on one type: a readonly tuple of [error, value].

type Result<T, E> = readonly [null, T] | readonly [E, null];

Destructure it, check the error, and TypeScript narrows the value for you:

import { err, ok, type Result } from "evercatch";

function divide(a: number, b: number): Result<number, Error> {
  if (b === 0) {
    return err(new Error("Division by zero"));
  }
  return ok(a / b);
}

const [error, value] = divide(10, 2);

if (error) {
  console.error(error.message);
} else {
  console.log(value); // number — narrowed, not number | null
}

null in the error slot means "this result is ok", so an error can never be nullish. Every error type in the library is constrained to reject null and undefined at compile time.

Catching what throws

Wrap a call that might throw and get a result back instead.

import { fromPromise, resultFrom } from "evercatch";

const [parseError, config] = resultFrom(() => JSON.parse(raw));

const [fetchError, response] = await fromPromise(
  fetch("https://api.example.com/data"),
);

Or wrap the function once and reuse the safe version:

import { fromAsyncThrowable, fromThrowable } from "evercatch";

const safeParse = fromThrowable(JSON.parse);
const safeFetch = fromAsyncThrowable(fetch);

const [error, data] = safeParse(raw);
const [fetchError, response] = await safeFetch("https://api.example.com/data");

Anything thrown that isn't an Error is wrapped in one, with the original value kept as cause.

Custom error types

Every catching function takes an optional mapErr to turn the caught value into an error type of your choosing — a string union, a tagged object, your own error class. Whatever you return becomes the error type of the result.

import { fromPromise } from "evercatch";

type FetchError = "NETWORK_ERROR" | "TIMEOUT";

const [error, response] = await fromPromise(
  fetch("https://api.example.com/data"),
  (e): FetchError => (e instanceof DOMException ? "TIMEOUT" : "NETWORK_ERROR"),
);

if (error === "TIMEOUT") {
  // ...
}

Unwrapping

When you'd rather not handle the error at the call site, unwrap the result with a fallback — or throw after all.

import { unwrapOr, unwrapOrElse, unwrapOrThrow } from "evercatch";

unwrapOr(divide(10, 0), 0); // 0
unwrapOrElse(divide(10, 0), (error) => error.message.length); // computed
unwrapOrThrow(divide(10, 0)); // throws the error

The async variants take a Promise of a result and return a promise: unwrapAsyncOr, unwrapAsyncOrElse and unwrapAsyncOrThrow.

Composing

Results compose by returning early. Errors travel upward as values, so a function that can fail has a signature that says so.

import { err, fromPromise, ok, type ResultAsync } from "evercatch";
import { auth } from "./auth";

async function fetchUserData(): ResultAsync<UserData, Error> {
  const [authError, user] = await fromPromise(auth());
  if (authError) {
    return err(authError);
  }

  const [fetchError, response] = await fromPromise(
    fetch(`https://api.example.com/user/${user.id}`),
  );
  if (fetchError) {
    return err(fetchError);
  }
  if (!response.ok) {
    return err(new Error("Failed to fetch user data"));
  }

  return await fromPromise(response.json());
}

Namespaces

The same functions are also grouped under the type they work with, which makes for shorter names at the call site. This is purely a matter of preference — the namespace members and the standalone exports are the same functions.

import { Result, ResultAsync, ResultAsyncFn, ResultFn } from "evercatch";

Result.ok(42);
Result.from(() => JSON.parse(raw));
Result.unwrapOr(someResult, 0);

await ResultAsync.from(fetch(url));

const safeParse = ResultFn.from(JSON.parse);
const safeFetch = ResultAsyncFn.from(fetch);

Note that Result, ResultAsync, ResultFn and ResultAsyncFn are each both a type and a value, so a single import gives you both.

Documentation

Full API reference: fransek.github.io/evercatch

License

MIT