Comparing version 1.7.0 to 1.7.2
@@ -109,3 +109,3 @@ // Generated by CoffeeScript 1.6.3 | ||
Finder.prototype.getPaths = function(dir, type, mask) { | ||
var exclude, filter, ok, path, paths, result, stat, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2; | ||
var err, exclude, filter, ok, path, paths, read, result, stat, _i, _j, _k, _len, _len1, _len2, _ref, _ref1; | ||
if (type == null) { | ||
@@ -118,10 +118,19 @@ type = 'all'; | ||
paths = []; | ||
_ref = fs.readdirSync(dir); | ||
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
path = _ref[_i]; | ||
try { | ||
read = fs.readdirSync(dir); | ||
} catch (_error) { | ||
err = _error; | ||
if (this.findFirst === true) { | ||
return null; | ||
} else { | ||
return paths; | ||
} | ||
} | ||
for (_i = 0, _len = read.length; _i < _len; _i++) { | ||
path = read[_i]; | ||
path = dir + '/' + path; | ||
ok = true; | ||
_ref1 = this.excludes; | ||
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { | ||
exclude = _ref1[_j]; | ||
_ref = this.excludes; | ||
for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) { | ||
exclude = _ref[_j]; | ||
if ((new RegExp(exclude)).test(path)) { | ||
@@ -143,9 +152,14 @@ ok = false; | ||
} | ||
stat = fs.statSync(path); | ||
try { | ||
stat = fs.statSync(path); | ||
} catch (_error) { | ||
err = _error; | ||
continue; | ||
} | ||
if (type === 'all' || (type === 'files' && stat.isFile()) || (type === 'directories' && stat.isDirectory())) { | ||
if (mask === null || (mask !== null && (new RegExp(mask, 'g')).test(path))) { | ||
ok = true; | ||
_ref2 = this.filters; | ||
for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) { | ||
filter = _ref2[_k]; | ||
_ref1 = this.filters; | ||
for (_k = 0, _len2 = _ref1.length; _k < _len2; _k++) { | ||
filter = _ref1[_k]; | ||
if (!filter(stat, path)) { | ||
@@ -192,3 +206,2 @@ ok = false; | ||
directory = this.directory; | ||
depth = this.up === true ? directory.match(/\//g).length : this.up - 1; | ||
paths = this.getPaths(directory, type, mask); | ||
@@ -198,2 +211,9 @@ if (this.findFirst === true && typeof paths === 'string') { | ||
} | ||
if (this.up === true) { | ||
depth = directory.match(/\//g).length; | ||
} else if (typeof this.up === 'string') { | ||
depth = _path.relative(this.up, directory).match(/\//g).length + 2; | ||
} else { | ||
depth = this.up - 1; | ||
} | ||
this.exclude(directory); | ||
@@ -220,2 +240,3 @@ for (i = _i = 0, _ref = depth - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; i = 0 <= _ref ? ++_i : --_i) { | ||
Finder.prototype.find = function(mask, type) { | ||
var _ref; | ||
if (mask == null) { | ||
@@ -228,3 +249,3 @@ mask = null; | ||
mask = Finder.normalizePattern(mask); | ||
if (this.up === true || typeof this.up === 'number') { | ||
if (this.up === true || ((_ref = typeof this.up) === 'number' || _ref === 'string')) { | ||
return this.getPathsFromParents(mask, type); | ||
@@ -231,0 +252,0 @@ } else { |
{ | ||
"name": "fs-finder", | ||
"description": "File system recursive finder", | ||
"version": "1.7.0", | ||
"version": "1.7.2", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "David Kudera", |
@@ -118,3 +118,4 @@ # fs-finder | ||
Keep in mind that one of parent directories is also your disk root directory, so you can set depth of count of these parents. | ||
Keep in mind that one of parent directories is also your disk root directory, so you can get list of all of your files or | ||
directories on disk which are accessible from your user account. To avoid this, you can set depth. | ||
@@ -124,5 +125,9 @@ ``` | ||
// or set depth | ||
// set depth with number of parent directories | ||
var files = Finder.in(dir).lookUp(3).findFiles('5.log'); | ||
// set depth with path to top directory | ||
var files = Finder.in(dir).lookUp('/var/stop/here').findFiles('5.log'); | ||
``` | ||
## Find first | ||
@@ -141,2 +146,8 @@ | ||
* 1.7.2 | ||
+ Added option to set depth in `lookUp` with path | ||
* 1.7.1 | ||
+ Catch errors when accessing secured paths (via `lookUp` option) | ||
* 1.7.0 | ||
@@ -143,0 +154,0 @@ + Mistake in test |
@@ -80,5 +80,8 @@ // Generated by CoffeeScript 1.6.3 | ||
}); | ||
return it('should return path to file in parent directory recursively', function() { | ||
it('should return path to file in parent directory recursively', function() { | ||
return Finder.from("" + dir + "/eight/3/4").lookUp(4).findFiles('twelve').should.be.eql(["" + dir + "/seven/twelve"]); | ||
}); | ||
return it('should return first file in parent directories with depth set by string', function() { | ||
return Finder.from("" + dir + "/eight/3/4").lookUp(dir).findFiles('twelve').should.be.eql(["" + dir + "/seven/twelve"]); | ||
}); | ||
}); | ||
@@ -85,0 +88,0 @@ describe('filters', function() { |
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
37499
453
196