Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

find-in-files

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

find-in-files - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

.travis.yml

14

index.js

@@ -5,4 +5,3 @@ 'use strict';

fs = require('fs'),
Q = require('q'),
deferred = Q.defer();
Q = require('q');

@@ -26,5 +25,10 @@ function readFile(filename) {

matchedFiles = [],
results = [];
results = [],
deferred = Q.defer();
if (typeof fileFilter === 'string') {
fileFilter = new RegExp(fileFilter);
} else {
fileFilter = new RegExp('.*');
}
find.file(fileFilter, directory, function(files) {
console.log(files.length);
for (var i = files.length - 1; i >= 0; i--) {

@@ -49,2 +53,2 @@ matchedFiles.push(readFile(files[i])

return deferred.promise;
};
};
{
"name": "find-in-files",
"version": "0.1.0",
"version": "0.1.1",
"description": "A simple tool to search text patterns across multiple files",
"main": "index.js",
"scripts": {
"test": "mocha"
"test": "istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage"
},

@@ -9,0 +9,0 @@ "repository": {

@@ -1,4 +0,60 @@

find-in-files
find-in-files [![Build Status](https://travis-ci.org/kaesetoast/find-in-files.svg?branch=master)](https://travis-ci.org/kaesetoast/find-in-files) [![Coverage Status](https://img.shields.io/coveralls/kaesetoast/find-in-files.svg)](https://coveralls.io/r/kaesetoast/find-in-files)
=============
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.
```JavaScript
find(pattern, directory, fileFilter)
```
#### pattern [string]
The string you want to search for.
#### 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.
```JavaScript
var findInFiles = require('find-in-files');
```
The find function returns a promise which will recieve the results object. The results object contains the matches and a count of matches per file.
```JavaScript
{
'fileOne.txt': {
matches: ['found string'],
count: 1
}
}
```
## Example
```JavaScript
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 + '"'
);
}
});
```
## License
MIT © [Philipp Nowinski](http://philippnowinski.de)

@@ -1,1 +0,3 @@

Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius. Claritas est etiam processus dynamicus, qui sequitur mutationem consuetudium lectorum. Mirum est notare quam littera gothica, quam nunc putamus parum claram, anteposuerit litterarum formas humanitatis per seacula quarta decima et quinta decima. Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum.
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius. Claritas est etiam processus dynamicus, qui sequitur mutationem consuetudium lectorum. Mirum est notare quam littera gothica, quam nunc putamus parum claram, anteposuerit litterarum formas humanitatis per seacula quarta decima et quinta decima. Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum.
This is in both files
This is duplicate This is duplicate
'use strict';
var chai = require('chai'),
findInFiles = require('../index');
findInFiles = require('../index'),
stringOne = 'dolor sit amet',
stringTwo = 'Träumen',
stringThree = 'This is in both files',
stringFour = 'This is duplicate';

@@ -9,9 +13,55 @@ chai.should();

describe('find some test strings', function () {
it('should find stringOne in fileOne exactly one time', function (done) {
findInFiles.find('dolor sit amet', '.', '.txt$')
it('should find stringOne only in fileOne exactly one time', function (done) {
findInFiles.find(stringOne, '.', '.txt$')
.then(function(result) {
result['fileOne.txt'].count.should.equal(1);
result['test/fileOne.txt'].count.should.equal(1);
result.should.not.have.property('test/fileTwo.txt');
done();
});
});
});
it('should find stringTwo only in fileTwo exactly one time', function (done) {
findInFiles.find(stringTwo, '.', '.txt$')
.then(function(result) {
result['test/fileTwo.txt'].count.should.equal(1);
result.should.not.have.property('test/fileOne.txt');
done();
});
});
it('should find stringThree in both files exactly one time', function (done) {
findInFiles.find(stringThree, '.', '.txt$')
.then(function(result) {
result['test/fileOne.txt'].count.should.equal(1);
result['test/fileTwo.txt'].count.should.equal(1);
done();
});
});
it('should find stringFour 2 times in fileOne and 3 times in fileTwo', function (done) {
findInFiles.find(stringFour, '.', '.txt$')
.then(function(result) {
result['test/fileOne.txt'].count.should.equal(2);
result['test/fileTwo.txt'].count.should.equal(3);
done();
});
});
it('should not find strings in the .js file', function (done) {
findInFiles.find(stringOne, '.', '.txt$')
.then(function(result) {
result['test/fileOne.txt'].count.should.equal(1);
result.should.not.have.property('test/fileOne.md');
done();
});
});
it('should find strings in all files', function (done) {
findInFiles.find(stringOne, '.')
.then(function(result) {
result['test/fileOne.txt'].count.should.equal(1);
result['test/fileOne.md'].count.should.equal(1);
done();
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc