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

@punpun-dev/ts-result

v0.1.4

Published

A tiny TypeScript Result type for explicit success and failure values

Readme

ts-result

A tiny TypeScript Result type for explicit success and failure values.

Installation

npm install @punpun-dev/ts-result
# or
pnpm add @punpun-dev/ts-result
# or
yarn add @punpun-dev/ts-result

Usage

import { Result } from "@punpun-dev/ts-result";

type AppError =
  | { kind: "not_found"; resource: string }
  | { kind: "validation"; message: string };

function findUser(id: string): Result<User, AppError> {
  const user = db.users.find(id);

  if (!user) {
    return Result.failure({ kind: "not_found", resource: "user" });
  }

  return Result.success(user);
}

const userName = findUser("42")
  .mapValue((user) => user.name)
  .unwrapOr("Anonymous");

Option Interop

@punpun-dev/ts-result depends on @punpun-dev/ts-option for fromOption() and toOption().

import { Option } from "@punpun-dev/ts-option";
import { Result } from "@punpun-dev/ts-result";

const maybeUser = Option.fromNullable(cache.get("user:42"));
const userResult = Result.fromOption(maybeUser, "Missing cached user");
const backToOption = userResult.toOption();

API

Static Methods

| Method | Description | | --- | --- | | Result.success<T>(value: T): Result<T, never> | Create a successful result | | Result.failure<E>(error: E): Result<never, E> | Create a failed result | | Result.handle<T>(fn: () => T \| Promise<T>): Promise<Result<T, unknown>> | Capture thrown or rejected errors | | Result.fromNullable<T, E>(value, error): Result<T, E> | Convert null or undefined into a failure | | Result.fromOption<T, E>(option, error): Result<T, E> | Convert an Option into a Result | | Result.all<T, E>(results): Result<T[], E> | Combine many results, returning the first failure |

Instance Methods

| Method | Description | | --- | --- | | isSuccess(): this is Success<T> | Narrow to Success | | isFailure(): this is Failure<E> | Narrow to Failure | | mapValue<U>(fn): Result<U, E> | Transform the success value | | flatMapValue<U>(fn): Result<U, E> | Chain a result-returning function | | tapValue(fn): Result<T, E> | Run a side effect for Success | | mapError<F>(fn): Result<T, F> | Transform the failure error | | flatMapError<F>(fn): Result<T, F> | Recover or remap with a result-returning function | | tapError(fn): Result<T, E> | Run a side effect for Failure | | match<U>(cases): U | Handle both success and failure branches | | unwrapOrThrow(): T | Return the value or throw if failed | | unwrapOr(fallback: T): T | Return the value or fallback | | unwrapOrElse(fallbackFn: () => T): T | Return the value or computed fallback | | toOption(): Option<T> | Convert success to Some and failure to None | | toNullable(): T \| null | Convert success to value and failure to null |

Success and Failure

Success<T> and Failure<E> are the concrete result classes. Most code should create them through Result.success() and Result.failure().

  • Success<T> exposes value: T
  • Failure<E> exposes error: E

License

MIT