mirror of
https://github.com/Xahau/xahaud.git
synced 2025-11-20 18:45:55 +00:00
UT: remove mapOr.
This commit is contained in:
@@ -1,16 +1,18 @@
|
|||||||
|
var async = require("async");
|
||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
var path = require("path");
|
var path = require("path");
|
||||||
|
|
||||||
var utils = require("./utils.js");
|
var utils = require("./utils.js");
|
||||||
|
|
||||||
// Empty a directory.
|
// Empty a directory.
|
||||||
|
// done(err) : err = true if an error occured.
|
||||||
var emptyPath = function(dirPath, done) {
|
var emptyPath = function(dirPath, done) {
|
||||||
fs.readdir(dirPath, function(err, files) {
|
fs.readdir(dirPath, function(err, files) {
|
||||||
if (err) {
|
if (err) {
|
||||||
done(err);
|
done(err);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
utils.mapOr(rmPath, files.map(function(f) { return path.join(dirPath, f); }), done);
|
async.some(files.map(function(f) { return path.join(dirPath, f); }), rmPath, done);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -53,6 +55,7 @@ var resetPath = function(dirPath, mode, done) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Remove path recursively.
|
// Remove path recursively.
|
||||||
|
// done(err)
|
||||||
var rmPath = function(dirPath, done) {
|
var rmPath = function(dirPath, done) {
|
||||||
// console.log("rmPath: %s", dirPath);
|
// console.log("rmPath: %s", dirPath);
|
||||||
|
|
||||||
|
|||||||
19
js/utils.js
19
js/utils.js
@@ -19,24 +19,6 @@ var throwErr = function(done) {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
// apply function to elements of array. Return first true value to done or undefined.
|
|
||||||
var mapOr = function(func, array, done) {
|
|
||||||
if (array.length) {
|
|
||||||
func(array[array.length-1], function(v) {
|
|
||||||
if (v) {
|
|
||||||
done(v);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
array.length -= 1;
|
|
||||||
mapOr(func, array, done);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
done();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
var trace = function(comment, func) {
|
var trace = function(comment, func) {
|
||||||
return function() {
|
return function() {
|
||||||
console.log("%s: %s", trace, arguments.toString);
|
console.log("%s: %s", trace, arguments.toString);
|
||||||
@@ -88,7 +70,6 @@ var stringToArray = function (s) {
|
|||||||
return a;
|
return a;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.mapOr = mapOr;
|
|
||||||
exports.trace = trace;
|
exports.trace = trace;
|
||||||
exports.arraySet = arraySet;
|
exports.arraySet = arraySet;
|
||||||
exports.hexToString = hexToString;
|
exports.hexToString = hexToString;
|
||||||
|
|||||||
Reference in New Issue
Block a user