R

@robonen/stdlib

A platform-independent standard library of tools, utilities, and helpers for TypeScript — arrays, async, math, data structures, and patterns, all tree-shakeable and fully typed.

Every project ends up reimplementing the same handful of helpers: dedupe an array, clamp a number, group records by a key, retry a flaky request. @robonen/stdlib collects those building blocks into one cohesive, dependency-free package. It runs the same in Node, the browser, and the edge — there are no platform globals, no polyfills, and no runtime dependencies. Import only what you use; the rest is shaken out of your bundle.

Fully typed

Generic signatures preserve element and key types end to end, so inference keeps working through groupBy, partition, zip, and friends.

Zero dependencies

No transitive dependencies and no platform assumptions. The same code runs in Node, the browser, Deno, Bun, and edge runtimes.

Tree-shakeable

Each utility is a standalone export with no shared side effects. Import a single function and ship only that function.

Batteries included

Beyond array and math helpers you get data structures (Deque, BinaryHeap, LinkedList) and patterns (StateMachine, PubSub, Command).

Install

sh
pnpm add @robonen/stdlib

Quick start

Import named utilities directly from the package root. Each one is small, predictable, and focused on a single job.

ts
import { groupBy, unique, clamp, tryIt } from '@robonen/stdlib';

// Arrays — group records by a derived key
const byType = groupBy(
  [{ type: 'a', v: 1 }, { type: 'b', v: 2 }, { type: 'a', v: 3 }],
  item => item.type,
);
// => { a: [{ type: 'a', v: 1 }, { type: 'a', v: 3 }], b: [{ type: 'b', v: 2 }] }

// Arrays — dedupe in a single pass
unique([1, 1, 2, 3, 3]); // => [1, 2, 3]

// Math — keep a value inside a range
clamp(value, 0, 100);

// Async — error handling without forking control flow
const { error, data } = await tryIt(fetch)('/api/todos/1');
if (error) {
  // handle the failure
} else {
  // use data
}

What's inside

The library is organized into focused modules. A few of the most-used building blocks:

  • ArraysgroupBy, partition, unique, zip, cluster, range.
  • AsynctryIt, retry, pool, sleep for control flow that doesn't fight you.
  • Mathclamp, lerp, remap, each with a BigInt variant.
  • Functionsdebounce, throttle, memoize, once, compose, pipe.
  • Structs & patternsDeque, PriorityQueue, StateMachine, PubSub and more.

Where to next

Browse the full API reference below, or jump straight to a popular utility:

API Reference

Arrays · 14

Async · 4

Bits · 9

Collections · 2

Comparators · 1

Functions · 6

Math · 10

Objects · 2

Patterns · 7

Structs · 7

Sync · 1

Text · 9

Types · 14