UNPKG

466 BJavaScriptView Raw
1'use strict';
2var fs = require('fs');
3var Promise = require('pinkie-promise');
4
5module.exports = function (fp) {
6 var fn = typeof fs.access === 'function' ? fs.access : fs.stat;
7
8 return new Promise(function (resolve) {
9 fn(fp, function (err) {
10 resolve(!err);
11 });
12 });
13};
14
15module.exports.sync = function (fp) {
16 var fn = typeof fs.accessSync === 'function' ? fs.accessSync : fs.statSync;
17
18 try {
19 fn(fp);
20 return true;
21 } catch (err) {
22 return false;
23 }
24};