.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / stylelint / node_modules / path-type / index.js
1 'use strict';
2 const fs = require('fs');
3 const pify = require('pify');
4
5 function type(fn, fn2, fp) {
6         if (typeof fp !== 'string') {
7                 return Promise.reject(new TypeError(`Expected a string, got ${typeof fp}`));
8         }
9
10         return pify(fs[fn])(fp)
11                 .then(stats => stats[fn2]())
12                 .catch(err => {
13                         if (err.code === 'ENOENT') {
14                                 return false;
15                         }
16
17                         throw err;
18                 });
19 }
20
21 function typeSync(fn, fn2, fp) {
22         if (typeof fp !== 'string') {
23                 throw new TypeError(`Expected a string, got ${typeof fp}`);
24         }
25
26         try {
27                 return fs[fn](fp)[fn2]();
28         } catch (err) {
29                 if (err.code === 'ENOENT') {
30                         return false;
31                 }
32
33                 throw err;
34         }
35 }
36
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');