@rabjs/kit
v0.0.3
Published
A comprehensive TypeScript utility library with 100+ helper functions for arrays, objects, strings, functions, numbers, dates, promises, and more. Similar to lodash but with full TypeScript support and tree-shaking friendly.
Readme
@rabjs/kit
A comprehensive TypeScript utility library with 100+ helper functions for arrays, objects, strings, functions, numbers, dates, promises, and more. Similar to lodash but with full TypeScript support and tree-shaking friendly.
Features
- TypeScript First: Complete type definitions with full TypeScript support
- Tree-shaking Friendly: Only import what you need, reduce bundle size
- High Test Coverage: 90%+ test coverage with 675+ test cases
- Multiple Module Formats: CommonJS and ES Module support
- Modern Tooling: Built with Rollup, tested with Jest
- 100+ Functions: Comprehensive utility library across 10+ categories
Installation
npm install @rabjs/kit
# or
yarn add @rabjs/kit
# or
pnpm add @rabjs/kitQuick Start
Import Everything
import * as kit from '@rabjs/kit';
kit.chunk([1, 2, 3, 4, 5], 2); // [[1, 2], [3, 4], [5]]
kit.debounce(() => console.log('hello'), 300);Import Specific Functions
import { chunk, debounce } from '@rabjs/kit';
chunk([1, 2, 3, 4, 5], 2); // [[1, 2], [3, 4], [5]]
debounce(() => console.log('hello'), 300);Import from Submodules
import { chunk } from '@rabjs/kit/array';
import { debounce } from '@rabjs/kit/function';
chunk([1, 2, 3, 4, 5], 2);
debounce(() => console.log('hello'), 300);API Documentation
Array Functions
chunk(array, size)- Split array into chunkscompact(array)- Remove falsy valuesflatten(array, depth)- Flatten arrayflattenDeep(array)- Deep flattenuniq(array)- Remove duplicatesuniqBy(array, iteratee)- Remove duplicates by conditiondifference(...arrays)- Get differenceintersection(...arrays)- Get intersectionunion(...arrays)- Get union- And more...
Object Functions
clone(obj)- Shallow clonecloneDeep(obj)- Deep clonemerge(target, ...sources)- Merge objectsmergeDeep(target, ...sources)- Deep mergepick(obj, keys)- Pick propertiesomit(obj, keys)- Omit propertiesget(obj, path, defaultValue)- Safe getset(obj, path, value)- Safe set- And more...
String Functions
camelCase(str)- Convert to camelCasekebabCase(str)- Convert to kebab-casesnakeCase(str)- Convert to snake_casepascalCase(str)- Convert to PascalCasecapitalize(str)- Capitalize stringtrim(str, chars)- Trim characterstruncate(str, options)- Truncate string- And more...
Function Utilities
debounce(func, wait, options)- Debounce functionthrottle(func, wait, options)- Throttle functiononce(func)- Execute oncememoize(func, resolver)- Cache resultscurry(func, arity)- Curry functioncompose(...funcs)- Compose functionspipe(...funcs)- Pipe functions- And more...
Number Functions
clamp(number, lower, upper)- Clamp numberrandom(lower, upper, floating)- Generate random numberround(number, precision)- Round numbersum(numbers)- Sum arraymean(numbers)- Averagemedian(numbers)- Medianrange(start, end, step)- Generate range- And more...
Type Checking
isArray(value)- Check if arrayisObject(value)- Check if objectisString(value)- Check if stringisNumber(value)- Check if numberisFunction(value)- Check if functionisPromise(value)- Check if promise- And more (20+ type checkers)...
Date Functions
format(date, formatStr)- Format dateparse(dateStr, formatStr)- Parse dateaddDays(date, amount)- Add daysdiffDays(date1, date2)- Difference in days- And more...
Promise Utilities
delay(ms, value)- Delay executionretry(fn, options)- Retry functiontimeout(promise, ms, message)- Promise timeoutparallel(tasks, concurrency)- Run in parallelseries(tasks)- Run in series- And more...
Collection Operations
groupBy(collection, iteratee)- Group by propertykeyBy(collection, iteratee)- Create key-value mapsortBy(collection, iteratees)- Sort collectionpartition(collection, predicate)- Partition collectioncountBy(collection, iteratee)- Count by property- And more...
Math Functions
max(numbers)- Get maximummin(numbers)- Get minimummaxBy(array, iteratee)- Get max by conditionminBy(array, iteratee)- Get min by condition- And more...
Usage Examples
Array Operations
import { chunk, compact, flatten, uniq } from '@rabjs/kit';
// Chunk array
chunk([1, 2, 3, 4, 5], 2); // [[1, 2], [3, 4], [5]]
// Remove falsy values
compact([0, 1, false, 2, '', 3]); // [1, 2, 3]
// Flatten array
flatten(
[
[1, 2],
[3, [4, 5]],
],
1,
); // [1, 2, 3, [4, 5]]
// Remove duplicates
uniq([1, 2, 2, 3, 3, 3]); // [1, 2, 3]Object Operations
import { get, set, pick, omit, merge } from '@rabjs/kit';
const obj = { a: { b: { c: 1 } } };
// Safe get
get(obj, 'a.b.c'); // 1
get(obj, 'a.x.y', 'default'); // 'default'
// Safe set
set(obj, 'a.b.d', 2); // { a: { b: { c: 1, d: 2 } } }
// Pick properties
pick(obj, ['a']); // { a: { b: { c: 1 } } }
// Omit properties
omit(obj, ['a']); // {}
// Merge objects
merge({ a: 1 }, { b: 2 }); // { a: 1, b: 2 }Function Utilities
import { debounce, throttle, once } from '@rabjs/kit';
// Debounce
const handleSearch = debounce((query) => {
console.log('Searching for:', query);
}, 300);
// Throttle
const handleScroll = throttle(() => {
console.log('Scrolling...');
}, 1000);
// Execute once
const handleInit = once(() => {
console.log('Initializing...');
});String Operations
import { camelCase, kebabCase, capitalize } from '@rabjs/kit';
camelCase('hello-world'); // 'helloWorld'
kebabCase('helloWorld'); // 'hello-world'
capitalize('hello'); // 'Hello'Browser Support
- Chrome >= 70
- Safari >= 12
- Firefox >= 65
- Edge >= 79
Node.js Support
- Node.js >= 12
Contributing
We welcome contributions! Please read our contributing guidelines to get started.
License
MIT
Changelog
See CHANGELOG.md for detailed version history.
