From 5de0a375c8e13446c53d3aa72ca54d873b57cd22 Mon Sep 17 00:00:00 2001 From: lemures-t Date: Wed, 29 Jul 2015 01:15:35 +0800 Subject: [PATCH] realize multiple filters Since the filter option is a array, the module should support multiple filters. It will originally create the number of filter length times of html line when it comes to multiple filters. Now fixed it. --- index.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 031786b..da4a533 100644 --- a/index.js +++ b/index.js @@ -7,6 +7,7 @@ module.exports = function (opt) { if (file.isStream()) return this.emit('error', new Error("gulp-delete-lines: Streaming not supported")); var str = file.contents.toString('utf8'); var line, _i, _j, _len, lines; + var isMatched = true; var newLines = []; lines = str.split(/\r\n|\r|\n/g); @@ -14,8 +15,14 @@ module.exports = function (opt) { for (_i = 0; _i < lines.length; _i++) { for (_j = 0; _j < opt.filters.length; _j++) { - if (! lines[_i].match(opt.filters[_j])) { - newLines.push(lines[_i]); + if ( ! lines[_i].match(opt.filters[_j])) { + isMatched = false; + } + else{ + break; + } + if (_j == opt.filters.length-1 && !isMatched){ + newLines.push(lines[_i]); } } }