| 1 |
"use strict"; |
| 2 |
|
| 3 |
var isCallable = require("es5-ext/object/is-callable") |
| 4 |
, isValue = require("es5-ext/object/is-value") |
| 5 |
, resolve = require("path").resolve |
| 6 |
, access = require("./access"); |
| 7 |
|
| 8 |
module.exports = function (path/*[, options[, callback]]*/) { |
| 9 |
path = resolve(String(path)); |
| 10 |
var options = arguments[1], cb = arguments[2]; |
| 11 |
if (!isValue(cb) && isCallable(options)) { |
| 12 |
cb = options; |
| 13 |
options = {}; |
| 14 |
} |
| 15 |
options = Object(options); |
| 16 |
return access(path, options.mode) |
| 17 |
.then( |
| 18 |
function () { return true; }, |
| 19 |
function (error) { |
| 20 |
if (options.loose && (error.code === "ENOENT" || error.code === "ENOTDIR")) { |
| 21 |
return null; |
| 22 |
} |
| 23 |
if (error.code === "EACCES") return false; |
| 24 |
throw error; |
| 25 |
} |
| 26 |
) |
| 27 |
.cb(cb); |
| 28 |
}; |