Skip to content

nspragg/filesniffer

Repository files navigation

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