Skip to content

Toolkit API Reference

Complete reference for all utilities available in @vielzeug/toolkit.

Overview

Toolkit provides 110+ utilities organized into 9 categories. All utilities are:

  • Type-safe with full TypeScript inference
  • Tree-shakeable for minimal bundle sizes
  • Isomorphic (Browser + Node.js)
  • Well-tested with >95% code coverage

Quick Navigation


Array Utilities

Transform, filter, and manipulate arrays with type safety.

See Array Examples for detailed usage.

Transformation

UtilityDescriptionExample
mapTransform each element (async supported)map([1,2,3], x => x*2)[2,4,6]
filterFilter elements by predicate (async supported)filter([1,2,3], x => x > 1)[2,3]
reduceReduce array to single valuereduce([1,2,3], (a,b) => a+b)6
chunkSplit into chunks of specific sizechunk([1,2,3,4,5], 2)[[1,2],[3,4],[5]]
flattenFlatten nested arraysflatten([[1,2],[3,4]])[1,2,3,4]
compactRemove null/undefined valuescompact([1,null,2])[1,2]
alternateToggle item in array (add/remove)alternate([1,2], 2)[1]
shiftRotate array elementsshift([1,2,3], 1)[2,3,1]
substituteReplace elements conditionallysubstitute([1,2,3], x => x === 2, 0)[1,0,3]

Aggregation

UtilityDescriptionExample
groupGroup elements by key or functiongroup(users, u => u.role)
aggregateAggregate array to object by keyaggregate(items, 'id')
uniqRemove duplicate valuesuniq([1,2,2,3])[1,2,3]

Querying

UtilityDescriptionExample
findFind first matching elementfind([1,2,3], x => x > 1)2
findIndexFind index of first matchfindIndex([1,2,3], x => x > 1)1
findLastFind last matching elementfindLast([1,2,3], x => x > 1)3
someCheck if any element matchessome([1,2,3], x => x > 2)true
everyCheck if all elements matchevery([1,2,3], x => x > 0)true
containsCheck if array contains valuecontains([1,2,3], 2)true
searchFuzzy search in arraysearch(users, 'alice')

Sorting

UtilityDescriptionExample
sortSort with custom comparatorsort([3,1,2], (a,b) => a-b)[1,2,3]
arrangeSort by property or functionarrange(users, {age: 'asc'})

Selection

UtilityDescriptionExample
pickPick and transform elementpick([1,2,3], x => x*2, x => x > 1)4
selectMap and filter in one stepselect([1,2,3], x => x > 1 ? x*2 : null)

Pagination

UtilityDescriptionExample
listClient-side reactive paginationlist(data, {limit: 10})
remoteListServer-side reactive pagination with cachingremoteList({fetch: fetchFn, limit: 20})

Object Utilities

Deep operations, merging, and property manipulation.

See Object Examples for detailed usage.

UtilityDescriptionExample
cacheKey-value cache with automatic GCcache<T>()
cloneDeep clone an objectclone({a: {b: 1}})
mergeMerge objects (deep/shallow/etc.)merge('deep', obj1, obj2)
diffFind differences between objectsdiff(obj1, obj2)
pathAccess nested properties safelypath(obj, 'user.profile.name')
seekFind value by key anywhere in objectseek(obj, 'email')
parseJSONSafely parse JSON with fallbackparseJSON(str, defaultValue)
keysType-safe Object.keys()keys(obj)
valuesType-safe Object.values()values(obj)
entriesType-safe Object.entries()entries(obj)

String Utilities

Formatting, casing, similarity, and manipulation.

See String Examples for detailed usage.

Casing

UtilityDescriptionExample
camelCaseConvert to camelCasecamelCase('hello-world')'helloWorld'
snakeCaseConvert to snake_casesnakeCase('helloWorld')'hello_world'
kebabCaseConvert to kebab-casekebabCase('helloWorld')'hello-world'
pascalCaseConvert to PascalCasepascalCase('hello-world')'HelloWorld'

Manipulation

UtilityDescriptionExample
truncateTruncate string with ellipsistruncate('long text', 5)'long...'

Analysis

UtilityDescriptionExample
similarityCalculate string similaritysimilarity('hello', 'hallo')0.8

Function Utilities

Control execution timing and behavior.

See Function Examples for detailed usage.

UtilityDescriptionExample
debounceDelay execution until idledebounce(fn, 300)
throttleLimit execution ratethrottle(fn, 100)
memoMemoize/cache function resultsmemo(expensiveFn)
retryRetry failed operationsretry(asyncFn, {attempts: 3})
parallelProcess array with controlled concurrencyparallel(5, items, asyncFn)
composeCompose functions right-to-leftcompose(f, g, h)
pipeCompose functions left-to-rightpipe(f, g, h)
onceExecute function only onceonce(fn)
delayDelay executionawait delay(1000)
pruneRemove nullable/empty valuesprune({ a: 1, b: null }){ a: 1 }

