waiteach
v1.2.1
Published
A modern async forEach utility for JavaScript/TypeScript.
Downloads
6
Maintainers
Readme
waitEach
A modern, lightweight async forEach utility for JavaScript and TypeScript.
waitEach enables asynchronous iteration over arrays with await support. It can be used as a standalone function or globally installed on Array.prototype for more convenient syntax in both Node.js and browser environments.
Features
- ✅ Asynchronous
forEachwithawaitsupport - ✅ Works in Node.js and browser environments
- ✅ Optional global installation via
Array.prototype.waitEach - ✅ Fully typed for TypeScript
- ✅ Tiny and dependency-free
Installation
npm install waitEach
# or
yarn add waitEachUsage
Using as a standalone function
import { waitEach } from 'waitEach';
const numbers = [1, 2, 3];
await waitEach(numbers, async (num) => {
await new Promise(resolve => setTimeout(resolve, 500));
console.log(num);
});
console.log('Done!');Installing globally on Array.prototype
import { install } from 'waitEach';
// Install globally
install();
const numbers = [1, 2, 3];
await numbers.waitEach(async (num) => {
await new Promise(resolve => setTimeout(resolve, 500));
console.log(num);
});
console.log('Done!');TypeScript Support
waitEach is fully typed. If you use the install() method, TypeScript will recognize waitEach on all arrays automatically.
License
MIT License
