Why @pivanov/utils?
A small, opinionated TypeScript toolbox - the handful of helpers we reach for on every project, with no runtime dependencies and full type safety.
What's inside
| Module | What it gives you |
|---|---|
assertion | Type guards: isString, isArray, isDate, isNil, isEmpty, isPromise, and more |
object | pick, omit, merge, deepMerge, mapValues, groupBy, pickBy/omitBy, typed keysOf/entriesOf/fromEntries |
promise | sleep (with AbortSignal), timeout, retry (with backoff + cancellation), defer, parallelLimit |
string | camelCase, pascalCase, kebabCase, snakeCase, titleCase, slugify, escapeHtml, escapeRegExp, truncate, words, lines |
tools/deepClone | Rich deep clone - prototypes, getters/setters, symbols, Buffers, TypedArrays, circular refs |
tools/isEqual | Deep structural equality with cycle detection; handles RegExp, Error, TypedArrays, ArrayBuffer |
tools/dom | isBrowser, checkVisibility, isInViewport, setStyleProperties, calculateRenderedTextWidth |
tools/cache-api | Typed wrapper over the browser Cache API with BigInt-safe serialization and optional TTL |
tools/eventBus | Typed event bus with busDispatch, busSubscribe, busOnce, and the useEventBus React hook |
types | DeepPartial, DeepReadonly, Mutable, Prettify, TDict |
Design principles
Zero runtime dependencies
Install just this one package. React is a peer dependency and only needed for the optional useEventBus hook.
Tree-shakeable by construction
Per-module subpath exports plus "sideEffects": false means your bundler drops unused code.
ts
import { camelCase } from '@pivanov/utils/string';
import { deepClone } from '@pivanov/utils/tools';Fully typed
Every function has generic signatures that preserve literal types where it matters. Type guards narrow their arguments. Utility types like DeepPartial and DeepReadonly are ready-made.
Tested
200+ tests covering the happy path and real edge cases - circular references, concurrent timers, Buffer fallbacks, symbol-keyed properties, and more.
When not to use it
- You already have
lodashand don't want another dependency -@pivanov/utilsisn't a full lodash replacement. - You need specialized libraries (e.g.,
mittfor event bus,dequalfor equality,change-casefor strings). Those are excellent at exactly one thing. This library is broader but shallower.
Drop it in
bash
bun add @pivanov/utilsbash
npm install @pivanov/utilsbash
yarn add @pivanov/utilsbash
pnpm add @pivanov/utilsHead to Getting Started to begin.