1 | ;
|
2 |
|
3 | const _ = require('lodash');
|
4 | const q = require('q');
|
5 | const qfs = require('q-io/fs');
|
6 |
|
7 | exports.asyncFilter = (items, cb) => {
|
8 | return _(items)
|
9 | .map((item) => cb(item).then((res) => res && item))
|
10 | .thru(q.all)
|
11 | .value()
|
12 | .then(_.compact);
|
13 | };
|
14 |
|
15 | exports.matchesFormats = (path, formats) => {
|
16 | return _.isEmpty(formats) || _.includes(formats, qfs.extension(path));
|
17 | };
|
18 |
|
19 | exports.isFile = (path) => qfs.stat(path).then((stat) => stat.isFile());
|