Math Utilities

Statistics, calculations, and number operations.

See Math Examples for detailed usage.

Arithmetic Operations

UtilityDescriptionExample
addAdd two numbersadd(10, 20)30
subtractSubtract numberssubtract(20, 10)10
multiplyMultiply numbersmultiply(10, 5)50
divideDivide numbersdivide(20, 5)4
absAbsolute valueabs(-5)5

Distribution

UtilityDescriptionExample
allocateDistribute proportionallyallocate(100, [1,2,3])[16,33,51]
distributeDistribute evenlydistribute(100, 3)[34,33,33]

Statistics

UtilityDescriptionExample
sumSum of numberssum([1,2,3])6
averageCalculate average/meanaverage([1,2,3])2
medianFind median valuemedian([1,2,3,4,5])3
minFind minimum valuemin([1,2,3])1
maxFind maximum valuemax([1,2,3])3

Number Utilities

UtilityDescriptionExample
clampClamp value to rangeclamp(10, 0, 5)5
rangeGenerate number rangerange(1, 5)[1,2,3,4,5]
roundRound to decimal placesround(3.14159, 2)3.14
rateCalculate percentagerate(25, 100)25
boilReduce with comparatorboil([1,2,3], (a,b) => a+b)

Money Utilities

Currency formatting and conversion with precision.

See Money Examples for detailed usage.

UtilityDescriptionExample
currencyFormat money for displaycurrency({amount: 123456n, currency: 'USD'})'$1,234.56'
exchangeConvert between currenciesexchange(usd, {from: 'USD', to: 'EUR', rate: 0.85})

Date Utilities

Time intervals, differences, and expiration checks.

See Date Examples for detailed usage.

UtilityDescriptionExample
expiresCheck expiration statusexpires('2026-01-01')'SOON'
intervalGenerate date rangeinterval('2024-01-01', '2024-01-31', {interval: 'D'})
timeDiffCalculate time differencetimeDiff(date1, date2){value: 5, unit: 'DAY'}

Random Utilities

Random generation, shuffling, and sampling.

See Random Examples for detailed usage.

UtilityDescriptionExample
randomRandom number in rangerandom(1, 10)7
drawRandom array elementdraw([1,2,3])2
shuffleShuffle arrayshuffle([1,2,3])[3,1,2]
uuidGenerate UUID v4uuid()'550e8400-...'

Typed Utilities

Comprehensive type guards and runtime type checking.

See Typed Examples for detailed usage.

Type Guards

UtilityDescriptionTypeScript Narrowing
isStringCheck if stringunknownstring
isNumberCheck if numberunknownnumber
isBooleanCheck if booleanunknownboolean
isArrayCheck if arrayunknownArray<unknown>
isObjectCheck if objectunknownobject
isFunctionCheck if functionunknownFunction
isDateCheck if DateunknownDate
isRegexCheck if RegExpunknownRegExp
isPromiseCheck if PromiseunknownPromise<unknown>
isDefinedCheck if not null/undefinedTNonNullable<T>
isNilCheck if null or undefinedunknownnull | undefined
isPrimitiveCheck if primitive typeunknownboolean

Value Checks

UtilityDescriptionExample
isEmptyCheck if emptyisEmpty([])true
isEqualDeep equality comparisonisEqual({a:1}, {a:1})true
isMatchPattern matchingisMatch(obj, {role: 'admin'})
isWithinCheck if number in rangeisWithin(5, 0, 10)true
isEvenCheck if even numberisEven(4)true
isOddCheck if odd numberisOdd(3)true
isPositiveCheck if positiveisPositive(5)true
isNegativeCheck if negativeisNegative(-5)true
isZeroCheck if zeroisZero(0)true

Comparison

UtilityDescriptionExample
gtGreater thangt(5, 3)true
geGreater or equalge(5, 5)true
ltLess thanlt(3, 5)true
leLess or equalle(5, 5)true

Multi-Purpose

UtilityDescriptionExample
isMulti-purpose type checkeris('string', val)boolean
typeOfGet type of valuetypeOf([])'array'

Import Reference

ts
// Best for tree-shaking
import { map, filter, group } from '@vielzeug/toolkit';

Category Imports

ts
import { chunk, map } from '@vielzeug/toolkit/array';
import { merge, clone } from '@vielzeug/toolkit/object';
import { camelCase } from '@vielzeug/toolkit/string';
import { debounce } from '@vielzeug/toolkit/function';
import { sum, average } from '@vielzeug/toolkit/math';
import { interval } from '@vielzeug/toolkit/date';
import { random, uuid } from '@vielzeug/toolkit/random';
import { isString, isArray } from '@vielzeug/toolkit/typed';

See Also


Note: All utilities throw TypeError for invalid inputs. Check individual utility docs for specific error conditions and edge cases.