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

fs-finder

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fs-finder - npm Package Compare versions

Comparing version 1.5.1 to 1.6.0

test/Finder.coffee

43

lib/Finder.js

@@ -30,4 +30,9 @@ // Generated by CoffeeScript 1.6.3

Finder.prototype.up = false;
function Finder(directory) {
directory = _path.resolve(directory);
if (!fs.statSync(directory).isDirectory()) {
throw new Error("Path " + directory + " is not directory");
}
this.directory = directory;

@@ -80,10 +85,12 @@ }

Finder.prototype.showSystemFiles = function(show) {
if (show == null) {
show = true;
}
this.systemFiles = show;
Finder.prototype.showSystemFiles = function(systemFiles) {
this.systemFiles = systemFiles != null ? systemFiles : true;
return this;
};
Finder.prototype.lookUp = function(up) {
this.up = up != null ? up : true;
return this;
};
Finder.prototype.filter = function(fn) {

@@ -152,2 +159,22 @@ this.filters.push(fn);

Finder.prototype.getPathsFromParents = function(mask, type) {
var depth, directory, i, paths, _i, _ref;
if (mask == null) {
mask = null;
}
if (type == null) {
type = 'all';
}
directory = this.directory;
depth = this.up === true ? directory.match(/\//g).length : this.up - 1;
paths = this.getPaths(directory, type, mask);
this.exclude(directory);
for (i = _i = 0, _ref = depth - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; i = 0 <= _ref ? ++_i : --_i) {
directory = _path.dirname(directory);
paths = paths.concat(this.getPaths(directory, type, mask));
this.exclude(directory);
}
return paths;
};
Finder.prototype.find = function(mask, type) {

@@ -161,3 +188,7 @@ if (mask == null) {

mask = Finder.normalizePattern(mask);
return this.getPaths(this.directory, type, mask);
if (this.up === true || typeof this.up === 'number') {
return this.getPathsFromParents(mask, type);
} else {
return this.getPaths(this.directory, type, mask);
}
};

@@ -164,0 +195,0 @@

4

package.json
{
"name": "fs-finder",
"description": "File system recursive finder",
"version": "1.5.1",
"version": "1.6.0",
"author": {

@@ -33,4 +33,4 @@ "name": "David Kudera",

"scripts": {
"test": "cd ./test; mocha ./index.js;"
"test": "cd ./test; mocha ./index.js --reporter spec;"
}
}

@@ -17,3 +17,3 @@ # fs-finder

```
var Finder = requrire('fs-finder');
var Finder = require('fs-finder');
var finder = new Finder('/var/data/base-path');

@@ -27,3 +27,3 @@

```
var directories = finder.findDirectories(); // returns array with directorie's names
var directories = finder.findDirectories(); // returns array with directories's names
```

@@ -34,3 +34,3 @@

```
var paths = finder.find(); // returns array with file's and directorie's names
var paths = finder.find(); // returns array with file's and directories's names
```

@@ -105,3 +105,3 @@

Returns all files if actual time is any hour with 42 minutes.
Custom filters are annonymous function with stat file object parameter ([documentation](http://nodejs.org/api/fs.html#fs_class_fs_stats))
Custom filters are anonymous function with stat file object parameter ([documentation](http://nodejs.org/api/fs.html#fs_class_fs_stats))
and file name.

@@ -119,2 +119,18 @@

## Look in parent directories
Finder can also look for files in parent directories. There is used `exclude` method, so directories in which were your
files already searched, will not be opened for searching again in their next parent directory.
Keep in mind that one of parent directories is also your disk root directory, so you can set depth of count of these parents.
Of course, you can combine it with other methods, even with `recursive`.
```
var files = finder.lookUp().findFiles('5.log');
// or set depth
var files = finder.lookUp(3).findFiles('5.log');
```
## Shortcuts

@@ -145,2 +161,8 @@

* 1.6.0
+ New reporter for tests
+ Tests rewritten to coffeescript
+ Added `lookUp` option
+ Typos in readme
* 1.5.1

@@ -152,3 +174,3 @@ + Compare function replaced with [operation-compare](https://npmjs.org/package/operator-compare)

+ Created tests (npm test)
+ Repaired bugs with hidding system and temp files
+ Repaired bugs with hiding system and temp files

@@ -165,6 +187,6 @@ * 1.4.3

* 1.4.0
+ Every regexp must be enclosed in <> (before this, dots meens everything, not dot)
+ Every regexp must be enclosed in <> (before this, dots means everything, not dot)
+ Every character, which does mean something in regexp and is not in <>, is escaped
* 1.3.0 (it seems that I skiped this version, sorry)
* 1.3.0 (it seems that I skipped this version, sorry)

@@ -171,0 +193,0 @@ * 1.2.0

@@ -1,171 +0,129 @@

(function () {
// Generated by CoffeeScript 1.6.3
(function() {
var Finder, dir, finder, fs, path, should;
var should = require('should');
var path = require('path');
var fs = require('fs');
should = require('should');
var dir = path.resolve('./data');
path = require('path');
var Finder = require('../lib/Finder');
var finder = new Finder(dir);
fs = require('fs');
describe('Finder', function() {
dir = path.resolve('./data');
describe('#findFiles()', function() {
it('should return file names from root folder', function() {
finder.findFiles().should.eql([
dir + '/0',
dir + '/1',
dir + '/five',
dir + '/one',
dir + '/three',
dir + '/two'
]);
});
});
Finder = require('../lib/Finder');
describe('#findDirectories()', function() {
it('should return directory names from root folder', function() {
finder.findDirectories().should.eql([
dir + '/eight',
dir + '/seven',
dir + '/six'
]);
});
});
finder = new Finder(dir);
describe('#find()', function() {
it('should return file and directory names from root folder', function() {
finder.find().should.eql([
dir + '/0',
dir + '/1',
dir + '/eight',
dir + '/five',
dir + '/one',
dir + '/seven',
dir + '/six',
dir + '/three',
dir + '/two'
]);
});
});
describe('Finder', function() {
describe('base', function() {
return it('should throw an error if path is not directory', function() {
return (function() {
return new finder("" + dir + "/two");
}).should["throw"]();
});
});
describe('#findFiles()', function() {
return it('should return file names from root folder', function() {
return finder.findFiles().should.eql(["" + dir + "/0", "" + dir + "/1", "" + dir + "/five", "" + dir + "/one", "" + dir + "/three", "" + dir + "/two"]);
});
});
describe('#findDirectories()', function() {
return it('should return directory names from root folder', function() {
return finder.findDirectories().should.eql(["" + dir + "/eight", "" + dir + "/seven", "" + dir + "/six"]);
});
});
describe('#find()', function() {
return it('should return file and directory names from root folder', function() {
return finder.find().should.eql(["" + dir + "/0", "" + dir + "/1", "" + dir + "/eight", "" + dir + "/five", "" + dir + "/one", "" + dir + "/seven", "" + dir + "/six", "" + dir + "/three", "" + dir + "/two"]);
});
});
describe('#recursive()', function() {
return it('should return file names recursively from find* methods', function() {
finder.recursively(true);
finder.findFiles().should.eql(["" + dir + "/0", "" + dir + "/1", "" + dir + "/eight/3/4/file.json", "" + dir + "/five", "" + dir + "/one", "" + dir + "/seven/13", "" + dir + "/seven/14", "" + dir + "/seven/twelve", "" + dir + "/six/eleven", "" + dir + "/six/nine", "" + dir + "/six/ten", "" + dir + "/three", "" + dir + "/two"]);
return finder.recursively(false);
});
});
describe('#exclude()', function() {
return it('should return files which has not got numbers in name', function() {
finder.exclude(['<[0-9]>']);
finder.findFiles().should.eql(["" + dir + "/five", "" + dir + "/one", "" + dir + "/three", "" + dir + "/two"]);
return finder.excludes = [];
});
});
describe('#showSystemFiles()', function() {
return it('should return also system, hide and temp files', function() {
finder.showSystemFiles(true);
finder.findFiles().should.eql(["" + dir + "/.cache", "" + dir + "/0", "" + dir + "/1", "" + dir + "/five", "" + dir + "/five~", "" + dir + "/one", "" + dir + "/three", "" + dir + "/two"]);
return finder.showSystemFiles(false);
});
});
describe('#lookUp()', function() {
it('should return path to file in parent directory', function() {
return Finder["in"]("" + dir + "/eight/3/4").lookUp(4).showSystemFiles().findFiles('._.js').should.be.eql(["" + dir + "/eight/._.js"]);
});
return 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"]);
});
});
describe('filters', function() {
afterEach(function() {
return finder.filters = [];
});
describe('#size()', function() {
return it('should return files with size between 2000B and 3000B', function() {
finder.size('>=', 2000).size('<=', 3000);
return finder.findFiles().should.eql(["" + dir + "/five"]);
});
});
describe('#date()', function() {
return it('should return files which were changed in less than 1 minute ago', function() {
fs.writeFileSync("" + dir + "/two", 'just some changes');
finder.date('>', {
minutes: 1
});
return finder.findFiles().should.eql(["" + dir + "/two"]);
});
});
return describe('#filter()', function() {
return it('should return files which names are 3 chars length', function() {
finder.filter(function(stat, file) {
var name;
name = path.basename(file, path.extname(file));
return name.length === 3;
});
return finder.findFiles().should.eql(["" + dir + "/one", "" + dir + "/two"]);
});
});
});
return describe('utils', function() {
describe('#parseDirectory()', function() {
return it('should return object with directory and mask from path to find* methods', function() {
Finder.parseDirectory("" + dir + "/one").should.eql({
directory: "" + dir + "/one",
mask: null
});
Finder.parseDirectory("" + dir + "<(five|three)*>").should.eql({
directory: dir,
mask: '<(five|three)*>'
});
return Finder.parseDirectory("" + dir + "*<e$>").should.eql({
directory: dir,
mask: '*<e$>'
});
});
});
describe('#escapeForRegex()', function() {
return it('should return escaped string for using it in regexp', function() {
return Finder.escapeForRegex('.h[]e()l+|l?^o$').should.be.equal('\\.h\\[\\]e\\(\\)l\\+\\|l\\?\\^o\\$');
});
});
return describe('#normalizePattern()', function() {
return it('should return proper regular expression from path parameter', function() {
return Finder.normalizePattern("" + dir + "/.temp/<(one|two)>*<$>").should.be.equal("" + dir + "/\\.temp/(one|two)[0-9a-zA-Z/.-_ ]+$");
});
});
});
});
describe('#recursive()', function() {
it('should return file names recursively from find* methods', function() {
finder.recursively(true);
finder.findFiles().should.eql([
dir + '/0',
dir + '/1',
dir + '/eight/3/4/file.json',
dir + '/five',
dir + '/one',
dir + '/seven/13',
dir + '/seven/14',
dir + '/seven/twelve',
dir + '/six/eleven',
dir + '/six/nine',
dir + '/six/ten',
dir + '/three',
dir + '/two'
]);
finder.recursively(false);
});
});
describe('#exclude()', function() {
it('should return files which has not got numbers in name', function() {
finder.exclude(['<[0-9]>']);
finder.findFiles().should.eql([
dir + '/five',
dir + '/one',
dir + '/three',
dir + '/two'
]);
finder.excludes = [];
});
});
describe('#size()', function() {
it('should return files with size between 2000B and 3000B', function() {
finder.size('>=', 2000).size('<=', 3000);
finder.findFiles().should.eql([
dir + '/five'
]);
finder.filters = [];
});
});
describe('#date()', function() {
it('should return files which were changed in less than 1 minute ago', function() {
fs.writeFileSync(dir + '/two', 'just some change');
finder.date('>', {minutes: 1});
finder.findFiles().should.eql([
dir + '/two'
]);
finder.filters = [];
});
});
describe('#showSystemFiles()', function() {
it('should return also system, hide and temp files', function() {
finder.showSystemFiles(true);
finder.findFiles().should.eql([
dir + '/.cache',
dir + '/0',
dir + '/1',
dir + '/five',
dir + '/five~',
dir + '/one',
dir + '/three',
dir + '/two'
]);
finder.showSystemFiles(false);
});
});
describe('#filter()', function() {
it('should return files which names are 3 chars length', function() {
finder.filter(function(stat, file) {
var name = path.basename(file, path.extname(file));
return name.length === 3;
});
finder.findFiles().should.eql([
dir + '/one',
dir + '/two'
]);
finder.filters = [];
});
});
describe('#parseDirectory()', function() {
it('should return object with directory and mask from path to find* methods', function() {
Finder.parseDirectory(dir + '/one').should.eql({
directory: dir + '/one',
mask: null
});
Finder.parseDirectory(dir + '<(five|three)*>').should.eql({
directory: dir,
mask: '<(five|three)*>'
});
Finder.parseDirectory(dir + '*<e$>').should.eql({
directory: dir,
mask: '*<e$>'
});
});
});
describe('#escapeForRegex()', function() {
it('should return escaped string for using it in regexp', function() {
Finder.escapeForRegex('.h[]e()l+|l?^o$').should.be.equal('\\.h\\[\\]e\\(\\)l\\+\\|l\\?\\^o\\$');
});
});
describe('#normalizePattern()', function() {
it('should return proper regular expression from path parameter', function() {
Finder.normalizePattern(dir + '/.temp/<(one|two)>*<$>').should.be.equal(dir + '/\\.temp/(one|two)[0-9a-zA-Z/.-_ ]+$');
});
});
});
})();
}).call(this);

@@ -1,5 +0,5 @@

(function () {
// Generated by CoffeeScript 1.6.3
(function() {
require('./Finder');
require('./Finder.js');
})();
}).call(this);

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