Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

recursive-search

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

recursive-search - npm Package Compare versions

Comparing version 0.0.4 to 1.0.0

test/test-files/.hidden

58

lib/recursive-search.js

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc