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.3.1 to 0.4.0

33

index.js

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

fs = require('fs'),
Q = require('q');
Q = require('q'),
path = require('path');

@@ -57,3 +58,2 @@ function readFile(filename) {

var matchedFiles = []
for (var i = files.length - 1; i >= 0; i--) {

@@ -90,8 +90,12 @@ matchedFiles.push(readFile(files[i])

var deferred = Q.defer()
find.file(getFileFilter(fileFilter), directory, function(files) {
find
.file(getFileFilter(fileFilter), directory, function(files) {
Q.allSettled(getMatchedFiles(pattern, files))
.then(function(content) {
deferred.resolve(getResults(content));
});
.then(function (content) {
deferred.resolve(getResults(content));
})
.done();
})
.error(function (err){
deferred.reject(err)
});

@@ -102,10 +106,15 @@ return deferred.promise;

exports.findSync = function(pattern, directory, fileFilter) {
var deferred = Q.defer(),
var deferred = Q.defer();
var files;
try {
files = find.fileSync(getFileFilter(fileFilter), directory);
Q.allSettled(getMatchedFiles(pattern, files))
.then(function(content) {
Q.allSettled(getMatchedFiles(pattern, files))
.then(function (content) {
deferred.resolve(getResults(content));
});
})
.done();
} catch (err) {
deferred.reject(err)
}
return deferred.promise;
};
{
"name": "find-in-files",
"version": "0.3.1",
"version": "0.4.0",
"description": "A simple tool to search text patterns across multiple files",

@@ -25,3 +25,4 @@ "main": "index.js",

"devDependencies": {
"chai": "^1.9.1",
"chai": "^2.1.2",
"chai-as-promised": "^6.0.0",
"coveralls": "^2.10.1",

@@ -28,0 +29,0 @@ "istanbul": "^0.2.11",

@@ -13,4 +13,7 @@ 'use strict';

'flags': "ig"
};
},
chaiAsPromised = require('chai-as-promised'),
expect = require('chai').expect;
chai.use(chaiAsPromised);
chai.should();

@@ -21,4 +24,8 @@

this.timeout(15000);
it('should find stringOne only in fileOne exactly one time', function(done) {
findInFiles[method](stringOne, '.', '.txt$')
it('should handle error properly', function() {
return expect(findInFiles[method](stringOne, 'directorydoesnotexist', '.txt$')).to.be.rejected;
});
it('should find stringOne only in fileOne exactly one time', function() {
return findInFiles[method](stringOne, '.', '.txt$')
.then(function(result) {

@@ -31,8 +38,7 @@ var paths = constructPaths({

result.should.not.have.property(paths.second);
done();
});
});
it('should find stringTwo only in fileTwo exactly one time', function(done) {
findInFiles[method](stringTwo, '.', '.txt$')
it('should find stringTwo only in fileTwo exactly one time', function() {
return findInFiles[method](stringTwo, '.', '.txt$')
.then(function(result) {

@@ -45,8 +51,7 @@ var paths = constructPaths({

result.should.not.have.property(paths.second);
done();
});
});
it('should find stringThree in both files exactly one time', function(done) {
findInFiles[method](stringThree, '.', '.txt$')
it('should find stringThree in both files exactly one time', function() {
return findInFiles[method](stringThree, '.', '.txt$')
.then(function(result) {

@@ -59,8 +64,7 @@ var paths = constructPaths({

result[paths.second].count.should.equal(1);
done();
});
});
it('should find stringFour 2 times in fileOne and 3 times in fileTwo', function(done) {
findInFiles[method](stringFour, '.', '.txt$')
it('should find stringFour 2 times in fileOne and 3 times in fileTwo', function() {
return findInFiles[method](stringFour, '.', '.txt$')
.then(function(result) {

@@ -73,8 +77,7 @@ var paths = constructPaths({

result[paths.second].count.should.equal(3);
done();
});
});
it('should not find strings in the .js file', function(done) {
findInFiles[method](stringOne, '.', '.txt$')
it('should not find strings in the .js file', function() {
return findInFiles[method](stringOne, '.', '.txt$')
.then(function(result) {

@@ -87,8 +90,7 @@ var paths = constructPaths({

result.should.not.have.property(paths.second);
done();
});
});
it('should accept a regex object for fileFilter', function(done) {
findInFiles[method](stringOne, '.', /.txt$/)
it('should accept a regex object for fileFilter', function() {
return findInFiles[method](stringOne, '.', /.txt$/)
.then(function(result) {

@@ -102,8 +104,7 @@

result.should.not.have.property(paths.second);
done();
});
});
it('should find strings in all files', function(done) {
findInFiles[method](stringOne, 'test/')
it('should find strings in all files', function() {
return findInFiles[method](stringOne, 'test/')
.then(function(result) {

@@ -116,8 +117,7 @@ var paths = constructPaths({

result[paths.second].count.should.equal(1);
done();
});
});
it('should find stringOne twice in fileOne since we are case insensative', function(done) {
findInFiles[method](ObjectOne, '.', '.txt$')
it('should find stringOne twice in fileOne since we are case insensative', function() {
return findInFiles[method](ObjectOne, '.', '.txt$')
.then(function(result) {

@@ -130,3 +130,2 @@ var paths = constructPaths({

result.should.not.have.property(paths.second);
done();
});

@@ -133,0 +132,0 @@ });

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