@rwaterman/utils
v1.1.2
Published
Typed, small, dependency-free, lightweight async helper/utility functions we use all the time
Readme
@rwaterman/utils
Typed, small, dependency-free, lightweight async helper/utility functions we use all the time.
npm install @rwaterman/utilsFunctions
to(promise)— resolves to{ res, err }instead of throwingtoSync(fn)— sync sibling ofto:{ res, err }from a throwing function (JSON.parse,new URL(), ...)delay(ms)— promise that resolves aftermstimeout(promise, ms)— rejects withTimeoutErrorif the promise takes longer thanmsretry({ yourAsyncFn, numTimes, delayMs, factor, maxDelayMs, shouldRetry })— retries with optional exponential backoff, returns{ res, errors }poll({ fn, until, everyMs, timeoutMs })— callsfneveryeveryMsuntiluntil(res)is true; rejects withTimeoutErroraftertimeoutMsabortable(promise, signal)— rejects withsignal.reasonon abort; composes withAbortSignal.timeout()/AbortSignal.any()debounce(fn, ms)— trailing-edge debounce with.cancel()and.flush()throttle(fn, ms)— leading edge plus one trailing call per window, with.cancel()and.flush()once(fn)— callsfnat most once and returns the cached result (a throw is not cached)memoize(fn, { ttlMs, key })— caches by arguments; async-aware (shares in-flight promises, never caches rejections)requireEnv(name)— returnsprocess.env[name]or throws naming the missing variable
Development
Node 24+, TypeScript 7 (native compiler), Vitest, oxlint.
npm ci
npm test
npm run lint
npm run build