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

@zemnmez/result

v1.0.4

Published

A tiny, purely functional TypeScript implementation of Rust's Result type

Readme

@zemnmez/result

View @zemnmez/result on npm

@zemnmez/result is a TypeScript implementation of Rust's Result<T, E> type. A Result represents, exactly and in a type-safe manner, the result of a sequence of any number of operations that may potentially fail.

The benefit is that every possible failure remains explicit in the return type, even across long chains of operations. The tradeoff is that a Result must be handled explicitly before its successful value can be used.

In React, this can effectively eliminate early returns from components that would otherwise violate the Rules of Hooks. A function that may fail can return a Result, while the component calls every hook unconditionally and uses unwrap_or_else to select its success or failure UI:

import {
	and_then,
	Err,
	Ok,
	type Result,
	unwrap_or_else,
} from '@zemnmez/result';

type Vector3 = readonly [x: number, y: number, z: number];

export function normalize([x, y, z]: Vector3): Result<Vector3, Error> {
	const length = Math.hypot(x, y, z);
	if (length === 0) {
		return Err(new Error('Cannot normalize a zero-length vector.'));
	}

	return Ok([x / length, y / length, z / length]);
}

declare function useTheme(): { error: string; vector: string };

export function UnitVector({ vector }: { vector: Vector3 }) {
	const theme = useTheme();

	return unwrap_or_else(
		and_then(normalize(vector), vector => (
			<output className={theme.vector}>
				{vector.map(value => value.toFixed(2)).join(', ')}
			</output>
		)),
		error => <p className={theme.error}>{error.message}</p>
	);
}

Implementation

Result is implemented purely functionally. Advanced JavaScript and TypeScript compilers can therefore erase or inline its inner functionality. With a minifier, no class names, constructor names, property names, discriminant strings, or symbols identifying Ok or Err need to occupy space in the resulting bundle.

The representation is intentionally opaque. Inspect a result with is_ok, is_err, unwrap, unwrap_err, or the provided combinators rather than runtime properties.

Usage

and_then maps the successful value. and_then_flatten chains an operation that can itself fail. Curried map_result and bind_result work well in pipelines:

import { bind_result, Err, Ok, unwrap } from '@zemnmez/result';

export const doubled = bind_result((value: number) =>
	value >= 0 ? Ok(value * 2) : Err('negative')
);

export const result = doubled(Ok(21));
export const answer = unwrap(result); // 42

pipe_result chains several Result-returning functions from left to right and stops at the first Err.