@peerigon/typescript-toolkit
v4.4.0
Published
π§β¨ Tiny helpers for TypeScript applications
Readme
Features
- π― High-quality module design
- β‘ Lightweight sub-package exports
- π¦ Tree-shakeable ES modules
- β Zero dependencies
Installation
npm install @peerigon/typescript-toolkit --saveAlso available on JSR.
Usage
Import only the utilities you need. Each one is exposed as its own subpath:
import { assert } from "@peerigon/typescript-toolkit/assert";Utilities
| Module | Description | Docs |
| ---------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------- | --------------------------------------------------- |
| api | Define a typed JSON API client with an overridable hook pipeline | β |
| api/rate-limit | Rate-limited fetch for defineApi (pacing + Retry-After) | β |
| api/result | defineApiResult β like defineApi, but returns Result.Sync | β |
| assert | Assert a value is not null or undefined, with TypeScript narrowing | β |
| assert-never | Assert a code path is unreachable, for exhaustive switch/case statements | β |
| concurrency/once | Run an async function at most once (single-flight + cache) | β |
| concurrency/once/result | once with a synchronous Result snapshot | β |
| concurrency/exactlyOnce | Invoke an async function exactly once; second call throws | β |
| concurrency/exactlyOnce/result | exactlyOnce with a synchronous Result snapshot | β |
| concurrency/mutex | Serialize async tasks (concurrency 1) | β |
| concurrency/rate-limit | Pace async task starts (max per sliding interval) | β |
| need | Assert a value is not null or undefined and return it with a narrowed type | β |
| no-null | Convert between null and undefined in JSON-like values (runtime + types) | β |
| dedupe | Remove duplicate values from an array while preserving first-occurrence order | β |
| emitter | Minimal typed event emitter with payload objects per event | β |
| enums | Lightweight string-enum alternative for erasableSyntaxOnly TypeScript projects | β |
| map-leaves | Deeply map leaves in JSON-like values (mutates arrays/objects in place) | β |
| match | Exhaustive pattern matching with compile-time case checks, similar to switch | β |
| metadata | Typed metadata attached to objects via per-channel WeakMap stores | β |
| namespace | Hierarchical namespaces with exclusive member claims and dotted prefixes | β |
| result | Type-safe error handling with pending, success, and error states | β |
| runtime | Generator-based runtime for the generator context pattern, with type-safe yield* | β |
| signals | Push-based reactive state with explicit watchers and signal.from adapters | β |
| sleep | Promise-based delay with optional AbortSignal cancellation | β |
| stable-stringify | Deterministic stringify for JSON + Map/Set/BigInt/Symbol/Date/RegExp | β |
| stable-stringify/json | JSON-only deterministic JSON.stringify with sorted object keys | β |
| unwrap | Extract values from Result or nullable types, with optional fallback support | β |
