recursive-search
Advanced tools
Comparing version 0.0.4 to 1.0.0
@@ -11,4 +11,9 @@ // Generated by CoffeeScript 1.6.3 | ||
module.exports = { | ||
recursiveSearchSync: function(filename, dir) { | ||
recursiveSearchSync: function(filename, dir, options) { | ||
var f, matches; | ||
if (arguments.length !== 3) { | ||
options = { | ||
all: false | ||
}; | ||
} | ||
matches = []; | ||
@@ -32,4 +37,10 @@ f = (function(dir) { | ||
condition = (filename.constructor.name === "RegExp" ? path.basename(file).match(filename) : path.basename(file) === filename); | ||
if (condition) { | ||
matches.push(file); | ||
if (condition || filename === '*') { | ||
if (options.all === false) { | ||
if (path.basename(file).charAt(0) !== '.') { | ||
matches.push(file); | ||
} | ||
} else { | ||
matches.push(file); | ||
} | ||
} | ||
@@ -44,21 +55,26 @@ return next(); | ||
}, | ||
recursiveSearch: function(filename, dir, callback, complete) { | ||
var results; | ||
results = []; | ||
return (function() { | ||
return dive(dir, function(err, file) { | ||
var condition; | ||
if (err) { | ||
return callback(err); | ||
} | ||
condition = (filename.constructor.name === "RegExp" ? path.basename(file).match(filename) : path.basename(file) === filename); | ||
if (condition) { | ||
results.push(file); | ||
return callback(null, file); | ||
} | ||
}, function() { | ||
return complete(results); | ||
}); | ||
})(); | ||
recursiveSearch: function(filename, dir, options, callback, complete) { | ||
var matches; | ||
if (arguments.length !== 5) { | ||
complete = callback; | ||
callback = options; | ||
options = { | ||
all: false | ||
}; | ||
} | ||
matches = []; | ||
return dive(dir, options, function(err, file) { | ||
var condition; | ||
if (err) { | ||
return callback(err); | ||
} | ||
condition = (filename.constructor.name === "RegExp" ? path.basename(file).match(filename) : path.basename(file) === filename); | ||
if (condition || filename === '*') { | ||
matches.push(file); | ||
return callback(null, file); | ||
} | ||
}, function() { | ||
return complete(matches); | ||
}); | ||
} | ||
}; |
@@ -7,9 +7,10 @@ { | ||
], | ||
"version": "0.0.4", | ||
"version": "1.0.0", | ||
"description": "Recursively search a file in given directory from name of RegExp", | ||
"keywords": [ | ||
"recursive", | ||
"search", | ||
"file", | ||
"search", | ||
"exists" | ||
"exists", | ||
"RegExp" | ||
], | ||
@@ -16,0 +17,0 @@ "license": "MIT", |
@@ -5,3 +5,3 @@ # node-recursive-search | ||
Recursively search a file in given directory from name or RegExp. | ||
Recursively search a file in given directory from name or RegExp. Can return dot files or ignore them. | ||
@@ -14,2 +14,11 @@ ### Install | ||
### Methods | ||
```javascript | ||
search.recursiveSearchSync(searchTerm, directory, [options]) | ||
search.recursiveSearch(searchTerm, directory, [options], callback, complete) | ||
``` | ||
Where `searchTerm` can be a `String` or a `RegExp`. | ||
### Usage | ||
@@ -20,5 +29,6 @@ | ||
// search one file | ||
var results = search.recursiveSearchSync('foo.txt', __dirname + '/dir') | ||
if (results.length > 0) { | ||
// no file | ||
// no file | ||
} else { | ||
@@ -28,3 +38,4 @@ // results | ||
search.recursiveSearch('foo.txt', __dirname + '/dir', function(err, result){ | ||
// search all files | ||
search.recursiveSearch('*', __dirname + '/dir', function(err, result){ | ||
if (err) throw err | ||
@@ -36,4 +47,7 @@ // result | ||
// regex support in both functions | ||
// search from RegExp | ||
results = search.recursiveSearchSync(/.txt$/, __dirname + '/dir') | ||
// hidden files | ||
results = search.recursiveSearchSync(/.txt$/, __dirname + '/dir', { all: true }) // return hidden files | ||
``` | ||
@@ -40,0 +54,0 @@ |
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
11071
14
73
1
59