Comparing version
@@ -0,1 +1,7 @@ | ||
0.2.8 / 2013-01-08 | ||
------------------ | ||
* Added FsTools.walkSync() | ||
0.2.7 / 2012-12-19 | ||
@@ -2,0 +8,0 @@ ------------------ |
@@ -263,3 +263,54 @@ /** | ||
/** | ||
* FsTools.walkSync(path, pattern, iterator) -> void | ||
* FsTools.walkSync(path, iterator) -> void | ||
* | ||
* Synchronous version of [[FsTool.walk]]. | ||
**/ | ||
fstools.walkSync = function (path, pattern, iterator) { | ||
var match, stat; | ||
if (!iterator) { | ||
pattern = null; | ||
iterator = arguments[1]; | ||
} | ||
if (!pattern) { | ||
match = function () { return true; }; | ||
} else if (_.isFunction(pattern) && !_.isRegExp(pattern)) { | ||
match = pattern; | ||
} else { | ||
pattern = new RegExp(pattern); | ||
match = function (path) { return pattern.test(path); }; | ||
} | ||
path = path_normalize(path); | ||
try { | ||
stat = fs.lstatSync(path); | ||
} catch (err) { | ||
if ('ENOENT' === err.code) { | ||
return; | ||
} | ||
// rethrow | ||
throw err; | ||
} | ||
if (stat.isDirectory()) { | ||
fs.readdirSync(path).forEach(function (file) { | ||
fstools.walkSync(path_join(path, file), match, iterator); | ||
}); | ||
return; | ||
} | ||
if (match(path)) { | ||
iterator(path, stat); | ||
return; | ||
} | ||
}; | ||
/** | ||
* FsTools.remove(path, callback) -> void | ||
@@ -266,0 +317,0 @@ * - path (String): Path to remove |
{ | ||
"name" : "fs-tools", | ||
"version" : "0.2.7", | ||
"version" : "0.2.8", | ||
"description" : "fs helper utilities (walk, copy, mkdir -p)", | ||
@@ -5,0 +5,0 @@ "keywords" : ["fs", "file", "utils"], |
Sorry, the diff of this file is not supported yet
50164
7.57%27
3.85%1226
11.45%