UNPKG

486 BJavaScriptView Raw
1'use strict';
2
3const _ = require('lodash');
4const q = require('q');
5const qfs = require('q-io/fs');
6
7exports.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
15exports.matchesFormats = (path, formats) => {
16 return _.isEmpty(formats) || _.includes(formats, qfs.extension(path));
17};
18
19exports.isFile = (path) => qfs.stat(path).then((stat) => stat.isFile());