1 | 'use strict';
|
2 |
|
3 | function spacerStr (len) {
|
4 | var str = '';
|
5 | for(var i = 0; i < len; i += 1) {
|
6 | str += ' ';
|
7 | }
|
8 | return str;
|
9 | }
|
10 |
|
11 | function StringWriter (config) {
|
12 | this.lines = [];
|
13 | this.lineSeparator = config.lineSeparator;
|
14 | this.regex = new RegExp(this.lineSeparator, 'g');
|
15 | this.spacer = spacerStr(config.outputOffset);
|
16 | }
|
17 |
|
18 | StringWriter.prototype.write = function (str) {
|
19 | this.lines.push(this.spacer + str.replace(this.regex, this.lineSeparator + this.spacer));
|
20 | };
|
21 |
|
22 | StringWriter.prototype.flush = function () {
|
23 | var str = this.lines.join(this.lineSeparator);
|
24 | this.lines.length = 0;
|
25 | return str;
|
26 | };
|
27 |
|
28 | module.exports = StringWriter;
|