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

galvorn

v1.0.5

Published

Rust's Option and Result for TypeScript. Fully typed, tested, zero dependencies.

Readme

galvorn

Rust's Option and Result for TypeScript. Fully typed, tested, zero dependencies.

NPM Version CI Bundle size NPM Downloads TypeScript License Zero Dependencies

Install

pnpm add galvorn  # or npm i galvorn

Quick Start

import { Some, None, Ok, Fail, match } from 'galvorn';

const user = Some('Alice');
const greeting = user.map((n) => `Hello, ${n}`).unwrapOr('Hello, stranger');

const parsed = Ok('42').flatMap((s) => {
  const n = Number(s);
  return Number.isNaN(n) ? Fail('NaN') : Ok(n);
});

match(parsed, {
  Ok: (n) => console.log(`Parsed: ${n}`),
  Err: (e) => console.error(`Failed: ${e}`),
});

Why

TypeScript lacks a standard way to represent optional values and fallible operations without null, undefined, or try/catch. Galvorn brings Rust's algebraic types to TypeScript with an idiomatic API and complete type safety.

  • Option<T> replaces T | null | undefined — no more if (x !== null && x !== undefined)
  • Result<T, E> replaces try/catch and { data, error } patterns — errors are values, not exceptions
  • match() provides exhaustive pattern matching for both types — standalone or method
  • 100% test coverage, 112 tests, zero runtime dependencies

Features

Option — Safe Nullable Handling

import { Some, None, Option } from 'galvorn';

const name = Some('Alice');
const empty = None<string>();

// Transform
const upper = name.map((n) => n.toUpperCase()); // Some("ALICE")

// Chain
const first = name.flatMap((n) => (n.length > 0 ? Some(n[0]) : None()));

// Extract with default
const value = empty.unwrapOr('default'); // "default"

// Pattern match
name.match({
  Some: (n) => console.log(`Hello, ${n}`),
  None: () => console.log('No name'),
});

// Convert from nullable
const opt = Option.fromNullable(document.getElementById('app'));

Result — Error as Values

import { Ok, Fail, Result } from 'galvorn';

const success = Ok(42);
const failure = Fail('something went wrong');

// Transform
const doubled = success.map((n) => n * 2); // Ok(84)

// Chain
const parsed = Ok('42').flatMap((s) => {
  const n = Number(s);
  return Number.isNaN(n) ? Fail('not a number') : Ok(n);
});

// Extract with default
const value = failure.unwrapOr(0); // 0

// Pattern match
parsed.match({
  Ok: (n) => console.log(`Parsed: ${n}`),
  Err: (e) => console.error(`Error: ${e}`),
});

// Catch exceptions
const result = Result.fromThrowable(() => JSON.parse(input));

// Combine multiple results
const combined = Result.combine([Ok(1), Ok(2), Ok(3)]); // Ok([1, 2, 3])

Standalone match

Works with both Option and Result — useful for pipelines and functional composition:

import { match, Some, Ok } from 'galvorn';

const msg = match(Some(42), {
  Some: (v) => `got ${v}`,
  None: () => 'nothing',
});

const status = match(Ok(200), {
  Ok: (code) => `status ${code}`,
  Err: (e) => `failed: ${e}`,
});

Examples

| Example | Run | Showcases | |---|---|---| | option-basics.ts | npx tsx examples/option-basics.ts | Some/None, map, flatMap, filter, unwrapOr | | result-basics.ts | npx tsx examples/result-basics.ts | Ok/Fail, fromThrowable, combine, mapErr | | real-world.ts | npx tsx examples/real-world.ts | Option + Result in realistic scenarios |

Architecture

src/
  index.ts     # public barrel — only file consumers import
  option.ts    # Option<T> abstract class + SomeOption/NoneOption + Some()/None() factories
  result.ts    # Result<T, E> abstract class + OkResult/ErrResult + Ok()/Fail() factories
  match.ts     # Standalone match() with overloads for Option and Result

Internal classes (SomeOption, NoneOption, OkResult, ErrResult) are NOT exported. Only factory functions and abstract types are public — this keeps the API surface minimal and prevents instanceof checks against internals.

LLM / AI Integration

This package ships with llms.txt files for AI-assisted development:

  • llms.txt — Concise index following the llms.txt standard
  • llms-full.txt — Complete API reference optimized for LLM context windows

Compatible with Context7 and any tool that supports the llms.txt standard.

API Reference

Factory Functions

| Export | Description | |---|---| | Some(value) | Creates an Option containing a value | | None<T>() | Creates an empty Option | | Ok(value) | Creates a successful Result | | Fail(error) | Creates a failed Result | | match(value, patterns) | Standalone pattern matching for Option or Result |

Option Methods

| Method | Description | |---|---| | isSome() | Returns true if the option contains a value | | isNone() | Returns true if the option is empty | | unwrap() | Returns the value or throws | | expect(msg) | Returns the value or throws with a custom message | | unwrapOr(default) | Returns the value or a default | | unwrapOrElse(fn) | Returns the value or computes a default | | map(fn) | Transforms the inner value | | flatMap(fn) | Transforms and flattens Option<Option<U>> | | filter(predicate) | Returns None if the predicate fails | | and(other) | Returns other if both are Some, otherwise None | | or(other) | Returns self if Some, otherwise other | | orElse(fn) | Returns self if Some, otherwise calls fn | | xor(other) | Returns Some if exactly one is Some | | zip(other) | Combines two Some values into a tuple | | inspect(fn) | Calls fn on the value without consuming it | | match({ Some, None }) | Exhaustive pattern matching | | toUndefined() | Converts to T \| undefined | | toNull() | Converts to T \| null |

Option Static Methods

| Method | Description | |---|---| | Option.fromNullable(value) | Creates Some(v) or None from a nullable value |

Result Methods

| Method | Description | |---|---| | isOk() | Returns true if the result is Ok | | isErr() | Returns true if the result is Err | | unwrap() | Returns the value or throws | | unwrapErr() | Returns the error or throws | | expect(msg) | Returns the value or throws with a custom message | | expectErr(msg) | Returns the error or throws with a custom message | | unwrapOr(default) | Returns the value or a default | | unwrapOrElse(fn) | Returns the value or computes from the error | | map(fn) | Transforms the Ok value | | mapErr(fn) | Transforms the Err value | | mapOr(default, fn) | Transforms Ok or returns a default | | mapOrElse(errFn, okFn) | Transforms both branches | | flatMap(fn) | Transforms and flattens Result<Result<U, E>, E> | | and(other) | Returns other if both are Ok, otherwise the first Err | | or(other) | Returns self if Ok, otherwise other | | orElse(fn) | Returns self if Ok, otherwise calls fn with the error | | inspect(fn) | Calls fn on the Ok value without consuming it | | inspectErr(fn) | Calls fn on the Err value without consuming it | | match({ Ok, Err }) | Exhaustive pattern matching |

Result Static Methods

| Method | Description | |---|---| | Result.fromThrowable(fn) | Wraps a throwing function into Result<T, Error> | | Result.combine(results) | Collects an array of results into Result<T[], E> |

Types

| Export | Description | |---|---| | Option<T> | Abstract class for optional values | | Result<T, E> | Abstract class for fallible operations (E defaults to string) |

Compatibility

  • Node.js >= 20
  • TypeScript >= 5.0
  • ESM only

License

MIT