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

@davemanufor/resultify

v1.0.3

Published

A lightweight, type-safe Result type for functional error handling in TypeScript. Provides Ok and Err variants for clear, expressive success and failure management in your code.

Readme


Table of Contents


Features

  • Type-safe: Enforces explicit handling of success and error cases.
  • Functional: Inspired by Rust and FP paradigms, with Ok and Err variants.
  • Lightweight: Zero dependencies, minimal footprint.
  • Expressive: Clear API for mapping, unwrapping, and error propagation.
  • Custom Error Types: Supports custom error classes for richer error handling.

Installation

npm install @davemanufor/resultify
# or
yarn add @davemanufor/resultify

Usage

Import the factory and types:

import { Result, Ok, Err } from "resultify";

// Create an Ok result
const ok = Result.ok(42);

// Create an Err result
const err = Result.err(new Error("Something went wrong"));

// Type narrowing
if (ok.isOk()) {
  console.log("Success:", ok.unwrap());
}
if (err.isError()) {
  console.error("Error:", err.unwrapError());
}

API Reference

Types

  • Result<T, E extends Error = Error>: Union type of Ok<T, E> and Err<T, E>
  • Ok<T, E>: Represents a successful result
  • Err<T, E>: Represents an error result

Factory

  • Result.ok<T, E>(value: T): Ok<T, E>
  • Result.err<T, E>(error: E): Err<T, E>

Methods

Common

  • isOk(): boolean — Returns true if result is Ok
  • isError(): boolean — Returns true if result is Err

Ok

  • unwrap(): T — Returns the value
  • unwrapError(): never — Throws if called on Ok
  • throwError(): void — No-op for Ok
  • map<U>(fn: (value: T) => U): Ok<U, E> — Maps value

Err

  • unwrap(): never — Throws if called on Err
  • unwrapError(): E — Returns the error
  • throwError(): void — Throws the error
  • map<U>(fn: (value: T) => U): Err<U, E> — Passes error through

Type Safety

You can use custom error types for richer error handling:

class MyError extends Error {}
const result: Result<string, MyError> = Result.err(new MyError("fail"));
if (result.isError()) {
  result.throwError(); // Throws MyError
}

Examples

Basic Usage

function parseNumber(str: string): Result<number, Error> {
  const n = Number(str);
  if (isNaN(n)) return Result.err(new Error("Not a number"));
  return Result.ok(n);
}

const res = parseNumber("123");
if (res.isOk()) {
  console.log("Parsed:", res.unwrap());
} else {
  console.error("Parse error:", res.unwrapError().message);
}

Mapping Values

const ok = Result.ok(2);
const mapped = ok.map((x) => x * 5); // Ok(10)

const err = Result.err<number>(new Error("fail"));
const mappedErr = err.map((x) => x * 2); // Err("fail")

Error Propagation

function mightFail(flag: boolean): Result<string, Error> {
  if (flag) return Result.ok("success");
  return Result.err(new Error("fail"));
}

const result = mightFail(false);
result.throwError(); // Throws Error("fail") if Err

Contributing

Contributions, issues, and feature requests are welcome! Feel free to check issues and submit PRs.


License

MIT © David Manufor