@anyhow/std
v0.3.0
Published
A batteries-included TypeScript utility toolkit featuring type-safe error handling, optional values, runtime guards, async primitives, iterator combinators, formatting, string utilities, math, random, and caching — all with zero dependencies.
Readme
@anyhow/std
A batteries-included TypeScript utility toolkit featuring type-safe error handling, optional values, runtime guards, async primitives, iterator combinators, formatting, string utilities, math, random, and caching — all with zero dependencies.
Quick start
bun add @anyhow/stdimport { ok, err } from "@anyhow/std/result";
function divide(a: number, b: number) {
if (b === 0) return err("division by zero");
return ok(a / b);
}
divide(10, 2)
.map((v) => v * 2)
.unwrapOr(0); // 10
import { some, none } from "@anyhow/std/option";
some(42)
.filter((v) => v > 0)
.unwrapOr(0); // 42Modules
Each module is independently importable via subpath exports:
- result —
Result<T, E>with method chaining and static combinators - option —
Option<T>for nullable values - guard — Runtime type guards and assertions
- async —
sleep,debounce,throttle,retry,concurrent,memoizeAsync - safe — Wrap throwy operations in
Result - fmt — Human-readable formatting (strings, numbers, dates, units)
- iter — Lazy iterator combinators
- math — Interpolation, statistics, number theory
- cache — LRU cache with TTL and memoization
- string — Case conversion, slugify, template, HTML escaping
- random — Seeded PRNG with shuffle, pick, gaussian, uuid
See the main README for full documentation and examples.
