0.1.0 • Published 9 years ago
serial-filter v0.1.0
Serial filter
Serial asynchronous version of Array#filter, with promised based interface.
Installation
npm install --save serial-filterUsage
const got = require('got')
const filter = require('serial-filter')
filter([1, 2, 3, 4], n => {
return got(`http://is-number-even.com/${n}`, { json: true }).then(res => res.body)
}).then(result => {
console.log(result)
//=> 2, 4
})API
filter(arr, callback, thisArg)
Returns a promise of a new array with all elements that pass the asynchronous test implemented by the provided function.
arr Array that will be filtered.
callback Function to test each element of the array. Invoked with
(element, index, array). Return a promise that resolves totrueto keep the element,falseotherwise.thisArg Optional. Value to use as
thiswhen executingcallback.
If any promise provided by the callback rejects, the promise returned will
immediately reject with that rejection.
See also
- parallel-filter - Parallel asynchronous version of Array#filter, with promised based interface
0.1.0
9 years ago