GithubHelp home page GithubHelp logo

nspragg / filehound Goto Github PK

View Code? Open in Web Editor NEW
222.0 6.0 16.0 1.06 MB

Flexible and fluent interface for searching the file system

License: MIT License

JavaScript 84.86% CSS 15.14%
file filesystem promise fluent-interface

filehound's Introduction

Filehound

NPM downloads npm Build Status Coverage Status license github-issues stars forks

Flexible and fluent interface for searching the file system

nodei.co

Installation

npm install --save filehound

Demo

Usage

The example below prints all of the files in a directory that have the .json file extension:

const FileHound = require('filehound');

const files = FileHound.create()
  .paths('/some/dir')
  .ext('json')
  .find();

files.then(console.log);

Documentation

For more examples and API details, see API documentation

Test

npm test

To generate a test coverage report:

npm run coverage

Contributing

  • If you're unsure if a feature would make a good addition, you can always create an issue first.
  • We aim for high test coverage. Please write tests for any new functionality or changes.
  • Any API changes should be fully documented.
  • Make sure your code meets our linting standards. Run npm run lint to check your code.
  • Maintain the existing coding style. There are some settings in .jsbeautifyrc to help.
  • Be mindful of others when making suggestions and/or code reviewing.

filehound's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

filehound's Issues

Support for modification filter

Add support for filtering by file modification time.

eg All files changed in the last 10 days

const files = FileHound.create()
  .modified(10) 
  .find();

Add path

Add .path since this is the common case. Only considers the first argument.

const files = fh
.path(p)
.find();

Path must be a string error

Hey there,

I'm getting the following error when using this package:

image

I'm not quite sure why. You docs seem to suggest that paths can be an array, although there are no actual examples of this.

.paths(paths...) -> FileHound

Directories to search. Accepts one or more directories or a reference to an array of directories

Parameters

path - array of directories
Returns

Returns a FileHound instance

Any help would be appreciated. Thanks!

Emit match events

Add events for:

  • file match as a 'data' or 'match' event
  • end of search as an end event
  • error as an error event

Examples:

filehound.on('data', (filename) => {
   console.log('matched for file %s', filename);
});
filehound.on('error', (err) => {
  console.log(`error: ${err}`);
});
filehound.on('end', () => {
  console.log('finished searching');
});

[Q] UNC paths supported?

Hello guys,
could it be possible that the great filehound paths() method doesn't support windows unc paths?

Sync support

Consider adding support for sync calls, like fs.

depth doesn't work if path starts with "./"

Working code:
var reportFiles = FileHound.create() .paths('reports') .ext('MD') .not() .depth(0) .find();

Not working code:
var reportFiles = FileHound.create() .paths('./reports') .ext('MD') .not() .depth(0) .find();
Code above returns all files, including subfolders.

Array of extensions

It would be great to pass in an array of extensions. For instance, if I want all images, i should be able to pass in
.ext(['jpg','png','gif'])

match() and glob() have different behavior

The documentation states that glob() and match() have the same functionality:
image

But actually that is not true. The source code shows that match() only uses one argument. The method glob()instead uses all arguments. Therefore the example .glob('*tmp1*','*tmp2*')does not work with match().

Is this intentional?

issue with grunt

When i run with node its perfectly working. But its not working with grunt. Please help us.
Screen Shot 2019-03-21 at 22 39 06

license ?

Hi,
The FileHound module seems great and i'll test it for my project.
Is there any Licence information somewhere ?
Thanks in advance
Laurent

About depth(0) in fileHound.create()

Hello nspragg!
May I ask some question ?
Does there have something like "depth(0)" in using :

var find = FileHound.create()
    .paths(directory)
    .depth(0)
...

And get the files in directory ( which is not current directory) ?

Sort results

Is there any way to sort the results? like for creation time or last modified?

Slow search

Hi, I'm trying to use FileHound to find package.json files in a directory tree with about 80,000 files (most of them in node_modules which I'm excluding, see below) and it runs much slower than find. I'm not sure if I'm doing something wrong or if FileHound's implementation could be improved. This is what I'm seeing:

FileHound, taking around 18 seconds on average:

packageJsons = await FileHound.create()
    .path(rootDir)
    .discard('node_modules')
    .match('package\.json')
    .find();

find (actually the "slower" find as I'm on Windows and this is Git for Windows' find), taking around 2 seconds:

await execa.shell(`find . -path "*node_modules*" -prune -o -name package.json -print`);

Any ideas?

exclude

Hello. does it have exclude option? E.g. I want to get all *.js files but not *.spec.js files

Parallel

Add support for parallel searching:

For example:
.parallel

Broken TypeScript definitions

npm install --save-dev "@types/bluebird"

node_modules/filehound/index.d.ts:2:8 - error TS1259: Module '"./node_modules/@types/bluebird/index"' can only be default-imported using the 'esModuleInterop' flag

2 import Bluebird from "bluebird";
         ~~~~~~~~

  node_modules/@types/bluebird/index.d.ts:1262:1
    1262 export = Bluebird;
         ~~~~~~~~~~~~~~~~~~
    This module is declared with using 'export =', and can only be used with a default import when using the 'esModuleInterop' flag.

