2 const fs = require('fs');
3 const pify = require('pify');
5 function type(fn, fn2, fp) {
6 if (typeof fp !== 'string') {
7 return Promise.reject(new TypeError(`Expected a string, got ${typeof fp}`));
10 return pify(fs[fn])(fp)
11 .then(stats => stats[fn2]())
13 if (err.code === 'ENOENT') {
21 function typeSync(fn, fn2, fp) {
22 if (typeof fp !== 'string') {
23 throw new TypeError(`Expected a string, got ${typeof fp}`);
27 return fs[fn](fp)[fn2]();
29 if (err.code === 'ENOENT') {
37 exports.file = type.bind(null, 'stat', 'isFile');
38 exports.dir = type.bind(null, 'stat', 'isDirectory');
39 exports.symlink = type.bind(null, 'lstat', 'isSymbolicLink');
40 exports.fileSync = typeSync.bind(null, 'statSync', 'isFile');
41 exports.dirSync = typeSync.bind(null, 'statSync', 'isDirectory');
42 exports.symlinkSync = typeSync.bind(null, 'lstatSync', 'isSymbolicLink');