All files async-filter.js

100% Statements 6/6
100% Branches 1/1
100% Functions 1/1
100% Lines 6/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 301x 1x                           11x 10x   9x                   1x  
const { mapIterable, filterIterable } = require('./helpers'),
	{ validateIsIterable, validateIsFunction } = require('./validation');
 
/**
 * Async Filter
 *
 * Filter asynchronously and resolve when all callbacks are resolved
 * @async
 * @param {any[]} iterable
 * @param {Function} callback - callback(currentValue, index, array)
 * @param {any} [thisArg=undefined]
 * @return {Promise<any[]>}
 * @throws {TypeError}
 */
async function asyncFilter(iterable, callback, thisArg = undefined) {
	validateIsIterable(iterable);
	validateIsFunction(callback);
 
	return filterIterable(
		iterable,
		await Promise.all(
			mapIterable(iterable, callback.bind(thisArg), {
				useEmptyElements: false
			})
		)
	);
}
 
module.exports = { asyncFilter };