utils-sdk-0xfff
v1.0.0
Published
A useful utility library with common helper functions
Maintainers
Readme
utils-sdk-0xfff
A comprehensive utility library with common helper functions for TypeScript/JavaScript projects.
Installation
npm install utils-sdk-0xfffFeatures
- 🎯 TypeScript Support - Full TypeScript definitions included
- 📦 Tree-shakeable - Only import what you need
- ⚡ Zero Dependencies - Lightweight and fast
- 🔧 Comprehensive - String, Array, Object, and Async utilities
Usage
String Utilities
import { capitalize, toCamelCase, toKebabCase, truncate, isEmail } from 'utils-sdk-0xfff';
capitalize('hello'); // 'Hello'
toCamelCase('hello world'); // 'helloWorld'
toKebabCase('helloWorld'); // 'hello-world'
truncate('This is a long text', 10); // 'This is...'
isEmail('[email protected]'); // trueArray Utilities
import { unique, chunk, shuffle, groupBy, sum, average } from 'utils-sdk-0xfff';
unique([1, 2, 2, 3]); // [1, 2, 3]
chunk([1, 2, 3, 4, 5], 2); // [[1, 2], [3, 4], [5]]
shuffle([1, 2, 3, 4]); // Random order
groupBy([{type: 'a', val: 1}, {type: 'b', val: 2}], item => item.type);
sum([1, 2, 3, 4]); // 10
average([1, 2, 3, 4]); // 2.5Object Utilities
import { deepClone, pick, omit, deepMerge, isEmpty } from 'utils-sdk-0xfff';
const obj = { a: 1, b: { c: 2 } };
deepClone(obj); // Deep copy
pick(obj, ['a']); // { a: 1 }
omit(obj, ['a']); // { b: { c: 2 } }
deepMerge({ a: 1 }, { b: 2 }); // { a: 1, b: 2 }
isEmpty({}); // trueAsync Utilities
import { sleep, retry, parallel, debounce } from 'utils-sdk-0xfff';
await sleep(1000); // Wait 1 second
// Retry with exponential backoff
await retry(async () => {
// Your async operation
}, { maxRetries: 3, delayMs: 1000, backoff: 2 });
// Run tasks in parallel with concurrency limit
await parallel([task1, task2, task3], 2);
// Debounce function calls
const debouncedFn = debounce(() => console.log('Called'), 300);API Reference
String Functions
capitalize(str: string): string- Capitalizes first lettertoCamelCase(str: string): string- Converts to camelCasetoKebabCase(str: string): string- Converts to kebab-casetruncate(str: string, length: number, suffix?: string): string- Truncates stringisEmail(str: string): boolean- Validates email format
Array Functions
unique<T>(arr: T[]): T[]- Removes duplicateschunk<T>(arr: T[], size: number): T[][]- Splits into chunksshuffle<T>(arr: T[]): T[]- Randomly shufflesgroupBy<T>(arr: T[], keyFn: (item: T) => string | number): Record<string | number, T[]>- Groups by keysum(arr: number[]): number- Sums numbersaverage(arr: number[]): number- Calculates average
Object Functions
deepClone<T>(obj: T): T- Deep clones objectpick<T, K>(obj: T, keys: K[]): Pick<T, K>- Picks keysomit<T, K>(obj: T, keys: K[]): Omit<T, K>- Omits keysdeepMerge<T>(...objects: Partial<T>[]): T- Deep merges objectsisEmpty(obj: object): boolean- Checks if empty
Async Functions
sleep(ms: number): Promise<void>- Delays executionretry<T>(fn: () => Promise<T>, options?): Promise<T>- Retries with backoffparallel<T>(tasks: (() => Promise<T>)[], concurrency?: number): Promise<T[]>- Parallel executiondebounce<T>(fn: T, delayMs: number): T- Debounces function
Building
npm install
npm run buildPublishing
npm publish --access publicLicense
MIT
