fs-walk-breadth-first
Advanced tools
Comparing version 0.0.1 to 1.0.0
@@ -5,2 +5,6 @@ # Change Log | ||
## [1.0.0] - 2015-07-15 | ||
### Changed | ||
- Change iterator argument to be async, expecting its own callback | ||
## [0.0.1] - 2015-07-07 | ||
@@ -7,0 +11,0 @@ ### Fixed |
@@ -10,3 +10,7 @@ "use strict"; | ||
var isDirectory = R.pipe(R.lensIndex(1), R.invoker(0, "isDirectory")); | ||
function walk(directory, iterator, finished) { | ||
var walker = R.curry(walk)(R.__, iterator, R.__); // eslint-disable-line no-underscore-dangle | ||
fs.readdir(directory, function(err, files) { | ||
@@ -25,8 +29,9 @@ if (err) { | ||
var pairs = R.zip(files, stats); | ||
R.forEach(R.apply(iterator), pairs); | ||
var isDirectory = R.pipe(R.lensIndex(1), R.invoker(0, "isDirectory")); | ||
var dirs = R.map(R.lensIndex(0), R.filter(isDirectory, pairs)); | ||
async.each(dirs, function(dir, callback) { | ||
walk(dir, iterator, callback); | ||
}, finished); | ||
async.each(pairs, function(pair, callback) { | ||
pair.push(callback); | ||
R.apply(iterator, pair); | ||
}, function() { | ||
var dirs = R.map(R.lensIndex(0), R.filter(isDirectory, pairs)); | ||
async.each(dirs, walker, finished); | ||
}); | ||
}); | ||
@@ -33,0 +38,0 @@ }); |
{ | ||
"name": "fs-walk-breadth-first", | ||
"version": "0.0.1", | ||
"version": "1.0.0", | ||
"description": "Call a function on each file in a filesystem tree", | ||
@@ -37,3 +37,4 @@ "keywords": [ | ||
"tap-spec": "^4.0.2", | ||
"tape": "^4.0.0" | ||
"tape": "^4.0.0", | ||
"tape-catch": "^1.0.4" | ||
}, | ||
@@ -40,0 +41,0 @@ "dependencies": { |
@@ -32,3 +32,3 @@ # node-fs-walk-breadth-first | ||
* `directory` - The directory to traverse. | ||
* `iterator(filename, stats)` - A function to apply to each file or directory found. `stats` is an instance of [fs.Stats](https://nodejs.org/api/fs.html#fs_class_fs_stats). | ||
* `iterator(filename, stats, callback)` - A function to apply to each file or directory found. `stats` is an instance of [fs.Stats](https://nodejs.org/api/fs.html#fs_class_fs_stats). `callback(err)` should be called when the iterator is finished | ||
* `callback(err)` - A function that is called when all the files and directories have been visited, or when an error occurs. | ||
@@ -35,0 +35,0 @@ |
@@ -5,3 +5,3 @@ "use strict"; | ||
var mockFs = require("mock-fs"); | ||
var test = require("tape"); | ||
var test = require("tape-catch"); | ||
@@ -36,4 +36,5 @@ function setup(t, fakeFs) { | ||
t.plan(2); | ||
walk("folder", function(filename) { | ||
walk("folder", function(filename, _, callback) { | ||
t.equal(filename, "folder/file", "should return the file's path"); | ||
callback(); | ||
}, function(err) { | ||
@@ -47,4 +48,5 @@ t.notOk(err, "should have no errors"); | ||
t.plan(3); | ||
walk("folder", function(filename, stat) { | ||
walk("folder", function(filename, stat, callback) { | ||
t.equal(stat.isFile(), true, "should return a fs.Stats"); | ||
callback(); | ||
}, function(err) { | ||
@@ -58,6 +60,7 @@ t.notOk(err, "should have no errors"); | ||
t.plan(2); | ||
walk("folder1", function(filename, stat) { | ||
walk("folder1", function(filename, stat, callback) { | ||
if (filename === "folder1/folder2/file") { | ||
t.ok(stat.isFile(), "should return a fs.Stats"); | ||
} | ||
callback(); | ||
}, function(err) { | ||
@@ -64,0 +67,0 @@ t.notOk(err, "should have no errors"); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
95
0
436485
5