| 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 |
, lstat = require("./lstat") |
| 7 |
, rmdir = require("./rmdir") |
| 8 |
, unlink = require("./unlink"); |
| 9 |
|
| 10 |
var rm = function (path, options) { |
| 11 |
return lstat(path, options)(function (stats) { |
| 12 |
if (!stats) return null; // loose option |
| 13 |
if (stats.isDirectory()) return rmdir(path, options); |
| 14 |
return unlink(path, options); |
| 15 |
}); |
| 16 |
}; |
| 17 |
rm.returnsPromise = true; |
| 18 |
|
| 19 |
module.exports = function (path/*[, options[, callback]]*/) { |
| 20 |
var options, cb; |
| 21 |
|
| 22 |
path = resolve(String(path)); |
| 23 |
options = arguments[1]; |
| 24 |
cb = arguments[2]; |
| 25 |
if (!isValue(cb) && isCallable(options)) { |
| 26 |
cb = options; |
| 27 |
options = {}; |
| 28 |
} else { |
| 29 |
options = Object(options); |
| 30 |
} |
| 31 |
|
| 32 |
return rm(path, options).cb(cb); |
| 33 |
}; |
| 34 |
module.exports.returnsPromise = true; |
| 35 |
module.exports.rm = rm; |