forked from carstenschaefer/gulp-delete-lines
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
32 lines (27 loc) · 868 Bytes
/
Copy pathindex.js
File metadata and controls
32 lines (27 loc) · 868 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
var es = require('event-stream'),
gutil = require('gulp-util');
module.exports = function (opt) {
function gulpDeleteLines(file) {
if (file.isNull()) return this.emit('data', file);
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 newLines = [];
lines = str.split(/\r\n|\r|\n/g);
for (_i = 0; _i < lines.length; _i++) {
newLines.push(lines[_i]);
for (_j = 0; _j < opt.filters.length; _j++) {
if (lines[_i].match(opt.filters[_j])) {
newLines.pop();
break;
}
}
}
if (lines.length != newLines.length) {
str = newLines.join('\n');
file.contents = new Buffer(str);
}
this.emit('data', file);
}
return es.through(gulpDeleteLines);
};