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

resultr

v1.0.2

Published

Rust-inspired error handling with the `Result` type, implemented in typescript.

Readme

resultr - Better error handling

Rust-inspired error handling with the Result type, implemented in typescript.

try and catch really suck.

So this library aims to provide a nice and neat way to handle errors.

Problem

Very often in the javascript world, many that could throw an error and crash your program are used without the correct error handling, an example is JSON.parse:

const result = JSON.parse("{ "a": ");
// This will throw without any warning!

Solution

Use the Result type as a return value when you define your functions!

function couldFail(): Result<number, Error> {
  // This means that the return type is a result with either one set: value (number), or error.
  let r = Math.random();

  if (r < 0.5) {
    Err("This in an error!");
  } else {
    Ok(r);
  }
}

In the example above, return a failing result if r < 0.5, else return a successful result. It should be handled like this:

const r = couldFail();

// Use isOk() to check whether the value of the result exists

if (r.isOk()) {
  // Use unwrap() to get the inner value of the result
  // NOTE: this function throws if the result value doens't exist!
  let inner = r.unwrap();
}

// Or you can use isErr() to check whether the result has an error

if (r.isErr()) {
  // Use unwrapErr() to get the inner error
  // NOTE: this function throws if the error doesnt exist!
  let error = r.unwrapErr();
}

But JSON.parse doesn't return a Result!

To handle the case where a function can throw but it is not specified, like fetch or JSON.parse, you can use the resultr function to wrap a call to these problematic functions.

const value = resultr(() => JSON.parse(...));
// type of `value` is Result<any, Error>

This way if the callback function throws, the resultr function will catch the error for you, without the need to write the atrocious try-catch blocks.

You can use the resultr function to handle async functions too:

const res = resultr(() => fetch("..."));
// type of `res` is Promise<Result<Response, Error>>
// So to get the inner result just:
const res = await resultr(() => fetch("..."));

License

MIT License 2025 (c) Saverio Scagnoli