utilstrust
v0.1.0
Published
A lightweight, typed utility belt for modern TypeScript — arrays, objects, strings, functions, math & type checks. Zero dependencies.
Maintainers
Readme
utilstrust
Zero-dependency, tree-shakeable, TypeScript-first utility library inspired by Lodash.
Installation
npm install utilstrust
# or
pnpm add utilstrust
# or
yarn add utilstrustFeatures
- Zero dependencies — lightweight and self-contained
- Tree-shakeable — import only what you need via sub-path exports
- TypeScript-first — fully typed with generics and type guards
- Dual format — ships ESM and CJS builds
- 108+ utility functions across 6 categories
Usage
// Import everything
import { chunk, camelCase, debounce, isEmpty, clamp } from 'utilstrust';
// Or use sub-path imports for smaller bundles
import { chunk, groupBy, sortBy } from 'utilstrust/array';
import { pick, omit, deepClone } from 'utilstrust/object';
import { camelCase, kebabCase, slugify } from 'utilstrust/string';
import { debounce, throttle, memoize } from 'utilstrust/function';
import { isEmpty, isPlainObject, typeOf } from 'utilstrust/is';
import { clamp, sum, median } from 'utilstrust/math';API Reference
Array (utilstrust/array)
| Function | Description |
|---|---|
| chunk(arr, size) | Split array into chunks of size |
| compact(arr) | Remove falsy values |
| flatten(arr) | Flatten one level |
| flattenDeep(arr) | Recursively flatten |
| unique(arr) | Remove duplicates |
| uniqueBy(arr, fn) | Remove duplicates by key function |
| groupBy(arr, fn) | Group elements by key function |
| countBy(arr, fn) | Count elements by key function |
| sortBy(arr, fn) | Sort by key function (returns new array) |
| keyBy(arr, fn) | Index elements by key function |
| partition(arr, fn) | Split into [truthy, falsy] |
| intersection(...arrs) | Elements common to all arrays |
| difference(arr, ...others) | Elements in first array not in others |
| union(...arrs) | Unique elements across all arrays |
| first(arr) / last(arr) | First/last element |
| sample(arr) | Random element |
| shuffle(arr) | Fisher-Yates shuffle (new array) |
| take(arr, n) / drop(arr, n) | First n / skip first n elements |
| zip(...arrs) / unzip(arr) | Zip/unzip arrays |
| range(start, end, step) | Generate number range |
Object (utilstrust/object)
| Function | Description |
|---|---|
| pick(obj, keys) | Pick specified keys |
| omit(obj, keys) | Omit specified keys |
| merge(target, ...sources) | Shallow merge |
| deepMerge(target, ...sources) | Deep recursive merge |
| deepClone(value) | Deep clone via structuredClone |
| get(obj, path, default?) | Get nested value by dot path |
| set(obj, path, value) | Set nested value by dot path |
| has(obj, path) | Check if nested path exists |
| entries(obj) / fromEntries(entries) | Typed Object.entries/fromEntries |
| mapValues(obj, fn) | Map over object values |
| mapKeys(obj, fn) | Map over object keys |
| filterObj(obj, fn) | Filter object entries |
| invert(obj) | Swap keys and values |
| freeze(obj) | Deep freeze object |
String (utilstrust/string)
| Function | Description |
|---|---|
| capitalize(str) / uncapitalize(str) | Capitalize/uncapitalize first letter |
| camelCase(str) | fooBar |
| pascalCase(str) | FooBar |
| snakeCase(str) | foo_bar |
| kebabCase(str) | foo-bar |
| constantCase(str) | FOO_BAR |
| titleCase(str) | Foo Bar |
| truncate(str, length, suffix?) | Truncate with ellipsis |
| padStart(str, len, char?) / padEnd(...) | Pad string |
| trim(str) / trimChar(str, char) | Trim whitespace or specific char |
| escapeHtml(str) / unescapeHtml(str) | HTML entity escaping |
| escapeRegExp(str) | Escape regex special chars |
| template(str, data) | Simple {{key}} template interpolation |
| slugify(str) | URL-safe slug |
| countOccurrences(str, sub) | Count substring occurrences |
Function (utilstrust/function)
| Function | Description |
|---|---|
| debounce(fn, ms) | Debounce with .cancel() |
| throttle(fn, ms) | Throttle with .cancel() |
| memoize(fn, keyFn?) | Memoize with .cache Map |
| once(fn) | Call function only once |
| delay(fn, ms, ...args) | Delayed invocation |
| pipe(...fns) / compose(...fns) | Function composition |
| noop / identity / constant(v) | Utility functions |
| negate(fn) | Negate a predicate |
| retry(fn, opts?) | Retry with exponential backoff |
| withTimeout(fn, ms) | Timeout wrapper |
| sleep(ms) | Promise-based delay |
Type Checking (utilstrust/is)
| Function | Description |
|---|---|
| isString / isNumber / isBoolean | Primitive type guards |
| isBigInt / isSymbol | Primitive type guards |
| isUndefined / isNull / isNil | Nullish checks |
| isFunction / isArray | Type guards |
| isObject / isPlainObject | Object checks (excludes arrays) |
| isDate / isRegExp / isError | Built-in object checks |
| isMap / isSet / isWeakMap / isWeakSet | Collection checks |
| isPromise | Promise-like check |
| isEmpty | Empty check for strings, arrays, objects, maps, sets |
| isInteger / isFinite / isNaN | Number checks |
| typeOf(value) | Enhanced typeof returning specific types |
Math (utilstrust/math)
| Function | Description |
|---|---|
| clamp(value, min, max) | Clamp to range |
| lerp(start, end, t) | Linear interpolation |
| mapRange(value, inMin, inMax, outMin, outMax) | Map between ranges |
| sum(arr) / average(arr) / median(arr) | Aggregations |
| min(arr) / max(arr) | Min/max of array |
| round(value, precision?) | Round to decimal places |
| randomInt(min, max) / randomFloat(min, max) | Random numbers |
| inRange(value, start, end) | Range check |
| toRadians(deg) / toDegrees(rad) | Angle conversion |
| percentage(value, total) | Percentage calculation |
| gcd(a, b) / lcm(a, b) | GCD / LCM |
| factorial(n) | Factorial |
License
MIT
