0.1.0 • Published 8 years ago

serial-filter v0.1.0

Weekly downloads
4
License
MIT
Repository
github
Last release
8 years ago

Serial filter

Serial asynchronous version of Array#filter, with promised based interface.

Installation

npm install --save serial-filter

Usage

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 to true to keep the element, false otherwise.

  • thisArg Optional. Value to use as this when executing callback.

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