TypeScript Examples

TypeScriptOct 23, 2026

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.

unicodeutf-8encodingbase64
000
TypeScriptOct 23, 2026

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.

formattingtableterminalcli
000
TypeScriptOct 23, 2026

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.

error-messagestypesvalidationforms
000
TypeScriptOct 23, 2026

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.

debuggingerror-handlingparsingjson
000
TypeScriptOct 23, 2026

buildQuery and parseQuery URL helpers

Encodes flat values and arrays into a query string, merges defaults and parses incoming URLs without double-encoding mistakes.

query-stringurlurlsearchparamsencoding
000
TypeScriptOct 23, 2026

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.

concurrencypromisesasyncworker-pool
000
TypeScriptOct 23, 2026

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.

httpjsontimeoutfetch
000
TypeScriptOct 23, 2026

EnvConfig reader with typed getters

Collects typed values from environment variables with defaults, range checks and aggregated validation errors instead of silent NaN fallbacks.

configurationenv-varsvalidationdefaults
000
TypeScriptOct 23, 2026

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.

token-bucketasyncthrottlingrate-limiting
000
TypeScriptOct 23, 2026

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.

evictiongenericslrucache
000
TypeScriptOct 23, 2026

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.

sortingrecordsnull-handlingcomparator
000
TypeScriptOct 23, 2026

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.

batchingasyncpaginationiterables
000
TypeScriptOct 23, 2026

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.

streamingasync-iteratorfile-ioreadline
000
TypeScriptOct 23, 2026

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.

mergeimmutabilitydeep-cloneobjects
000
TypeScriptOct 23, 2026

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.

asyncresiliencebackoffretryjitter
000