2 const path = require('path');
3 const fs = require('fs');
4 const {promisify} = require('util');
5 const pLocate = require('p-locate');
7 const fsStat = promisify(fs.stat);
8 const fsLStat = promisify(fs.lstat);
10 const typeMappings = {
11 directory: 'isDirectory',
15 function checkType({type}) {
16 if (type in typeMappings) {
20 throw new Error(`Invalid type specified: ${type}`);
23 const matchType = (type, stat) => type === undefined || stat[typeMappings[type]]();
25 module.exports = async (paths, options) => {
33 const statFn = options.allowSymlinks ? fsStat : fsLStat;
35 return pLocate(paths, async path_ => {
37 const stat = await statFn(path.resolve(options.cwd, path_));
38 return matchType(options.type, stat);
45 module.exports.sync = (paths, options) => {
53 const statFn = options.allowSymlinks ? fs.statSync : fs.lstatSync;
55 for (const path_ of paths) {
57 const stat = statFn(path.resolve(options.cwd, path_));
59 if (matchType(options.type, stat)) {