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

plgg

v0.0.27

Published

Pipeline Utility

Readme

plgg

UNSTABLE - This is experimental study work focused on functional programming concepts. Primarily intended for our own projects, though publicly available.

The core functional programming library. Provides type-safe pipelines, Result/Option monads, validated primitive types, and pattern matching for TypeScript.

This package is part of the plgg monorepo.

Installation

npm install plgg

Quick Start

Type-Safe Validation with cast

Compose validation functions that return Result, with automatic error accumulation for object properties:

import {
  cast, asObj, forProp,
  asNum, asStr, asTime,
  isOk,
} from "plgg";
import type {
  Num, Str, Time,
  Result, InvalidError,
} from "plgg";

type UserProfile = {
  id: Num;
  email: Str;
  createdAt: Time;
};

const asUserProfile = (
  data: unknown,
): Result<UserProfile, InvalidError> =>
  cast(
    data,
    asObj,
    forProp("id", asNum),
    forProp("email", asStr),
    forProp("createdAt", asTime),
  );

const result = asUserProfile({
  id: 1,
  email: "[email protected]",
  createdAt: "2025-01-01T00:00:00Z",
});

if (isOk(result)) {
  console.log(result.content);
}

Async Pipelines with proc

Chain sync and async functions with automatic Result unwrapping and error short-circuiting:

import { proc, isOk } from "plgg";

const result = await proc(
  5,
  (x: number) => x + 1,
  (x: number) => Promise.resolve(x * 2),
  (x: number) => `Result: ${x}`,
);

if (isOk(result)) {
  console.log(result.content); // "Result: 12"
}

Pattern Matching with match

Exhaustive, type-safe pattern matching for tagged unions:

import {
  match, ok$, err$, otherwise,
} from "plgg";
import type { Result } from "plgg";

const describe = (
  r: Result<string, number>,
): string =>
  match(r)(
    [ok$("hello"), () => "Greeting"],
    [err$(404), () => "Not found"],
    [otherwise, () => "Something else"],
  );

Simple Composition with pipe

Pass a value through a chain of functions:

import { pipe } from "plgg";

const result = pipe(
  "hello world",
  (s: string) => s.split(" "),
  (words: string[]) => words.length,
); // 2

Module Categories

All exports are available as top-level imports from "plgg". The library is organized into 11 categories:

Abstracts

Typeclass interfaces following the Haskell hierarchy: Functor, Apply, Applicative, Chain, Monad, Foldable, Traversable. Also provides service interfaces: Castable, Refinable, JsonSerializable.

Atomics

Primitive validated types: Num, Bool, BigInt, Bin, SoftStr, Time, Int. Each has an is* type guard and as* cast function (e.g., isNum, asNum).

Basics

Refined string types (Str, Alphabet, Alphanumeric, CamelCase, PascalCase, KebabCase, SnakeCase, CapitalCase), floating point (Float), and ranged integers (I8, I16, I32, I64, I128, U8, U16, U32, U64, U128).

Collectives

Array types: Vec, MutVec, ReadonlyArray, VecLike.

Conjunctives

Object types: Obj (readonly validated record), Dict (string-keyed dictionary), RawObj (unvalidated object).

Contextuals

Tagged containers: Box<TAG, CONTENT> (universal variant), Ok, Err, Some, None, Icon, Pattern, NominalDatum, OptionalDatum.

Disjunctives

Union types and protocols: Result<T, E>, Option<T>, Datum, JsonReady, Atomic, Basic, ObjLike. Also provides forProp and forOptionProp for object property validation.

Exceptionals

Errors are pure tagged data (Box unions), not Error subclasses — expected failures are values that fold through match/matchResult by tag, and flow through Result/proc with their precise type preserved. Variants: InvalidError, SerializeError, DeserializeError, and Defect — the bottom for an unexpected throw, carrying a serializable Cause ({ name, message, stack }); the union is PlggError. Helpers: isPlggError, plggErrorMessage, matchPlggError, resultErrorMessage, printPlggError, and the Error-interop seam toError / panic (for handing a value-error to an Error-expecting boundary).

Flowables

Composition primitives: cast (sync validation chain), proc (async pipeline), pipe (simple composition), flow (lazy curried composition), match (pattern matching).

Functionals

Utility functions: env, bind, conclude, debug, defined, filter, find, hold, pass, refine, tap, tryCatch, postJson, atIndex, atProp.

Grammaticals

Type-level constructs: Brand, Function, NonNeverFn, Procedural, PromisedResult, BoolAlgebra.

Development

# Type check
npm run tsc

# Run tests
npm test

# Coverage
npm run coverage

License

MIT License - Copyright (c) 2025 qmu