Skip to content
VersionSizeTypeScriptDependencies
Toolkit logo

Toolkit

Toolkit is a comprehensive utility library with zero dependencies. It is tree-shakeable, so you only bundle what you import. It ships 75+ fully typed utilities for arrays, objects, strings, async flows, dates, math, money, random values, and runtime type checks.

Installation

sh
pnpm add @vielzeug/toolkit
sh
npm install @vielzeug/toolkit
sh
yarn add @vielzeug/toolkit

Quick Start

ts
import { chunk, group, keyBy, select, toggle, sort, debounce, retry, merge, is } from '@vielzeug/toolkit';

// Arrays
chunk([1, 2, 3, 4, 5], 2); // [[1,2],[3,4],[5]]
group([{ type: 'a' }, { type: 'b' }, { type: 'a' }], (x) => x.type);
// { a: [...], b: [...] }
keyBy(
  [
    { id: 1, name: 'Alice' },
    { id: 2, name: 'Bob' },
  ],
  'id',
);
// { '1': {id:1,name:'Alice'}, '2': {id:2,name:'Bob'} }

// Sort with object selectors
sort(
  [
    { age: 30, name: 'Bob' },
    { age: 30, name: 'Alice' },
    { age: 25, name: 'Chris' },
  ],
  { age: 'desc', name: 'asc' },
);

// Functions
const fn = debounce(() => console.log('typed'), 300);

// Async
const result = await retry(() => fetchData(), { times: 3, delay: 1000 });

// Objects
const merged = merge('deep', { a: { x: 1 } }, { a: { y: 2 } });
// { a: { x: 1, y: 2 } }

// Type guards
is.string('hello'); // true
is.nil(null); // true

Why Toolkit?

Lodash ships ~70 kB even tree-shaken. Toolkit provides modern, tree-shakeable utilities with full TypeScript inference at a fraction of the size.

ts
// Before - verbose native JS
let groupedByCategory = {} as Record<string, typeof items>;

groupedByCategory = items.reduce((acc, item) => {
  const key = item.category;
  (acc[key] = acc[key] || []).push(item);

  return acc;
}, groupedByCategory);

// After - Toolkit
import { group } from '@vielzeug/toolkit';
const grouped = group(items, (item) => item.category);
FeatureToolkitLodashRadash
Bundle size9.6 KB~26 kB~5 kB
Tree-shakeable✅ Always✅ lodash-es
TypeScript✅ First-class⚠️ Via @types
Async utilities⚠️ Limited
Zero dependencies

Use Toolkit when you want utility functions with strong TypeScript types and minimal bundle impact.

Consider Lodash or Radash if your codebase already depends on them and migration effort outweighs the type and bundle-size gains.

Features

  • Arrayschunk, group, keyBy, fold, select, toggle, replace, rotate, search, sort, contains, uniq, pick, list, remoteList
  • Asyncretry, sleep, parallel, pool, queue, race, attempt, defer, waitFor, Scheduler, polyfillScheduler
  • Objectsmerge, diff, get, seek, prune, proxy, stash, parseJSON
  • StringscamelCase, kebabCase, pascalCase, snakeCase, truncate, similarity
  • Mathsum, average, median, min, max, clamp, round, range, percent, linspace, allocate, distribute
  • DatestimeDiff, interval, expires
  • Functionsdebounce, throttle, compose, pipe, curry, memo, once, compare, fp
  • Zero dependencies — tree-shakeable; import only what you need

Compatibility

EnvironmentSupport
Browser
Node.js
SSR
Deno

See Also