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

antithrow

v3.0.0

Published

Rust-style Result types for type-safe error handling without exceptions

Readme

NPM Version NPM License GitHub Actions Workflow Status

Features

  • Explicit failures - return types show exactly which functions can fail and how.
  • Compiler-visible - success and failure are part of the type signature.
  • Type-safe errors - error types are known at compile time.
  • Sync + async support - compose fluid workflows with symmetrical methods.
  • Ergonomic chaining - use Result.do(...) + yield* for readable happy-path flow with early exits on failure.
  • Familiar API - based heavily on Rust's battle-tested std::result.

Installation

bun add antithrow

Usage

import { Err, Ok } from "antithrow";
import type { Result } from "antithrow";

type ConfigError =
  | { type: "missing-env"; key: string }
  | { type: "invalid-port"; value: string };

const readEnv = (key: string): Result<string, ConfigError> => {
  const value = process.env[key];
  return value
    ? new Ok(value)
    : new Err({ type: "missing-env", key });
};

const parsePort = (value: string): Result<number, ConfigError> => {
  const port = Number(value);
  return Number.isInteger(port) && port > 0 && port <= 65535
    ? new Ok(port)
    : new Err({ type: "invalid-port", value });
};

const port = readEnv("PORT").andThen(parsePort).unwrapOr(3000);

[!WARNING] antithrow preserves the Result<T, E> error kind. Because of that, it does not implicitly convert thrown values from callbacks or generator bodies into Err<E>.

  • Callbacks passed to methods like map, mapErr, andThen, and orElse can still throw/reject.
  • Result.do(...) generator bodies can still throw/reject.

If logic can throw, wrap it explicitly with Result.try(...) before feeding it into pipelines. Or use @antithrow/std which provides pre-wrapped versions of common globals.

const safeJsonParse = (input: string): Result<unknown, SyntaxError> =>
  Result.try(() => JSON.parse(input));

const result = new Ok('{"a":1}').andThen(safeJsonParse);

Getting Started

Transformations

import { Ok } from "antithrow";

const result = new Ok(2)
  .map((x) => x * 2)         // ok(4)
  .andThen((x) => new Ok(x + 1)) // ok(5)
  .unwrapOr(0);              // 5

Async Results

import { Ok, Result } from "antithrow";

// Wrap async throwing functions
const fetched = Result.try(async () => {
  const response = await fetch("/api/data");
  return response.json();
});

// `Pending` stays inside the same Result model
const result = Result.do(async function* () {
  const a = yield* new Ok(1);
  const b = yield* new Ok(2);
  return a + b;
});
// Pending<number, never>

Settle at the App Boundary

interface RequestError {
  status: number;
  message: string;
}

async function handler(request: Request): Promise<Response> {
  const result = await Result.do(async function* () {
    const { email, name } = yield* parseBody(request);
    const validEmail = yield* validateEmail(email);
    yield* checkEmailAvailable(validEmail);

    return yield* saveUser(validEmail, name);
  }).settle();

  return result.mapOrElse(
    ({ status, message }) => Response.json({ error: message }, { status }),
    (user) => Response.json(user, { status: 201 }),
  );
}

Static Constructors

Result.try(...)

Wraps synchronous throws and async rejections:

const parsed = Result.try<unknown, SyntaxError>(() => JSON.parse(input));
const loaded = Result.try(async () => {
  const response = await fetch("/api");
  return response.json();
});

Result.fromPromise(...)

Wraps an existing promise as Pending<T, E>:

const request = Result.fromPromise<Response, TypeError>(fetch("/api"));

Result.do(...)

Runs a sync or async generator in fail-fast mode with yield*:

const total = Result.do(function* () {
  const a = yield* new Ok(20);
  const b = yield* new Ok(22);
  return a + b;
});

Legacy API

If you want the older helper-based API with ok, err, chain, and ResultAsync, use the antithrow/legacy entrypoint. The modern root package is the v2 class-based API documented above.