-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
55 lines (51 loc) · 1.44 KB
/
index.js
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Generated by CoffeeScript 1.9.3
var gutil, isEmptyLine, through;
through = require("through2");
gutil = require("gulp-util");
isEmptyLine = function(string) {
return string === "" || string === "\r";
};
module.exports = function(options) {
var indent;
if (options == null) {
options = {};
}
if (options.tabs == null) {
options.tabs = false;
}
if (options.amount == null) {
options.amount = 2;
}
indent = function(file, enc, done) {
var character, i, indentation, line, lines, number, ref;
if (file.isNull()) {
this.push(file);
return done();
}
if (file.isStream()) {
this.emit("error", new gutil.PluginError("gulp-indent", "Stream content is not supported"));
return done();
}
if (file.isBuffer()) {
character = options.tabs ? "\t" : " ";
indentation = "";
for (number = i = 0, ref = options.amount; 0 <= ref ? i < ref : i > ref; number = 0 <= ref ? ++i : --i) {
indentation += character;
}
lines = file.contents.toString().split("\n");
lines = (function() {
var j, len, results;
results = [];
for (j = 0, len = lines.length; j < len; j++) {
line = lines[j];
results.push(!isEmptyLine(line) ? indentation + line : line);
}
return results;
})();
file.contents = new Buffer(lines.join("\n"));
this.push(file);
}
return done();
};
return through.obj(indent);
};