Skip to content

Commit

Permalink
Improved code quality
Browse files Browse the repository at this point in the history
  • Loading branch information
T-PWK committed Nov 25, 2014
1 parent 1855f00 commit 17114e6
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions lib/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,22 @@
}

function filter(self, line) {
var emit = self._include.length === 0, i;

for(i = self._include.length - 1; i >= 0; i--) {
if(self._include[i].test(line)) {
emit = true;
break;
}
}
// Check if the line of text matches includes and does not match excludes
if(checkFilters(self._include, line, true, self._include.length === 0) &&
checkFilters(self._exclude, line, false, true)) {

for(i = self._exclude.length - 1; i >= 0; i--) {
if(self._exclude[i].test(line)) {
emit = false;
break;
}
self.push(line);
}
}

if(emit) {
self.push(line);
function checkFilters (patterns, line, hasMatch, noMatch) {
for(var i = patterns.length - 1; i >= 0; i--) {
if(patterns[i].test(line)) {
return hasMatch;
}
}
return noMatch;
}

LineFilter.prototype._transform = function (line, encoding, done) {
Expand Down

0 comments on commit 17114e6

Please sign in to comment.