smartlog-destination-local/dist/beautylog.classes.table.js
2016-05-14 01:18:44 +02:00

55 lines
6.3 KiB
JavaScript

"use strict";
/// <reference path="./typings/main.d.ts" />
var plugins = require("./beautylog.plugins");
var tableHelpers = {
makeRow: function (cellCounterArg, colorArg) {
if (cellCounterArg === void 0) { cellCounterArg = 2; }
if (colorArg === void 0) { colorArg = "cyan"; }
var rowArray = [];
for (var i = 0; i < (cellCounterArg); i++) {
rowArray.push(String(i + 1).cyan);
}
return rowArray;
}
};
var Table = (function () {
function Table(tableTypeArg, tableHeadArrayArg) {
if (tableHeadArrayArg === void 0) { tableHeadArrayArg = tableHelpers.makeRow(); }
switch (tableTypeArg) {
case "checks":
this.tableHead = ['Check Item:'.cyan, 'Status:'.cyan];
break;
case "custom":
this.tableHead = tableHeadArrayArg;
break;
default:
break;
}
this.rows = [];
this.type = tableTypeArg;
}
Table.prototype.push = function (row) {
this.rows.push(row);
};
Table.prototype.print = function () {
var table = new plugins.cliTable({
head: this.tableHead
});
for (var row in this.rows) {
if (this.rows[row][1] == "success") {
this.rows[row][1] = ' '.bgGreen + ' ' + this.rows[row][1];
}
else if (this.rows[row][1] == "error") {
this.rows[row][1] = ' '.bgRed + ' ' + this.rows[row][1];
}
table.push(this.rows[row]);
}
;
console.log(table.toString());
};
return Table;
}());
exports.Table = Table;
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImJlYXV0eWxvZy5jbGFzc2VzLnRhYmxlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSw0Q0FBNEM7QUFDNUMsSUFBWSxPQUFPLFdBQU0scUJBQXFCLENBQUMsQ0FBQTtBQUUvQyxJQUFJLFlBQVksR0FBRztJQUNmLE9BQU8sRUFBRSxVQUFTLGNBQXlCLEVBQUMsUUFBd0I7UUFBbEQsOEJBQXlCLEdBQXpCLGtCQUF5QjtRQUFDLHdCQUF3QixHQUF4QixpQkFBd0I7UUFDaEU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WFuLCdTdGF0dXM6Jy5jeWFuXTtcclxuICAgICAgICAgICAgICAgIGJyZWFrO1xyXG4gICAgICAgICAgICBjYXNlIFwiY3VzdG9tXCI6XHJcbiAgICAgICAgICAgICAgICB0aGlzLnRhYmxlSGVhZCA9IHRhYmxlSGVhZEFycmF5QXJnO1xyXG4gICAgICAgICAgICAgICAgYnJlYWs7XHJcbiAgICAgICAgICAgIGRlZmF1bHQ6XHJcbiAgICAgICAgICAgICAgICBicmVhaztcclxuICAgICAgICB9XHJcbiAgICAgICAgdGhpcy5yb3dzID0gW107XHJcbiAgICAgICAgdGhpcy50eXBlID0gdGFibGVUeXBlQXJnO1xyXG4gICAgfVxyXG4gICAgcHVzaChyb3c6c3RyaW5nW10pe1xyXG4gICAgICAgIHRoaXMucm93cy5wdXNoKHJvdyk7XHJcbiAgICB9XHJcbiAgICBwcmludCgpIHtcclxuICAgICAgICBsZXQgdGFibGUgPSBuZXcgcGx1Z2lucy5jbGlUYWJsZSh7XHJcbiAgICAgICAgICAgIGhlYWQ6IHRoaXMudGFibGVIZWFkXHJcbiAgICAgICAgfSk7XHJcbiAgICAgICAgZm9yIChsZXQgcm93IGluIHRoaXMucm93cyl7XHJcbiAgICAgICAgICAgIGlmKHRoaXMucm93c1tyb3ddWzFdID09IFwic3VjY2Vzc1wiKXtcclxuICAgICAgICAgICAgICAgIHRoaXMucm93c1tyb3ddWzFdID0gJyAnLmJnR3JlZW4gKyAnICcgKyB0aGlzLnJvd3Nbcm93XVsxXTtcclxuICAgICAgICAgICAgfSBlbHNlIGlmICh0aGlzLnJvd3Nbcm93XVsxXSA9PSBcImVycm9yXCIpIHtcclxuICAgICAgICAgICAgICAgIHRoaXMucm93c1tyb3ddWzFdID0gJyAnLmJnUmVkICsgJyAnICsgdGhpcy5yb3dzW3Jvd11bMV07XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgdGFibGUucHVzaCh0aGlzLnJvd3Nbcm93XSk7XHJcbiAgICAgICAgfTtcclxuICAgICAgICBjb25zb2xlLmxvZyh0YWJsZS50b1N0cmluZygpKTtcclxuICAgIH1cclxufSJdfQ==