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

rerust

v0.1.1

Published

Zero-dependency, Rust-inspired error handling for TypeScript

Readme

ReRust 🦀

npm version Bundle Size License: MIT TypeScript No Dependencies JSR Registry

Zero-dependency, type-safe error handling inspired by Rust's Result type. Say goodbye to try-catch blocks and hello to elegant error handling!

Features

  • 🚀 Zero Dependencies - Lightweight and blazing fast
  • 💪 Type Safe - Full TypeScript support with type inference
  • 🌐 Universal - Works in Node.js, Bun, Deno, and browsers
  • 🎯 Tree Shakeable - Only import what you need
  • 📦 Tiny - Less than 300 bytes minified + gzipped

Installation

# npm
npm install rerust

# yarn
yarn add rerust

# pnpm
pnpm add rerust

# JSR registry
npx jsr add @jimfilippou/rerust

Sponsors

Why ReRust?

Traditional error handling in JavaScript/TypeScript often leads to verbose and nested try-catch blocks. ReRust provides a more elegant way to handle errors, inspired by Rust's Result type.

Before ReRust

async function getUserData(userId: string) {
  try {
    const response = await fetch(`/api/users/${userId}`);
    if (!response.ok) {
      throw new Error("Failed to fetch user");
    }
    const data = await response.json();
    try {
      validateUserData(data);
      return data;
    } catch (validationError) {
      console.error("Validation failed:", validationError);
      throw validationError;
    }
  } catch (error) {
    console.error("Error fetching user:", error);
    return null;
  }
}

// Usage
async function handleUserProfile() {
  try {
    const userData = await getUserData("123");
    if (userData === null) {
      showError("Failed to load user");
      return;
    }
    updateUI(userData);
  } catch (error) {
    showError("Something went wrong");
  }
}

After ReRust

import { ok, err, isOk, isErr, type Result } from "rerust";

async function getUserData(userId: string): Promise<Result<UserData>> {
  const response = await fetch(`/api/users/${userId}`)
    .then((res) => (res.ok ? ok(res) : err("Failed to fetch user")))
    .catch(() => err("Network error"));

  if (isErr(response)) return response;

  const data = await response.value.json();
  const validationResult = validateUserData(data);

  return isOk(validationResult) ? ok(data) : err("Invalid user data");
}

// Usage
async function handleUserProfile() {
  const res = await getUserData("123");
  if (isErr(res)) return showError(result.value); // Type-safe error message
  updateUI(result.value);
}

Advanced Usage

Chaining Results

import { ok, err, isOk, type Result } from "rerust";

type User = { id: string; name: string };
type Order = { id: string; items: string[] };

function findUser(id: string): Result<User> {
  // Simulate database lookup
  return id === "1" ? ok({ id: "1", name: "John" }) : err("User not found");
}

function getUserOrders(user: User): Result<Order[]> {
  // Simulate order lookup
  return ok([{ id: "order1", items: ["item1", "item2"] }]);
}

// Chain operations
function getUserWithOrders(
  userId: string
): Result<{ user: User; orders: Order[] }> {
  const userResult = findUser(userId);
  if (isErr(userResult)) return userResult;

  const ordersResult = getUserOrders(userResult.value);
  if (isErr(ordersResult)) return ordersResult;

  return ok({
    user: userResult.value,
    orders: ordersResult.value,
  });
}

Type Guards

const result = ok({ name: "John", age: 30 });

// TypeScript knows `user` has `name` and `age` properties
if (isOk(result)) {
  const user = result.value;
  console.log(user.name); // TypeScript autocompletion works!
}

// TypeScript knows `error` is a string
if (isErr(result)) {
  const error = result.value;
  console.error(error.toUpperCase()); // TypeScript knows this is a string
}

API Reference

Types

type Result<T, E = string> =
  | { success: true; value: T } // Ok variant
  | { success: false; value: E }; // Err variant

Functions

  • ok<T>(value: T): Result<T> - Creates a successful result
  • err<E>(value: E): Result<never, E> - Creates an error result
  • isOk<T, E>(result: Result<T, E>): boolean - Type guard for successful results
  • isErr<T, E>(result: Result<T, E>): boolean - Type guard for error results

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.