find-in-files
A simple tool to search text patterns across multiple files
Last updated 10 years ago by kaesetoast .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ gnpm install find-in-files 
SYNC missed versions from official npm registry.

find-in-files Build Status Coverage Status

A simple tool to search text patterns across multiple files

Installation

find-in-files is a node module available via npm. You can install it with

$ npm install --save find-in-files

Usage

The module exposes two simple functions which expect three parameters each.

// Async
find(pattern, directory, fileFilter)
// Sync
findSync(pattern, directory, fileFilter)

pattern [string|object]

The string you want to search for or object to control regex flags

directory [string]

The directory you want to search in.

fileFilter [regex] (optional)

A regex you can pass in to only search in files matching the filter.

var findInFiles = require('find-in-files');

Both functions return a promise which will receive the results object. The results object contains the matches, count of matches per file and the lines that match.

{
    'fileOne.txt': {
        matches: ['found string'],
        count: 1,
        lines: ['This line contains a found string.']
    }
}

Example

findInFiles.find("I'm Brian, and so's my wife!", '.', '.txt$')
    .then(function(results) {
        for (var result in results) {
            var res = results[result];
            console.log(
                'found "' + res.matches[0] + '" ' + res.count
                + ' times in "' + result + '"'
            );
        }
    });
// Use object to set flags on regular expression. This one will ignore case.
findInFiles.find({'term': "I'm Brian, and so's my wife!", 'flags': 'ig'}, '.', '.txt$')
    .then(function(results) {
        for (var result in results) {
            var res = results[result];
            console.log(
                'found "' + res.matches[0] + '" ' + res.count
                + ' times in "' + result + '"'
            );
        }
    });

License

MIT © Philipp Nowinski

Current Tags

  • 0.5.0                                ...           latest (7 years ago)

7 Versions

  • 0.5.0                                ...           7 years ago
  • 0.4.0                                ...           8 years ago
  • 0.3.1                                ...           8 years ago
  • 0.2.1                                ...           9 years ago
  • 0.1.2                                ...           9 years ago
  • 0.1.1                                ...           10 years ago
  • 0.1.0                                ...           10 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (2)
Dev Dependencies (5)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |