UNPKG

593 BJavaScriptView Raw
1
2var fs = require('fs');
3
4function exists (path, isFile, isDirectory) {
5 try {
6 var matches = false;
7 var stat = fs.statSync(path);
8
9 matches = matches || isFile && stat.isFile();
10 matches = matches || isDirectory && stat.isDirectory();
11
12 return matches;
13 }
14 catch (e) {
15 if (e.code === 'ENOENT') {
16 return false;
17 }
18
19 throw e;
20 }
21}
22
23module.exports = function (path, type) {
24 if (!type) {
25 return exists(path, true, true);
26 }
27
28 return exists(path, type & 1, type & 2);
29};
30
31module.exports.FILE = 1;
32
33module.exports.FOLDER = 2;