Skip to content

Latest commit

Β 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

dashlite

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.

πŸ“š Read the Documentation

Features

  • 🎯 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

Installation

npm install dashlite

Quick Start

import { 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])
// => 9

Core Utilities

πŸ“š Array Utilities (34 functions)

Transformation & Manipulation:

  • chunk(array, size) - Split arrays into chunks of specified size
  • compact(array) - Remove all falsy values (false, null, 0, "", undefined, NaN)
  • flatten(array) - Flatten array a single level deep
  • flattenDeep(array) - Recursively flatten array to a single level
  • flattenDepth(array, depth) - Flatten array up to specified depth
  • uniq(array) - Create duplicate-free array
  • uniqBy(array, iteratee) - Create duplicate-free array using comparator function
  • fill(array, value, start, end) - Fill array elements with value
  • reverse(array) - Reverse array in place
  • slice(array, start, end) - Create slice of array

Search & Access:

  • findIndex(array, predicate) - Find index of first element matching predicate
  • findLastIndex(array, predicate) - Find index from right to left
  • first(array) - Get first element of array
  • last(array) - Get last element of array
  • indexOf(array, value) - Get index of value
  • lastIndexOf(array, value) - Get last index of value

Sorted Array Operations:

  • sortedIndex(array, value) - Binary search for insertion index
  • sortedIndexBy(array, value, iteratee) - Binary search with iteratee
  • sortedIndexOf(array, value) - Binary search for value
  • sortedLastIndex(array, value) - Find highest insertion index
  • sortedUniq(array) - Remove duplicates from sorted array
  • sortedUniqBy(array, iteratee) - Remove duplicates with iteratee

Array Manipulation:

  • take(array, n) - Take n elements from beginning
  • takeRight(array, n) - Take n elements from end
  • takeWhile(array, predicate) - Take elements while predicate returns true
  • takeRightWhile(array, predicate) - Take elements from end while predicate returns true
  • drop(array, n) - Drop n elements from beginning
  • dropRight(array, n) - Drop n elements from end
  • tail(array) - Get all but first element
  • initial(array) - Get all but last element
  • pull(array, ...values) - Remove specified values
  • pullAt(array, indexes) - Remove elements at indexes
  • fromPairs(pairs) - Create object from key-value pairs
  • toPairs(object) - Create array of key-value pairs

⏳ Async Utilities (9 functions)

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)
])

πŸ—‚οΈ Collection Utilities (12 functions)

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)        // => true

Sampling:

// 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])

πŸ”§ Object Utilities (4 functions)

// 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 } })

✏️ String Utilities (4 functions)

// 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...'

⚑ Function Utilities (3 functions)

// 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)
})

πŸ”’ Math Utilities (15 functions)

Arithmetic Operations:

add(6, 4)        // => 10
subtract(6, 4)   // => 2
multiply(6, 4)   // => 24
divide(6, 4)     // => 1.5

Rounding:

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.01

Aggregation:

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 Utilities (3 functions)

// 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

Why dashlite?

  • 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

Use Cases

  • 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

Comparison with Lodash

Feature dashlite lodash
Bundle Size ~20KB ~70KB
Dependencies 0 0
TypeScript Native @types package
ESM Support βœ… Native βœ… Via lodash-es
Tree Shaking βœ… Excellent ⚠️ Requires lodash-es
Modern JS βœ… ES2015+ ⚠️ ES5 compatible
Async Utilities βœ… Built-in ❌ Separate lib
Collection Utils βœ… 12 functions βœ… Similar

Documentation

For full API reference and interactive examples, visit our documentation site: https://dashlite-ten.vercel.app/

License

MIT Β© Safwan

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages