-
Notifications
You must be signed in to change notification settings - Fork 0
/
reportformatter.js
53 lines (46 loc) · 1.01 KB
/
reportformatter.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
'use strict';
function leftpad(str, len) {
var i = -1;
len = len - str.length;
while (++i < len) {
str = ' ' + str;
}
return str;
}
function formatCells(cells) {
if (cells.length === 0) {
return '';
}
let line = ' ';
let label = cells.shift();
line += leftpad(label.Value, 35);
cells.forEach(function(cell) {
line += leftpad(cell.Value, 15);
});
return line;
}
function basicRow(row) {
return formatCells(row.Cells);
}
let formaters = {
Header: basicRow,
Section: function(row) {
return '\n' + row.Title + '\n' +
row.Rows.map(formatRow).join('\n');
},
Row: basicRow,
SummaryRow: basicRow
};
function formatRow(row) {
return formaters[row.RowType](row);
}
function formatReport(rep) {
let text = '';
rep.ReportTitles.forEach(function(title) {
text += title + '\n';
});
text += '\n';
text += rep.Rows.map(formatRow).join('\n');
return text;
}
module.exports = formatReport;