filter-async

1.0.0 • Public • Published

filter-async

https://travis-ci.org/sorribas/filter-async.svg?branch=master

Filter the elements of an array with an asynchronous predicate.

Usage

var filter = require('filter-async');
var fs = require('fs');
 
var isFile = function(file, callback) {
  fs.stat(file, function(err, stat) {
    if (err) return callback(err);
    cb(null, stat.isFile());
  });
};
 
filter(['some-file', 'some-other-file', 'some-directory'], isFile, function(err, files) {
  if (err) return console.log(err);
  console.log(files); // should print ['some-file, 'some-other-file'']
});

By default all the async predicates are run in a sequential manner, which means that elements of the array are processed one at a time. If you want to process them in parallel you can use the filter.parallel function. It has the same interface as the filter function.

The filter function is also aliased to filter.sequential.

License

MIT

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.0
    20
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.0
    20

Package Sidebar

Install

npm i filter-async

Weekly Downloads

20

Version

1.0.0

License

MIT

Last publish

Collaborators

  • sorribas