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

@eserstack/primitives

v5.1.0

Published

Readme

🧱 @eserstack/primitives

Note: JSR is frozen at 4.5.x. From 5.0.0, @eserstack/primitives is published on npm under the same name (pnpm add @eserstack/primitives); the JSR versions stay available but get no updates.

eserstack Foundation — eser/stack on GitHub Install: pnpm add @eserstack/primitives

The type foundation for the eserstack FP ecosystem.

Vision

@eserstack/primitives defines the Result and Option types that the rest of the ecosystem passes around, the functions that create, inspect and combine them, and runtime type guards and type-level helpers. Every other package in the ecosystem builds on these primitives.

Design Philosophy

  • Types describe shapes. Result<T, E>, Option<T>, Ok<T>, Fail<E>, Some<T>, None — discriminated unions with a _tag field.
  • Constructors create values. ok(), fail(), some(), none — minimal factory functions.
  • Type guards narrow them. isOk(), isFail(), isSome(), isNone() — predicate functions for type narrowing.
  • Combinators live next to their type. primitives.results also exports map, flatMap, mapError, match, getOrElse, tryCatch, all, any and tap, and primitives.options exports map, flatMap, filter, match, orElse, zip and toResult. Each takes the result or option as its first argument; to chain them in fp.pipe, wrap each call in an arrow function, as in (result) => primitives.results.map(result, double).
  • General utilities live elsewhere. Functions over arrays, objects and other functions (pipe, flow, groupBy, deepMerge and the rest) are in @eserstack/fp, and multi-step workflows are in @eserstack/functions.

How It Fits

@eserstack/primitives  →  @eserstack/fp  →  @eserstack/functions
   (this package)     (array, object   (higher-level
    types,             and function     compositions)
    constructors,      utilities)
    combinators)
  • vs @eserstack/fp: Primitives defines Result<T, E> and the map, flatMap and match that work on it; fp gives you pipe and flow, which chain one-argument functions such as those calls wrapped in arrow functions, plus utilities for arrays and objects.
  • vs @eserstack/functions: Primitives defines the data types — functions provides multi-step workflows (run(), collect(), Task) that orchestrate them.

Quick Start

import * as primitives from "@eserstack/primitives";

// Result — explicit error handling
const divide = (
  a: number,
  b: number,
): primitives.results.Result<number, string> =>
  b === 0
    ? primitives.results.fail("Division by zero")
    : primitives.results.ok(a / b);

const result = divide(10, 2);
if (primitives.results.isOk(result)) {
  console.log(result.value); // 5
}

// Option — nullable value handling
const find = (id: string): primitives.options.Option<string> =>
  id === "1" ? primitives.options.some("Alice") : primitives.options.none;

const user = find("1");
if (primitives.options.isSome(user)) {
  console.log(user.value); // "Alice"
}

Combinators

Each combinator takes the result or option as its first argument. A failure or a missing value passes through map and flatMap untouched, and match or getOrElse turns the outcome into a plain value:

import * as primitives from "@eserstack/primitives";

const parsed = primitives.results.tryCatch(() => JSON.parse('{"port":8080}'));
const port = primitives.results.map(parsed, (config) => Number(config.port));
const message = primitives.results.match(port, {
  ok: (value) => `listening on ${value}`,
  fail: (error) => `bad config: ${String(error)}`,
});
// "listening on 8080"

const nicknames = new Map([["ada", "Countess"]]);
const label = primitives.options.getOrElse(
  primitives.options.map(
    primitives.options.fromNullable(nicknames.get("grace")),
    (value) => value.toUpperCase(),
  ),
  "ANONYMOUS",
);
// "ANONYMOUS"

Generator Protocol (Do-Notation)

Result values implement the iterator protocol, enabling yield* unwrapping in generator-based composition (see @eserstack/functions):

import * as primitives from "@eserstack/primitives";
import * as functions from "@eserstack/functions";

const result = await functions.run(async function* () {
  const a = yield* primitives.results.ok(5); // unwraps to 5
  const b = yield* primitives.results.ok(10); // unwraps to 10
  return a + b; // 15
});
// result: ok(15)

Exports

Each module is a namespace on the package root (primitives.results, primitives.options and so on) and is also published under its own sub-path.

| Namespace | Sub-path | Contents | | ----------------------- | ----------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | primitives.results | @eserstack/primitives/results | Result<T,E>, Ok<T>, Fail<E>, ok(), fail(), isOk(), isFail(); combinators map, flatMap, flatMapW, mapError, flatMapError, flatMapErrorW, match, tap, tapError; getOrElse, getOrThrow, getOrNull, getOrUndefined; all, any; tryCatch, tryCatchAsync, fromPromise, toPromise | | primitives.options | @eserstack/primitives/options | Option<T>, Some<T>, None, some(), none, isSome(), isNone(), fromNullable(), fromFalsy(); combinators map, flatMap, filter, match, orElse, tap, tapNone, zip, zipWith, contains, exists; getOrElse, getOrThrow, getOrNull, getOrUndefined; all, any; toResult, fromResult | | primitives.functions | @eserstack/primitives/functions | Generic function and class type definitions | | primitives.promises | @eserstack/primitives/promises | Promisable<T> and promise utility types | | primitives.typeGuards | @eserstack/primitives/type-guards | Runtime type guards (isString, isNumber, isDefined, etc.) | | primitives.typeSlices | @eserstack/primitives/type-slices | Tuple utility types (First, Last, ArgList, etc.) |


🔗 For further details, visit the eserstack repository.