Find files by matching contents
npm install --save filesniffer
// 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');
For more examples and API details, see API documentation
npm test
To generate a test coverage report:
npm run coverage