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

zresult

v1.0.0

Published

Wrap errors into results with that simple library.

Readme

zresult

It helps to know the error you'll get.

GitHub license

zresult is an ultra-lightweight TypeScript wrapper designed to transform error handling into a predictable, strictly typed, and elegant data flow. Inspired by the Result pattern from Rust and Go, it integrates natively with yerror to provide absolute Type Safety for your error codes.

Key Features

  • No more noisy try/catch: Handle errors as return values.
  • Exhaustive Type Safety: Your error codes and debug data are validated via the yerror's YErrorRegistry type.
  • Explicit Flow: Clear distinction between synchronous and asynchronous operations.
  • Selective Catching: Capture only the errors you know how to handle, let the others bubble up (e.g., unexpected bugs or ReferenceError).

Installation

npm install zresult yerror

Quick Start

1. Creating Success or Failure

import { ok, fail } from 'zresult';

const success = ok(42);
// returns { ok: true, value: 42 }

const failure = fail('E_USER_NOT_FOUND', ['123']);
// returns { ok: false, error: YError }

2. Executing a Function (Attempt)

Use attempt for asynchronous functions and attemptSync for the synchronous world.

import { attempt, attemptSync } from 'zresult';

// Asynchronous
const result = await attempt(fetchUser, userId);

if (!result.ok) {
  console.error(result.error.code); // Strictly typed!
  return;
}
console.log(result.value.name);

// Synchronous
const config = attemptSync(parseConfig, rawData);

3. Selective Capture (The "From" Pattern)

Only handle expected errors and let unexpected bugs crash the process cleanly.

import { attemptFrom } from 'zresult';

// We only capture 'E_NETWORK' errors
const result = await attemptFrom(['E_NETWORK'], sendMessage, msg);

if (!result.ok) {
  // result.error is strictly typed as YError<'E_NETWORK'> here
  return retry(msg);
}

4. Stabilizing an existing Promise (Settle)

Useful for transforming a Promise from a third-party library into a Result.

import { settle } from 'zresult';

const result = await settle(externalApi.call());

Integration with YError

zresult shines when used with a declared YErrorRegistry. TypeScript will prevent you from using non-existent error codes or invalid debug arguments.

declare module 'yerror' {
  interface YErrorRegistry {
    E_ACCESS_DENIED: [userId: string];
  }
}

// TypeScript validates both 'E_ACCESS_DENIED' and the debug array contents
return fail('E_ACCESS_DENIED', ['user_123']);

API

Functions

ok()

Create a successful result

Kind: global function

fail()

Create a failure result using a YError code and debug values

Kind: global function

failWith()

Wrap an existing error into a failure result

Kind: global function

settle()

Transform a Promise into a Result catching any error

Kind: global function

settleFrom()

Transform a Promise into a Result catching only known errors and letting unknown pass through

Kind: global function

attempt()

Runs an asynchronous function and provides a Result catching any error

Kind: global function

attemptFrom()

Runs an asynchronous function and provides a Result catching only known errors and letting unknown pass through

Kind: global function

attemptSync()

Runs a synchronous function and provides a Result catching any error

Kind: global function

attemptSyncFrom()

Runs a synchronous function and provides a Result catching only known errors and letting unknown pass through

Kind: global function

Authors

License

MIT