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

lite-fp

v0.6.0

Published

Functional programming utilities.

Readme

lite-fp

Tiny, zero‑dependency FP helpers for TypeScript.

  • Algebraic data types: Option, Either, Result, Maybe
  • Product types: Pair
  • Small, predictable API with discriminated unions
  • ESM and CJS builds, first‑class TypeScript types

Install

npm i lite-fp
# or
pnpm add lite-fp

Import

// ESM
import {
  Option,
  Either,
  Result,
  Pair,
  some,
  none,
  right,
  left,
} from "lite-fp";

// CJS
const {
  Option,
  Either,
  Result,
  Pair,
  some,
  none,
  right,
  left,
} = require("lite-fp");

Quick Start

Option

import { Option, some, none } from "lite-fp";

const o1 = Option.new("hello"); // Some("hello")
const o2 = Option.new(null); // None

const upper = Option.map(o1, s => s.toUpperCase()); // Some("HELLO")

const value = Option.getOrElse(o2, "fallback"); // "fallback"

Maybe (T | null | undefined)

import { Maybe } from "lite-fp";

const m1 = Maybe.new(42); // 42
const m2 = Maybe.new(null); // undefined (None)

const doubled = Maybe.map(m1, x => x * 2); // 84
const value = Maybe.getOrElse(m2, 0); // 0

if (Maybe.isSome(m1)) {
  // m1 is number here
}

Either (A | B)

import { Either, left, right } from "lite-fp";

type Err = { message: string };

const parseJson = (s: string) =>
  Either.fromThrowable(
    () => JSON.parse(s),
    e => ({ message: String(e) }) as Err,
  );

const e1 = parseJson('{"a":1}'); // Right({ a: 1 })
const e2 = parseJson("invalid"); // Left({ message: "..." })

const msg = Either.fold(
  e2,
  l => `err: ${l.message}`,
  r => `ok: ${Object.keys(r).length}`,
); // => "err: ..."

Promise helper

// Adds Promise.prototype.toEither(onError)
const user = await fetch("/api/user")
  .then(r => r.json())
  .toEither(e => new Error(String(e))); // Either<Error, User>

Result (Done | Fail)

import { Result } from "lite-fp";

const r1 = Result.new("data", "nope"); // Done("data")
const r2 = await Result.fromPromise(
  Promise.reject("x"),
  e => new Error(String(e)),
);

const safe = Result.recover(r2, () => "default"); // Done("default")

Pair

import { Pair, pair } from "lite-fp";

const p = pair(1, "a"); // Pair<number, string>
const p2 = Pair.map(
  p,
  x => x + 1,
  s => s.toUpperCase(),
); // [2, "A"]

API Overview

  • Option

    • Constructors: none, some, new, fromNullable, fromPredicate, fromThrowable, fromPromise
    • Type guards: isSome, isNone
    • Ops: map, flatMap, filter, match, getOrElse, getOrUndefined, getOrThrow
    • Combine: zip, apply, orElse
  • Either

    • Constructors: left, right, new, fromNullable, fromThrowable, fromPromise
    • Type guards: isLeft, isRight
    • Ops: map, mapLeft, bimap, flatMap, chain, fold, match, swap, getOrElse, zip, apply, tap, tapLeft
  • Result

    • Constructors: done, fail, new, fromNullable, fromThrowable, fromPromise
    • Type guards: isDone, isFail
    • Ops: map, mapError, flatMap, match, recover, getOrElse, getOrThrow, zip, apply
  • Maybe (T | null | undefined)

    • Constructors: new, just, nothing/nothingNull/nothingUndefined, fromNullable, fromPredicate, fromThrowable, fromPromise
    • Type guards: isSome, isNothing
    • Ops: map, flatMap, filter, match, zip, apply, orElse
    • Extract: getOrElse, getOrUndefined, getOrThrow
  • Pair

    • pair, and utilities to map, zip, convert to/from arrays/objects.

See src/ for the full, well‑typed surface.

Differences: Result/Either vs Maybe/Option

  • Either vs Result

    • Both are discriminated unions with rich operations.
    • Either represents two generic branches (Left/Right) and is often used for domain errors (Left) vs success (Right).
    • Result represents success (Done) or failure (Fail) explicitly and includes helpers like recover and getOrUndefined.
    • Choose based on semantics and style; the APIs are similar.
  • Maybe vs Option

    • Maybe is T | null | undefined (lightweight and idiomatic in JS). No runtime tag; use == null or the provided guards to narrow.
    • Option is a discriminated union ({ $: "Some" } | { $: "None" }) with stable guards (isSome, isNone) and utility functions.
    • Use Maybe when interoperating with APIs that naturally return null/undefined; use Option when you want an explicit ADT and consistent operations.

Notes

  • Prototype additions
    • Promise.prototype.toEither(onError) is provided when Either is imported.
    • Promise.prototype.toResult(onError) is provided when Result is imported.
    • Array.prototype.firstOption() is provided when Option is imported.
    • No runtime dependencies. Fully typed. Tree‑shakeable.

Contributing

  1. Fork the repository.
  2. Create a new branch: git checkout -b feature-name.
  3. Commit your changes: git commit -m 'Add some feature'.
  4. Push to the branch: git push origin feature-name.
  5. Open a pull request.

License

Distributed under the MIT License. See the LICENSE file for more details.