@dependabit/utils
v0.1.14
Published
Utility functions for the monorepo
Downloads
246
Readme
@dependabit/utils
String and array utility functions for the monorepo.
Features
- String manipulation - capitalize, camelCase, kebabCase, truncate
- Array operations - unique, groupBy, flatten, chunk
- Type-safe - Full TypeScript support
- No dependencies - Pure functional utilities
Installation
pnpm add @dependabit/utilsUsage
String Utilities
import { capitalize, camelCase, kebabCase, truncate } from '@dependabit/utils/string';
capitalize('hello'); // 'Hello'
camelCase('hello-world'); // 'helloWorld'
kebabCase('HelloWorld'); // 'hello-world'
truncate('Hello World', 8); // 'Hello...'Array Utilities
import { unique, groupBy, flatten, chunk } from '@dependabit/utils/array';
unique([1, 2, 2, 3]); // [1, 2, 3]
groupBy([1, 2, 3], n => n % 2); // { 0: [2], 1: [1, 3] }
flatten([[1, [2, 3]]], 1); // [1, [2, 3]]
chunk([1, 2, 3, 4, 5], 2); // [[1, 2], [3, 4], [5]]Sub-paths
You can import specific modules:
// Import only string utilities
import { capitalize } from '@dependabit/utils/string';
// Import only array utilities
import { unique } from '@dependabit/utils/array';
// Import everything
import { capitalize, unique } from '@dependabit/utils';API
String Module
capitalize(str: string): string- Capitalize first lettercamelCase(str: string): string- Convert to camelCasekebabCase(str: string): string- Convert to kebab-casetruncate(str: string, maxLength: number, suffix?: string): string- Truncate with suffix
Array Module
unique<T>(arr: T[]): T[]- Remove duplicatesgroupBy<T, K>(arr: T[], keyFn: (item: T) => K): Record<K, T[]>- Group by keyflatten<T>(arr: Array<T | T[]>, depth?: number): T[]- Flatten nested arrayschunk<T>(arr: T[], size: number): T[][]- Split into chunks
Testing
# Run tests for this package
pnpm --filter @dependabit/utils test
# Watch mode
pnpm --filter @dependabit/utils test:watch
# Coverage
pnpm --filter @dependabit/utils test:coveragePerformance
All functions are optimized for:
- Time complexity O(n) or O(n log n)
- Minimal memory allocations
- No external dependencies
License
MIT
