3.0.0 • Published 3 years ago

node-filter-async v3.0.0

Weekly downloads
3,331
License
MIT
Repository
github
Last release
3 years ago

node-filter-async

Build Status npm version Node.js Version

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';
  });
})();