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

@philiprehberger/result-chain

v0.1.4

Published

Chainable Result monad for error handling without exceptions

Readme

@philiprehberger/result-chain

CI npm version License

Chainable Result monad for error handling without exceptions

Installation

npm install @philiprehberger/result-chain

Usage

import { ok, err, Result } from '@philiprehberger/result-chain';

// Create results
const success = ok(42);
const failure = err('something went wrong');

// Chain operations
const result = ok(10)
  .map((v) => v * 2)
  .flatMap((v) => (v > 15 ? ok(v) : err('too small')))
  .mapErr((e) => `Error: ${e}`);

// Extract values
const value = result.unwrapOr(0);

// Pattern match
const message = result.match({
  ok: (v) => `Got ${v}`,
  err: (e) => `Failed: ${e}`,
});

// Wrap throwable functions
const parsed = Result.fromThrowable(() => JSON.parse(rawInput));

// Wrap promises
const fetched = await Result.fromPromise(fetch('/api/data'));

// Combine results
const all = Result.all([ok(1), ok(2), ok(3)]); // Ok([1, 2, 3])
const settled = Result.allSettled([ok(1), err('x')]); // Ok({ ok: [1], err: ['x'] })

API

Factories

  • ok<T, E>(value: T): Result<T, E> - Creates an Ok result containing the given value.
  • err<E, T>(error: E): Result<T, E> - Creates an Err result containing the given error.

Instance Methods

  • .isOk(): boolean - Returns true if the result is Ok.
  • .isErr(): boolean - Returns true if the result is Err.
  • .map<U>(fn: (value: T) => U): Result<U, E> - Transforms the Ok value, leaving Err untouched.
  • .mapErr<F>(fn: (error: E) => F): Result<T, F> - Transforms the Err value, leaving Ok untouched.
  • .flatMap<U, F>(fn: (value: T) => Result<U, F>): Result<U, E | F> - Chains a function that returns a Result.
  • .unwrap(): T - Returns the Ok value or throws if Err.
  • .unwrapOr(defaultValue: T): T - Returns the Ok value or the provided default.
  • .unwrapOrElse(fn: (error: E) => T): T - Returns the Ok value or computes a default from the error.
  • .match<U>(handlers: { ok, err }): U - Pattern matches on the result, calling the appropriate handler.

Static Methods

  • Result.fromPromise<T, E>(promise: Promise<T>): Promise<Result<T, E>> - Wraps a promise, catching rejections as Err.
  • Result.fromThrowable<T, E>(fn: () => T): Result<T, E> - Wraps a function that may throw into a Result.
  • Result.all<T, E>(results: Result<T, E>[]): Result<T[], E> - Returns Ok with all values if every result is Ok, otherwise the first Err.
  • Result.allSettled<T, E>(results: Result<T, E>[]): Result<{ ok: T[]; err: E[] }, never> - Collects all results, separating Ok values and Err errors.

Development

npm install
npm run build
npm run typecheck
npm test

License

MIT