GithubHelp home page GithubHelp logo

filesniffer's Introduction

FileSniffer

NPM downloads Build Status Coverage Status github-issues

Find files by matching contents

Installation

npm install --save filesniffer

Usage

// Searches for `someString` in `/tmp/test.txt`, returning all matches as an array:
const matches = await FileSniffer.create()
  .path('/tmp/test.txt')
  .collect(asArray())
  .find('someString');

  console.log(matches); // array of matching lines
// Use events for searching large files: 
const sniffer = await FileSniffer.create();

// register event handlers
sniffer.on('match', (filename, line) => {
  console.log(`Matching line ${line} found in ${filename}`);
});

sniffer.on('end', (filenames) => {
  console.log(`All files that match: ${filenames}`);
});

// start search
sniffer
  .path('/tmp')
  .find('some string');

Documentation

For more examples and API details, see API documentation

Test

npm test

Test Coverage

To generate a test coverage report:

npm run coverage

Contributing

See contributing guidelines

filesniffer's People

Contributors

nspragg avatar ripla avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

filesniffer's Issues

Support ignore hidden directories and files

With the new api I can't use the FILE_HOUND criteria anymore and therefore can't use the
.ignoreHiddenDirectories()
.ignoreHiddenFiles()
Would be good to add them to filesniffer

Support match context

Add support for including context (number of lines) before and after match:

const matches = await FileSniffer.create()
.path(filename)
.context(5) // 5 line before and after match
.collection(asArray())
.find('str');

Support case insensitive search

Add a method .ignoreCase to allow for a case insensitive search. This is useful for simple string searches e.g .find(str)

Support for discard certain directories

After the removal of fileniffer + file_hound, i can't anymore use the file hound discard() feature. It would be good if we can create that in filesniffer..

Multiple result per file

I'm doing a search in files that contains the string target multiple times, and I'm returning the same file path multiple times, as many times as the target string appears.
Is this a bug or is this the expected behaviour? If is expected is there a way to return the file only once if the string appears at least one time?

No events emitted

No events are emitted when the input source (list of paths or Filehound results) are empty.

const sniffer = FileSniffer.create([]);

Add helper functions

  • Add helper functions to handle events
// find files on the cwd containing pattern. Populate buffer. 
FileSniffer.find(/pattern/, buffer);

When combined with FILE_HOUND on CI, (travis) doesn't emit any events

I noticed that if you run some tests on Travis and specify some search criteria using FILE_HOUND, filesniffer doesn't emit any event, no error, no match and no end.

The same setup that does't work on CI, works locally when i run the tests.

The code is pretty simple:

const searchCriteria = FILE_HOUND.create()
    .paths(projectRootPath)
    .discard("build")		
    .depth(20)
    .ignoreHiddenDirectories()
    .ignoreHiddenFiles()
    .ext('.java', '.kt');

  const fileSniffer = FILE_SNIFFER.create(searchCriteria);
// match, end, error

If there anything else that i can do to debug and understand what is happening inside filesniffer?

Api additions

API changes:

  1. Add support for collector functions to aggregator results (see example)
  2. Add .path and .paths methods
  3. Maintain support for all existing events
  4. Deprecate .create with args
  5. Add support for configuration recursion depth

Example:

const FileSniffer = require('filesniffer');
const asArray = FileSniffer.asArray;

const lines = FileSniffer.create()
 .paths(paths) // can be files and/or dirs 
 .collect(asArray()) // or just fn reference directly
 .find(/mypattern/); 

const {filename, line} = matchesAsArray[0];

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.