midash

Npm Versionopen in new windowNode VersionType SupportTree Shaking SupportNpm Month DownloadsGzip Size

An alternative to lodash with the same API, plus additional async utilities.

  • 🔨 High frequency API
  • 🕒 Familiar lodash API
  • 💪 Support Tree Shaking
  • 👫 Support Typescript
  • 🔥 Smaller Size (with ES6+ API)
  • 📦 2.5kb mini library
  • 🚀 Additional async utilities

API

Documentationopen in new window 中文文档open in new window

Installation

# yarn
$ yarn add midash
# pnpm
$ pnpm i midash
import { sum } from 'midash'

sum([1, 3, 5, 7, 9])

Async Utilities

Midash provides several async utilities:

  • sleep(ms): Pause execution for a specified number of milliseconds.
  • retry(fn, options): Retry a function multiple times with customizable options.
  • map(iterable, mapper, options): Asynchronously map over an iterable with concurrency control.
  • filter(iterable, filterer, options): Asynchronously filter an iterable with concurrency control.

Example usage:

import { sleep, retry, map, filter } from 'midash'

// Sleep for 1 second
await sleep(1000)

// Retry a function up to 3 times
const result = await retry(async () => {
  // Your async operation here
}, { times: 3 })

// Asynchronously map over an array with a concurrency of 2
const mappedResults = await map([1, 2, 3, 4], async (num) => {
  await sleep(100)
  return num * 2
}, { concurrency: 2 })

// Asynchronously filter an array
const filteredResults = await filter([1, 2, 3, 4, 5], async (num) => {
  await sleep(100)
  return num % 2 === 0
})