node-filter-async
v3.0.0
Published
Filter array elements with Promises
Downloads
54,963
Readme
node-filter-async
Filter array elements with Promises, zero dependencies, written in TypeScript.
Installation
npm i node-filter-async
Usage
API
filterAsync<T>(
// The array to be filtered.
array: T[],
// The async filter callback.
callback: (value: T, index: number) => Promise<boolean>,
): Promise<T[]>;
Example:
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';
});
})();