Comparing version 0.1.0 to 0.1.2
@@ -38,3 +38,5 @@ var fs = require('fs'), | ||
} | ||
if (typeof options === 'string') options = { encoding: options }; | ||
if (typeof options === 'string') options = { | ||
encoding: options | ||
}; | ||
options = extend({ | ||
@@ -57,2 +59,8 @@ recursive: true, | ||
if (options.reverse === true || | ||
(typeof options.sort == 'string' && | ||
(/reverse|desc/i).test(options.sort))) { | ||
list = list.reverse(); | ||
} else if (options.sort !== false) list = list.sort(); | ||
(function next() { | ||
@@ -63,10 +71,17 @@ var filename = list[i++]; | ||
fs.stat(file, function(err, stat) { | ||
if (stat && stat.isDirectory() && options.recursive) { | ||
readFiles(file, options, callback, function(err, sfiles) { | ||
files = files.concat(sfiles); | ||
next(); | ||
}); | ||
if (err) return done(err); | ||
if (stat && stat.isDirectory()) { | ||
if (options.recursive) { | ||
if (options.matchDir && !options.matchDir.test(filename)) return next(); | ||
if (options.excludeDir && options.excludeDir.test(filename)) return next(); | ||
readFiles(file, options, callback, function(err, sfiles) { | ||
if (err) return done(err); | ||
files = files.concat(sfiles); | ||
next(); | ||
}); | ||
} else next(); | ||
} else { | ||
if (options.match && !options.match.test(filename)) return next(); | ||
if (options.exclude && options.exclude.test(filename)) return next(); | ||
if (options.filter && !options.filter(filename)) return next(); | ||
if (options.shortName) files.push(filename); | ||
@@ -79,3 +94,3 @@ else files.push(file); | ||
else callback(null, data, file, next); | ||
else callback(null, data, next); | ||
else callback(null, data, next); | ||
}); | ||
@@ -82,0 +97,0 @@ } |
{ | ||
"name" : "node-dir", | ||
"version" : "0.1.0", | ||
"version" : "0.1.2", | ||
"description" : "asynchronous file and directory operations for Node.js", | ||
@@ -5,0 +5,0 @@ "main" : "index", |
@@ -18,4 +18,12 @@ # node-dir | ||
- exclude: a regex pattern to specify filenames to ignore | ||
- matchDir: a regex pattern to specify directories to recurse | ||
- excludeDir: a regex pattern to specify directories to ignore | ||
- shortName: whether to aggregate only the base filename rather than the full filepath | ||
- recursive: whether to recurse subdirectories when reading files. The default is true. | ||
- sort: sort files in each directory in ascending order (defaults to true). | ||
- reverse: sort files in each directory in descending order. | ||
note that a reverse sort can also be achieved by setting the sort option to 'reverse', 'desc', or 'descending' string value. | ||
```javascript | ||
@@ -22,0 +30,0 @@ dir.readFiles(__dirname, |
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
14127
10
217
115