A modern, lightweight, and type-safe utility library for TypeScript and JavaScript. Built as a modern alternative to lodash with zero dependencies, full ESM support, and comprehensive TypeScript types.
- π― Type-Safe: Full TypeScript support with comprehensive type definitions
- π¦ Tree-Shakeable: ESM support for optimal bundle sizes
- π Dual Format: Both ESM and CommonJS builds included
- β Well-Tested: 230+ tests with comprehensive coverage
- π Zero Dependencies: No external runtime dependencies
- π 85+ Utilities: Comprehensive collection across 8 categories
npm install dashliteimport { chunk, debounce, pick, add, max, groupBy, delay } from 'dashlite'
// Array manipulation
const chunks = chunk([1, 2, 3, 4, 5], 2)
// => [[1, 2], [3, 4], [5]]
// Collection operations
const users = [
{ name: 'Alice', role: 'admin' },
{ name: 'Bob', role: 'user' },
{ name: 'Charlie', role: 'admin' }
]
const grouped = groupBy(users, 'role')
// => { admin: [...], user: [...] }
// Async utilities
await delay(1000)
console.log('After 1 second')
// Object manipulation
const picked = pick({ a: 1, b: 2, c: 3 }, ['a', 'c'])
// => { a: 1, c: 3 }
// Function utilities
const debouncedLog = debounce((msg: string) => console.log(msg), 1000)
debouncedLog('Hello')
// Math operations
const total = add(5, 3)
// => 8
const maximum = max([1, 5, 3, 9, 2])
// => 9Transformation & Manipulation:
chunk(array, size)- Split arrays into chunks of specified sizecompact(array)- Remove all falsy values (false, null, 0, "", undefined, NaN)flatten(array)- Flatten array a single level deepflattenDeep(array)- Recursively flatten array to a single levelflattenDepth(array, depth)- Flatten array up to specified depthuniq(array)- Create duplicate-free arrayuniqBy(array, iteratee)- Create duplicate-free array using comparator functionfill(array, value, start, end)- Fill array elements with valuereverse(array)- Reverse array in placeslice(array, start, end)- Create slice of array
Search & Access:
findIndex(array, predicate)- Find index of first element matching predicatefindLastIndex(array, predicate)- Find index from right to leftfirst(array)- Get first element of arraylast(array)- Get last element of arrayindexOf(array, value)- Get index of valuelastIndexOf(array, value)- Get last index of value
Sorted Array Operations:
sortedIndex(array, value)- Binary search for insertion indexsortedIndexBy(array, value, iteratee)- Binary search with iterateesortedIndexOf(array, value)- Binary search for valuesortedLastIndex(array, value)- Find highest insertion indexsortedUniq(array)- Remove duplicates from sorted arraysortedUniqBy(array, iteratee)- Remove duplicates with iteratee
Array Manipulation:
take(array, n)- Take n elements from beginningtakeRight(array, n)- Take n elements from endtakeWhile(array, predicate)- Take elements while predicate returns truetakeRightWhile(array, predicate)- Take elements from end while predicate returns truedrop(array, n)- Drop n elements from beginningdropRight(array, n)- Drop n elements from endtail(array)- Get all but first elementinitial(array)- Get all but last elementpull(array, ...values)- Remove specified valuespullAt(array, indexes)- Remove elements at indexesfromPairs(pairs)- Create object from key-value pairstoPairs(object)- Create array of key-value pairs
Delay & Control:
// Delay execution
await delay(1000, 'result')
await sleep(2000)
// Retry failed operations with exponential backoff
const data = await retry(
async () => await fetchData(),
{ retries: 3, delay: 1000, backoff: 2 }
)
// Add timeout to promises
const result = await timeout(
fetch('https://api.example.com'),
5000
)Concurrent Execution:
// Run tasks in parallel with concurrency limit
const results = await parallel([
() => fetchUser(1),
() => fetchUser(2),
() => fetchUser(3)
], 2) // Max 2 concurrent
// Run tasks in series (sequential)
await series([
() => step1(),
() => step2(),
() => step3()
])
// Pass results through async pipeline
const result = await waterfall([
async (data) => processStep1(data),
async (result) => processStep2(result),
async (result) => processStep3(result)
], initialData)
// Race multiple promises
const fastest = await race([
fetch('https://api1.com'),
fetch('https://api2.com')
])
// Wait for all to settle (fulfilled or rejected)
const results = await allSettled([
Promise.resolve(1),
Promise.reject('error'),
Promise.resolve(3)
])Grouping & Counting:
// Group items by criteria
const users = [
{ name: 'Alice', role: 'admin' },
{ name: 'Bob', role: 'user' },
{ name: 'Charlie', role: 'admin' }
]
groupBy(users, 'role')
// => { admin: [...], user: [...] }
// Create object indexed by key
keyBy(users, 'name')
// => { Alice: {...}, Bob: {...}, Charlie: {...} }
// Count occurrences
countBy([6.1, 4.2, 6.3], Math.floor)
// => { 4: 1, 6: 2 }Sorting & Filtering:
// Multi-field sorting
const products = [
{ name: 'Phone', category: 'Electronics', price: 699 },
{ name: 'Laptop', category: 'Electronics', price: 1299 },
{ name: 'Desk', category: 'Furniture', price: 299 }
]
orderBy(products, ['category', 'price'], ['asc', 'desc'])
// Partition into two groups
const [active, inactive] = partition(users, u => u.active)
// Check conditions
every([1, 2, 3], n => n > 0) // => true
some([1, 2, 3], n => n > 2) // => true
includes([1, 2, 3], 2) // => trueSampling:
// Get random element
const winner = sample(['Alice', 'Bob', 'Charlie'])
// Get multiple random elements
const winners = sampleSize(participants, 3)
// Shuffle array
const shuffled = shuffle([1, 2, 3, 4, 5])// Pick specific properties from object
const user = { id: 1, name: 'John', email: 'john@example.com', age: 30 }
pick(user, ['id', 'name'])
// => { id: 1, name: 'John' }
// Omit specific properties from object
omit(user, ['email', 'age'])
// => { id: 1, name: 'John' }
// Deep merge objects
merge({ a: { b: 1 } }, { a: { c: 2 } })
// => { a: { b: 1, c: 2 } }
// Deep clone objects (supports Date, RegExp, Map, Set)
const cloned = clone({ a: 1, b: { c: 2 } })// Case conversions
capitalize('hello world') // => 'Hello world'
camelCase('foo-bar-baz') // => 'fooBarBaz'
kebabCase('fooBarBaz') // => 'foo-bar-baz'
// Truncate long strings
truncate('hi-diddly-ho there, neighborino', { length: 24 })
// => 'hi-diddly-ho there, n...'// Debounce: Delay execution until after wait time
const saveData = debounce((data) => api.save(data), 1000)
saveData(data) // Only executes after 1000ms of inactivity
// Throttle: Execute at most once per time period
const handleScroll = throttle(() => updateUI(), 200)
window.addEventListener('scroll', handleScroll)
// Memoize: Cache function results
const fibonacci = memoize((n) => {
if (n <= 1) return n
return fibonacci(n - 1) + fibonacci(n - 2)
})Arithmetic Operations:
add(6, 4) // => 10
subtract(6, 4) // => 2
multiply(6, 4) // => 24
divide(6, 4) // => 1.5Rounding:
ceil(4.006) // => 5
ceil(6.004, 2) // => 6.01
floor(4.006) // => 4
floor(0.046, 2) // => 0.04
round(4.006) // => 4
round(4.006, 2) // => 4.01Aggregation:
sum([1, 2, 3, 4]) // => 10
sumBy(objects, o => o.value) // Sum by property
mean([1, 2, 3, 4]) // => 2.5
meanBy(objects, o => o.value) // Average by property
min([4, 2, 8, 6]) // => 2
minBy(objects, o => o.value) // Find min by property
max([4, 2, 8, 6]) // => 8
maxBy(objects, o => o.value) // Find max by property// Type checking with TypeScript type guards
isArray([1, 2, 3]) // => true (narrows type to any[])
isObject({ a: 1 }) // => true (narrows type to Record)
isEmpty([]) // => true
isEmpty({}) // => true
isEmpty(null) // => true- Modern: Built for modern JavaScript/TypeScript with ES2015+ features
- Lightweight: No dependencies, smaller bundle size than lodash
- Type-Safe: First-class TypeScript support with full type inference
- Tree-Shakeable: Import only what you need with ESM support
- Fast: Optimized implementations with comprehensive test coverage
- Developer-Friendly: Clean API, well-documented, easy to use
- Async-Ready: Built-in utilities for promises, retries, and concurrent operations
- Data-Focused: Powerful collection utilities for grouping, sorting, and sampling
- Web Applications: React, Vue, Angular, Svelte projects
- Node.js: Backend services, APIs, CLI tools
- TypeScript Projects: Full type safety and IntelliSense support
- Performance-Critical: Zero dependencies, optimized algorithms
- Bundle Size Matters: Tree-shakeable, import only what you need
- Async Operations: Built-in retry logic, timeouts, parallel execution
- Data Processing: Group, sort, and transform collections efficiently
| Feature | dashlite | lodash |
|---|---|---|
| Bundle Size | ~20KB | ~70KB |
| Dependencies | 0 | 0 |
| TypeScript | Native | @types package |
| ESM Support | β Native | β Via lodash-es |
| Tree Shaking | β Excellent | |
| Modern JS | β ES2015+ | |
| Async Utilities | β Built-in | β Separate lib |
| Collection Utils | β 12 functions | β Similar |
For full API reference and interactive examples, visit our documentation site: https://dashlite-ten.vercel.app/
MIT Β© Safwan