https://github.com/megaconfidence/async-iterator
Easy to use async forEach and map utility functions
https://github.com/megaconfidence/async-iterator
Last synced: 2 months ago
JSON representation
Easy to use async forEach and map utility functions
- Host: GitHub
- URL: https://github.com/megaconfidence/async-iterator
- Owner: megaconfidence
- License: mit
- Created: 2020-12-04T19:15:37.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2020-12-04T22:45:10.000Z (over 4 years ago)
- Last Synced: 2025-03-17T21:43:33.285Z (3 months ago)
- Language: JavaScript
- Size: 5.86 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: MIT-LICENSE.txt
Awesome Lists containing this project
README
# @cokoghenun/async-iterator
Easy to use async `forEach` and `map` utility functions
## Installation
```
$ npm install @cokoghenun/async-iterator
```## Features
- Async `forEach`
- Async `map`## Example
To use the async `map` utility, call the `asyncMap` method:
```js
const iterator = require('@cokoghenun/async-iterator');const myArray = ['1st async stuff to do', '2nd async stuff to do'];
const asyncGeneratedArray = await iterator.asyncMap(
myArray,
async (item, index, array) => {
// do async stuff here
return item;
}
);
```To use the async `forEach` utility, call the `asyncForEach` method:
```js
const iterator = require('@cokoghenun/async-iterator');const myArray = ['1st async stuff to do', '2nd async stuff to do'];
await iterator.asyncForEach(myArray, async (item, index, array) => {
// do async stuff here
});
```## API
```js
iterator.METHOD(ARRAY, CALLBACK(ITEM, INDEX, ARRAY));
```Where
- **iterator** is an instance of `@cokoghenun/async-iterator`
- **METHOD** is a utility function i.e `asyncMap` or `asyncForEach`
- **ARRAY** is the array to be operated on
- **CALLBACK** is an asynchronous funcion passed to the **METHOD** that returns
- **ITEM** which is the current item being looped over
- **INDEX** which is the index of **ITEM**
- **ARRAY** which is a copy of the original **ARRAY**## License
[MIT](./MIT-LICENSE.txt)