node-filter-async
Version:
Filter array elements with Promises
40 lines (29 loc) • 1.03 kB
Markdown
# node-filter-async
[](https://github.com/mgenware/node-filter-async/actions)
[](https://npmjs.com/package/node-filter-async)
[](https://nodejs.org/en/)
Filter array elements with Promises, zero dependencies, written in TypeScript.
### Installation
```bash
npm i node-filter-async
```
## Usage
### API
```javascript
filterAsync<T>(
// The array to be filtered.
array: T[],
// The async filter callback.
callback: (value: T, index: number) => Promise<boolean>,
): Promise<T[]>;
```
Example:
```js
import filterAsync from 'node-filter-async';
(async () => {
const results = await filterAsync(someArray, async (value, index) => {
console.log(`filtering [${index}]: ${value}`);
return (await asyncFunc(value)) === 'blablabla';
});
})();
```