Code Monkey home page Code Monkey logo

find-in-files's Introduction

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 a simple find function that expects three parameters.

find(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');

The find function returns 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

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.