node_modules/filehound/index.d.ts:108:31 - error TS7051: Parameter has a name but no type. Did you mean 'arg0: any'?

108     public addFilter(filter: (...any) => boolean): FileHound;
                                  ~~~~~~

Broken Symbolic Link Blows up Directory Search

Description

I don't know if this is a bug or not. Perhaps it is, perhaps you can help me see how I should be handling this exception when I get it. If you think it is up to me to handle the exception, if you can give a concrete example of how I should handle it, that would be appreciated.

When searching for directories, if I hit a symbolic link that is bad, the search fails with

Error: ENOENT: no such file or directory, stat

Expected behaviour

Skips broken link, or does something more benign than throwing exception that I can't quite see how to handle, perhaps because there is something about working with Promises that I don't understand.

Actual behaviour

Throws exception

Here is what happens when I hit a broken Symbolic Link called NodeRouteBasics.

{ Error: ENOENT: no such file or directory, stat '/home/charlie/Git/isit320-2018/isit320-vincenzi-2018/aws-provision/server/NodeRouteBasics'
at Object.statSync (fs.js:848:3)
at File._getStatsSync (/media/charlie/elfdisk/Git/isit320-calvert-2018/aws-provision/node_modules/file-js/lib/file.js:50:28)
at File.isDirectorySync (/media/charlie/elfdisk/Git/isit320-calvert-2018/aws-provision/node_modules/file-js/lib/file.js:113:19)
at /media/charlie/elfdisk/Git/isit320-calvert-2018/aws-provision/node_modules/filehound/lib/filehound.js:723:18
at tryCatcher (/media/charlie/elfdisk/Git/isit320-calvert-2018/aws-provision/node_modules/bluebird/js/release/util.js:16:23)
at MappingPromiseArray._promiseFulfilled (/media/charlie/elfdisk/Git/isit320-calvert-2018/aws-provision/node_modules/bluebird/js/release/map.js:61:38)
at MappingPromiseArray.PromiseArray._iterate (/media/charlie/elfdisk/Git/isit320-calvert-2018/aws-provision/node_modules/bluebird/js/release/promise_array.js:114:31)
at MappingPromiseArray.init (/media/charlie/elfdisk/Git/isit320-calvert-2018/aws-provision/node_modules/bluebird/js/release/promise_array.js:78:10)
at Promise._settlePromise (/media/charlie/elfdisk/Git/isit320-calvert-2018/aws-provision/node_modules/bluebird/js/release/promise.js:566:21)
at Promise._settlePromise0 (/media/charlie/elfdisk/Git/isit320-calvert-2018/aws-provision/node_modules/bluebird/js/release/promise.js:614:10)
at Promise._settlePromises (/media/charlie/elfdisk/Git/isit320-calvert-2018/aws-provision/node_modules/bluebird/js/release/promise.js:694:18)
at Promise._fulfill (/media/charlie/elfdisk/Git/isit320-calvert-2018/aws-provision/node_modules/bluebird/js/release/promise.js:638:18)
at Promise._resolveCallback (/media/charlie/elfdisk/Git/isit320-calvert-2018/aws-provision/node_modules/bluebird/js/release/promise.js:432:57)
at Promise._settlePromiseFromHandler (/media/charlie/elfdisk/Git/isit320-calvert-2018/aws-provision/node_modules/bluebird/js/release/promise.js:524:17)
at Promise._settlePromise (/media/charlie/elfdisk/Git/isit320-calvert-2018/aws-provision/node_modules/bluebird/js/release/promise.js:569:18)
at Promise._settlePromise0 (/media/charlie/elfdisk/Git/isit320-calvert-2018/aws-provision/node_modules/bluebird/js/release/promise.js:614:10)
errno: -2,
syscall: 'stat',
code: 'ENOENT',
path:
'/home/charlie/Git/isit320-2018/isit320-vincenzi-2018/aws-provision/server/NodeRouteBasics' }

Steps to reproduce

Here is my code:

`const filehound = FileHound.create();

filehound
    .path(searchDir)
    .depth(1)
    .discard(["node_modules", "bower_components", "build", ".idea", "static", ".git"])
    .directory()
    .find((err, dirs) => {
        if (err) {
            console.log(err);
        }
        if (!dirs) {
            console.log('SEARCHDIR'.red, searchDir);
            return;
        } else {
            console.log('SEARCHDIR'.blue, searchDir);
        }`

When I hit the broken link err is valid and !dirs is true.

Operating system

Linux Ubuntu 18.04

Feature request .sort()

Is your proposal related to a problem?

no

Describe the solution you'd like

const FileHound = require('filehound');

const files = FileHound.create()
  .paths('/some/dir')
  .find()
  .sort({modified:1})  // could be other 

Additional context

.sort() invoked after find

Find only surface-level directories

Hello!
First of all thanks for great package, it's really useful.
I'd like to know weather it's possible to find only surface-level directories, e.g.
I have /media, in /media there are /test1, /test2. In /test1 i have also /test3
This
filehound.create()
.path(mediaPath)
.directory()
.find()
.then((media_items) => {})
fetches all - /test1, /test2, /test3
So is it possible to fetch only /tes1, /test2

File changed

Filter by time file creation time:

const files = FileHound.create()
.changed('<10h')
.find()

Test template

Expected behaviour

test

Actual behaviour

Steps to reproduce

Exclude directories by name

It would be nice to be able to exclude some folder during the search. Something like:
.exclude('aFolder', 'anotherFolder'). So when a folder with that name is found, it gets ignored.

discard - root path

Description

It seems like File Hound doesn't work properly on CI, i'm just executing this code below and it returns an empty array of files, while locally the same code returns many different files:

const files = await FileHound
    .create()
    .paths(projectRootPath)
    .discard("build")		
    .depth(20)
    .ignoreHiddenDirectories()
    .ignoreHiddenFiles()
    .ext('.java', '.kt')
    .find();

The js code is here: https://github.com/dvdciri/daggraph/blob/feature/fix-skipped-tests/src/dagger/DaggerAnalyzer.js#L16

Expected behaviour

Correct files returned

Actual behaviour

Empty array of files

Steps to reproduce

Run the snipped on CI
Have a look here https://travis-ci.org/dvdciri/daggraph/jobs/325764397#L485 ("File hound files: ")
While locally i get this:

File hound files: /Users/dci03/Projects/Personal/daggraph/test/data/kotlin_dagger_default/app/src/androidTest/java/org/loop/example/ApplicationTest.java,/Us
ers/dci03/Projects/Personal/daggraph/test/data/kotlin_dagger_default/app/src/main/java/org/loop/example/AndroidModule.kt,/Users/dci03/Projects/Personal/dagg
raph/test/data/kotlin_dagger_default/app/src/main/java/org/loop/example/ApplicationComponent.kt,/Users/dci03/Projects/Personal/daggraph/test/data/kotlin_dag
ger_default/app/src/main/java/org/loop/example/ForApplication.kt,/Users/dci03/Projects/Personal/daggraph/test/data/kotlin_dagger_default/app/src/main/java/o
rg/loop/example/MainActivity.kt,/Users/dci03/Projects/Personal/daggraph/test/data/kotlin_dagger_default/app/src/main/java/org/loop/example/MyApplication.kt

Operating system

Mac

Return file names?

Any chance of adding way to return filenames or file objects?
#64

something like below:
.returns('filename') // 'path' - default, filename, file.

I understand the desire to keep things simple, but this library provides more than just file names due to the chaining mechanism which could be applied to more situations.

Regards.

Plugin for seeing where files are used

I understand this is more of a "grep" feature rather than a file based feature, however with the addFilter method we could build up a plugin repository.

The idea is to see where a file / or files are called within a codebase e.g. if file foo.js is used in 5 files it should return the 5 files that it is referenced in.

What do you think?

Ignore hidden files

Allow hidden files to be excluded:

const withoutHiddenFiles = FileHound.create()
  .ignoreHiddenFiles() // explicitly ignore hidden files
  .find();

Finding hidden files should be enabled by default.

Add discard

Add support for excluding sub-directories:

const files = fh
 .paths(pathlist)
 .discard('*node_modules*')
 .find();

File accessed time

Filter by file accessed time:

const files = FileHound.create()
.accessed('<10h')
.find()

Special Characters in .match() / .glob()

Description

Each file in my directory has a 'set name' appended to it: i.e. 'Card [XYZ].jpg'.
When using a string that contains special characters in .glob() or .match(), results are not as expected.

Expected behaviour

stringToSearch = "Card*[XYZ]"
.glob(""+stringToSearch+"")

Should find results of "Card [XYZ].jpg", "Card Two [XYZ].jpg", etc.

Actual behaviour

Instead, am getting zero results. However, setting stringToSearch = "Card*[XYZ" works perfectly fine. Changed naming convention to ( ) instead of [ ] and am getting same issues.

Steps to reproduce

Have special characters in filename and a special character as the last character of the string being used in .glob() / .match().

Operating system

Windows 10 Pro x64

Attempting to pass string[] to paths() won't compile using tyepscript

From the documentation I expected this to work

const searchPaths = ["/tmp","/etc"];

const allFiles = FileHound.create()
    .paths(searchPaths)
    .findSync();

But instead I get this error:

Argument of type 'string[]' is not assignable to parameter of type 'string'.

I must instead use the spread operator:

const searchPaths = ["/tmp","/etc"];

const allFiles = FileHound.create()
    .paths(...searchPaths)
    .findSync();

(1) Is this intentional?
(2) If yes it would help to update the documentation to reflect this.

.glob should accept arrays for multiple matches

We'd like to match against multiple globs, i.e.

const expectedFiles = ['*a*', '*b*'];
const matchingFiles = filehound.create()
    .path( '/path/to/files'))
    .glob(expectedFiles)
    .findSync();

matchingFiles should be all files matching either glob.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.