Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
File system finder inspired by finder in Nette framework.
Unfortunately I don't have any more time to maintain this repository :-(
Don't you want to save me and this project by taking over it?
$ npm install fs-finder
There are two ways of searching for files or directories: synchronous
and asynchronous
.
var Finder = require('fs-finder');
var files = Finder.in('/var/data/base-path').findFiles(); // returns array with file's names
var directories = Finder.in(baseDir).findDirectories(); // returns array with directories's names
var paths = Finder.in(baseDir).find(); // returns array with file's and directories's names
If fs-finder
find callback in find* methods, it will automatically use asynchronous searching.
Finder.in('/var/data/base-path').findFiles(function(files) {
console.log(files);
});
Finder.in(baseDir).findDirectories(function(directories) {
console.log(directories);
});
var paths = Finder.in(baseDir).find(function(paths) {
console.log(paths);
});
var paths = Finder.from(baseDir).find();
var files = Finder.from(baseDir).findFiles('*.coffee');
or asynchronous:
Finder.from(baseDir).findFiles('*.coffee', function(files) {
// do something with given list of files
});
In this example fs finder looks for all files in base directories recursively with '.coffee' in their name. Asterisk is just shortcut for regexp '[0-9a-zA-Z/.-_ ]+' so you can also use regexp in mask.
Only thing what you have to do, is enclose your regex into <>.
var files = Finder.from(baseDir).findFiles('temp/<[0-9]+>.tmp'); // files in temp directories with numbers in name and .tmp extension
Same technique like path mask works also for excluding files or directories.
var files = Finder.from(baseDir).exclude(['/.git']).findFiles();
This code will return all files from base directory but not files beginning with .git or in .git directory. Also there you can use regular expressions or asterisk.
var files = Finder.from(baseDir).size('>=', 450).size('<=' 500).findFiles();
Returns all files with size between 450B and 500B.
var files = Finder.from(baseDir).date('>', {minutes: 10}).date('<', {minutes: 1}).findFiles();
Returns all files which were modified between two and nine minutes ago. Date filter expecting literal object (you can see documentation in moment.js documentation) or string date representation in YYYY-MM-DD HH:mm format.
var filter = function(stat, path) {
if ((new Date).getMinutes() === 42) {
return true;
} else {
return false;
}
});
var files = Finder.from(baseDir).filter(filter).findFiles();
Returns all files if actual time is any hour with 42 minutes. Custom filters are anonymous function with stat file object parameter (documentation) and file name.
In default, fs-finder ignoring temp and system files, which are created for example by gedit editor and which have got ~ character in the end of file name or dot in the beginning.
var files = Finder.in(dir).showSystemFiles().findFiles()
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 if you are using from
method.
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.
var files = Finder.in(dir).lookUp().findFiles('5.log');
// 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');
When you want to find first occur of some file or directory, you can use option findFirst
. fs-finder will not look into
all directories (for recursive searching) but stop when it will find first matching path.
If there is no matching path, null will be returned.
var file = Finder.from(dir).findFirst().findFiles('<[0-9]{2}>');
There is also shortcut:
var file = Finder.from(dir).findFile('<[0-9]{2}>');
or:
var directory = Finder.from(dir).findDirectory();
$ npm test
If you want to use fs-finder in your own tests, you can use it with fs-mock module, which is already build it.
For more information how to use it, please read documentation for fs-mock.
var fs = null;
beforeEach(function() {
fs = Finder.mock({
'var': {
'www': {
'index.php': '<?php echo "hello; ?>'
}
}
});
});
afterEach(function() {
Finder.restore();
});
In fs variable is now mocked fs module, so if you need to use fs module in your tests, just use this one.
1.8.1
1.8.0
1.7.4
lookUp
method1.7.3
lookUp
method1.7.2
lookUp
with path1.7.1
lookUp
option)1.7.0
findFirst
option1.6.0
lookUp
option1.5.1
1.5.0
1.4.3
1.4.2
1.4.1
1.4.0
1.3.0 (it seems that I skipped this version, sorry)
1.2.0
1.1.0
1.0.1
1.0.0
FAQs
[ABANDONED] File system recursive finder
We found that fs-finder demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.