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

@prosopo/result

v0.1.0

Published

Rust-style Result type for TypeScript and JavaScript: errors as typed values instead of exceptions

Readme

@prosopo/result

A Rust-style Result type for TypeScript and JavaScript. Errors become typed values that you return, instead of exceptions you throw and hope someone catches.

npm install @prosopo/result

ESM and CommonJS, no dependencies, Node 18+ and modern browsers.

Why

try/catch doesn't show up in a function's type. Nothing tells the caller that parseConfig() can fail, or how, and the error is always unknown in the catch block. A Result<T, E> puts both outcomes in the return type, so the compiler makes you handle them:

import { err, ok, type Result } from "@prosopo/result";

type ParseError = { kind: "empty" } | { kind: "nan"; input: string };

const parse = (input: string): Result<number, ParseError> => {
	if (input === "") return err({ kind: "empty" });
	const value = Number(input);
	return Number.isNaN(value) ? err({ kind: "nan", input }) : ok(value);
};

const result = parse(userInput);
if (result.ok) {
	result.value; // number
} else {
	result.error; // ParseError
}

API

Creating results

| Function | Returns | | --------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- | | ok(value) | Result<T, never> holding a value | | err(error) | Result<never, E> holding an error | | tryCatch(fn, mapError?) | Runs fn, returning Ok with its value or Err with what it threw. Pass mapError to turn the unknown throw into a typed error. | | tryCatchAsync(promiseOrFn, mapError?) | The same for a promise, or a function returning one. Resolves to a Result; never rejects. | | all(results) | Ok with every value, or the first Err |

Checking results

Every result has an ok property (true or false) that TypeScript narrows on. There are also type guards:

  • isOk(result) / isErr(result): standalone guards, handy with Array.prototype.filter.
  • result.isOk() / result.isErr(): the same, as methods.
const values = inputs
	.map(parse)
	.filter(isOk)
	.map((r) => r.value); // number[]

Methods

| Method | On Ok(value) | On Err(error) | | -------------------- | ------------------------ | ----------------------------- | | map(fn) | Ok(fn(value)) | unchanged | | mapErr(fn) | unchanged | Err(fn(error)) | | andThen(fn) | fn(value) (a Result) | unchanged | | orElse(fn) | unchanged | fn(error) (a Result) | | match({ ok, err }) | ok(value) | err(error) | | unwrap() | value | throws UnwrapError | | expect(message) | value | throws UnwrapError(message) | | unwrapOr(fallback) | value | fallback | | unwrapOrElse(fn) | value | fn(error) | | unwrapErr() | throws UnwrapError | error |

UnwrapError keeps the original error on both .error and .cause.

Development

pnpm install
pnpm run lint
pnpm run build:tsc
pnpm run test    # vitest, 100% coverage enforced
pnpm run build   # dist/esm and dist/cjs

Releases: bump version in package.json, merge, then publish a GitHub release tagged v<version>. .github/workflows/publish.yml publishes to npm with provenance.

Licence

Apache-2.0