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/future

v1.0.5

Published

A tiny, purely functional TypeScript type for values that may be loading, resolved, or errored

Readme

@zemnmez/future

View @zemnmez/future on npm

@zemnmez/future is a tiny TypeScript type for a value that may be loading, resolved, or errored. A Future<Then, Loading, Error> represents all three states exactly and requires each state to be handled before its resolved value can be used.

Like @zemnmez/result, Future is implemented purely functionally. Advanced JavaScript and TypeScript compilers can inline its implementation, so no class names, property names, discriminants, or symbols identifying a Future need to remain in a minified bundle.

React Query

useQueryFuture converts a React Query result into a Future. This is useful when a component should call all of its hooks unconditionally and select its loading, error, or resolved UI only after those hooks have run:

import { useQuery } from '@tanstack/react-query';
import { future, useQueryFuture } from '@zemnmez/future';

interface Todo {
	id: number;
	title: string;
}

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

export function TodoList() {
	const theme = useTheme();
	const todos = useQueryFuture(
		useQuery<Todo[], Error>({
			queryKey: ['todos'],
			queryFn: async () => {
				const response = await fetch('/api/todos');
				if (!response.ok) throw new Error('Could not load todos.');
				return response.json() as Promise<Todo[]>;
			},
		})
	);

	return future(
		todos,
		todos => (
			<ul className={theme.todoList}>
				{todos.map(todo => (
					<li key={todo.id}>{todo.title}</li>
				))}
			</ul>
		),
		() => <p>Loading todos…</p>,
		error => <p className={theme.error}>{error.message}</p>
	);
}

Usage

Construct a Future with resolve, loading, or error, then handle its three possible states with future:

import { type Future, future, resolve } from '@zemnmez/future';

export const answer: Future<number, number, Error> = resolve(42);
export const message = future(
	answer,
	value => `The answer is ${value}.`,
	progress => `Loading: ${progress}%`,
	error => `Failed: ${error.message}`
);

future_and_then maps a resolved value while preserving the loading and error types. Combine future_and_then with future_flatten_then to chain an operation that returns another Future, and future_collect combines several Futures into one.

Pipelines

future_and_then and future_flatten_then compose Future-returning operations into a pipeline. Each operation receives the preceding resolved value, while a loading or error state stops the pipeline. The resulting Future includes the loading and error types from every operation:

import {
	error,
	type Future,
	future_and_then,
	future_flatten_then,
	resolve,
} from '@zemnmez/future';

interface User {
	id: number;
	name: string;
}

export const findUser = (
	id: number
): Future<User, 'fetching user', 'user not found'> =>
	id === 42
		? resolve({ id, name: 'Deep Thought' })
		: error('user not found');

export const displayName = (
	user: User
): Future<string, 'formatting name', 'missing name'> =>
	user.name ? resolve(user.name) : error('missing name');

const user = future_flatten_then(future_and_then(resolve(42), findUser));
export const name = future_flatten_then(future_and_then(user, displayName));