TypeScript Examples
encodeBase64/decodeBase64 for UTF-8 text
Encodes and decodes Base64 over UTF-8 bytes with compact-input checks and clearer errors than atob's raw InvalidCharacterError.
renderTable<T>() align terminal columns
Renders rows as an aligned plain-text table with per-column alignment and automatic width calculation, no terminal library required.
validateFields with per-field error maps
Validates a flat form or payload against declarative rules and returns field-level messages ready to render next to each input.
parseJsonSafely<T>() with line/column errors
Parses JSON strings or files and rewrites raw SyntaxErrors into messages with line, column and a nearby snippet for faster debugging.
buildQuery and parseQuery URL helpers
Encodes flat values and arrays into a query string, merges defaults and parses incoming URLs without double-encoding mistakes.
runPool<T>() bounded async worker pool
Runs promise-returning tasks across a fixed number of concurrent workers and returns results or errors in the original index order.
getJson<T>() fetch with AbortSignal timeout
Fetches JSON with a hard AbortSignal timeout, status checks and content-type verification, turning network failures into clear errors.
EnvConfig reader with typed getters
Collects typed values from environment variables with defaults, range checks and aggregated validation errors instead of silent NaN fallbacks.
TokenBucket limiter with lazy refill
A token bucket limiter that allows bursts up to capacity while enforcing a sustained refill rate, useful for API clients and job queues.
LruCache<K, V> bounded generic LRU cache
A generic LRU cache backed by an insertion-ordered Map that evicts the least recently used key as soon as capacity is exceeded.
compareBy<T>() multi-key sort comparator
Builds a stable multi-key comparator with per-key direction and explicit null placement, replacing brittle nested if-chains inside sort callbacks.
chunk<T>() and chunkAsync<T>() batch iterables
Turns any sync or async iterable into fixed-size arrays, which is handy for bulk API calls, pagination tokens and batched database writes.
readLines(): stream a file with readline
Streams a text file lazily with readline and an async iterator, so multi-gigabyte logs pass through without loading into memory.
deepClone + deepMerge for nested records
Recursively copies arrays, Maps, Sets, Dates and plain objects, then merges patches without sharing references or mutating the source value.
retryWithBackoff<T>() with capped jitter
Retries an async task with capped exponential backoff and randomised jitter, so transient failures recover without hammering a struggling service.