Comparing version 1.0.6 to 1.0.7
28
index.js
/// <reference path="./index.ts" /> | ||
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 ConsoleTable = (function () { | ||
function ConsoleTable(tableType) { | ||
switch (tableType) { | ||
function ConsoleTable(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: | ||
@@ -12,3 +27,3 @@ break; | ||
this.rows = []; | ||
this.type = tableType; | ||
this.type = tableTypeArg; | ||
} | ||
@@ -20,4 +35,3 @@ ConsoleTable.prototype.push = function (row) { | ||
var table = new BeautylogOsTable.cliTable({ | ||
head: this.tableHead, | ||
colWidths: [20, 20] | ||
head: this.tableHead | ||
}); | ||
@@ -159,4 +173,4 @@ for (var row in this.rows) { | ||
var beautylogOsTable = {}; | ||
beautylogOsTable.new = function (type) { | ||
var newConsoleTable = new ConsoleTable(type); | ||
beautylogOsTable.new = function (typeArg, tableHeadArrayArg) { | ||
var newConsoleTable = new ConsoleTable(typeArg, tableHeadArrayArg); | ||
return newConsoleTable; | ||
@@ -163,0 +177,0 @@ }; |
{ | ||
"name": "beautylog", | ||
"version": "1.0.6", | ||
"version": "1.0.7", | ||
"description": "beautiful logging", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -33,5 +33,9 @@ # beautylog | ||
There are different types of tables. | ||
#### Custom | ||
```javascript | ||
var bl = require('beautylog')("os"); //for use in OS console environment | ||
var myTable = bl.table.new("checks"); //you can specify a format like "checks" to trigger things like the green and red badges | ||
var myTable = bl.table.new("custom",["Heading1".blue,"Heading2".blue,"Heading3".blue]); // type "custom" | ||
myTable.push(["check 1","success"]); // adds a row the myTable | ||
@@ -43,3 +47,14 @@ myTable.push(["check 2","error"]); // adds a row the myTable | ||
The table from the code above looks like this: | ||
#### Checks | ||
```javascript | ||
var bl = require('beautylog')("os"); //for use in OS console environment | ||
var myTable = bl.table.new("checks"); // type checks | ||
myTable.push(["check 1","success"]); // adds a row the myTable | ||
myTable.push(["check 2","error"]); // adds a row the myTable | ||
myTable.push(["check 3","error"]); // adds a row the myTable | ||
myTable.print(); //prints myTable to the console | ||
``` | ||
The table from the code with type "checks" above looks like this: | ||
![table.png](https://mediaserve.lossless.digital/github.com/pushrocks/beautylog/table.png) |
15
test.js
@@ -29,7 +29,12 @@ /// <reference path="./typings/tsd.d.ts" /> | ||
console.log("*** start table test ***"); | ||
var testTable = beautyLogOs.table.new("checks"); | ||
testTable.push(['check1', 'success']); | ||
testTable.push(['check2', 'error']); | ||
testTable.push(['check3', 'error']); | ||
testTable.print(); | ||
(function () { | ||
var testTable1 = beautyLogOs.table.new("checks"); | ||
testTable1.push(['check1', 'success']); | ||
testTable1.push(['check2', 'error']); | ||
testTable1.push(['check3', 'error']); | ||
testTable1.print(); | ||
var testTable2 = beautyLogOs.table.new("custom", ["Column1".red, "Column2".blue, "Column3".cyan]); | ||
testTable2.push(["Hey", "this", "works"]); | ||
testTable2.print(); | ||
})(); | ||
console.log("*** end table test ***"); |
/// <reference path="./index.ts" /> | ||
var tableHelpers = { | ||
makeRow: function(cellCounterArg:number = 2,colorArg:string = "cyan"){ | ||
var rowArray = []; | ||
for (var i = 0; i < (cellCounterArg); i++) { | ||
rowArray.push(String(i + 1).cyan); | ||
} | ||
return rowArray; | ||
} | ||
}; | ||
@@ -7,7 +16,10 @@ class ConsoleTable { | ||
type:string; | ||
constructor(tableType:string) { | ||
switch (tableType) { | ||
constructor(tableTypeArg:string,tableHeadArrayArg:string[] = tableHelpers.makeRow()) { | ||
switch (tableTypeArg) { | ||
case "checks": | ||
this.tableHead = ['Check Item:'.cyan,'Status:'.cyan]; | ||
break; | ||
case "custom": | ||
this.tableHead = tableHeadArrayArg; | ||
break; | ||
default: | ||
@@ -17,3 +29,3 @@ break; | ||
this.rows = []; | ||
this.type = tableType; | ||
this.type = tableTypeArg; | ||
} | ||
@@ -25,4 +37,3 @@ push(row:string[]){ | ||
var table = new BeautylogOsTable.cliTable({ | ||
head: this.tableHead, | ||
colWidths: [20, 20] | ||
head: this.tableHead | ||
}); | ||
@@ -29,0 +40,0 @@ for (var row in this.rows){ |
@@ -8,4 +8,4 @@ /// <reference path="./index.ts" /> | ||
beautylogOsTable.new = function(type:string) { | ||
var newConsoleTable = new ConsoleTable(type); | ||
beautylogOsTable.new = function(typeArg:string,tableHeadArrayArg?) { | ||
var newConsoleTable = new ConsoleTable(typeArg,tableHeadArrayArg); | ||
return newConsoleTable; | ||
@@ -12,0 +12,0 @@ }; |
@@ -36,7 +36,16 @@ /// <reference path="./typings/tsd.d.ts" /> | ||
console.log("*** start table test ***"); | ||
var testTable = beautyLogOs.table.new("checks"); | ||
testTable.push(['check1','success']); | ||
testTable.push(['check2','error']); | ||
testTable.push(['check3','error']); | ||
testTable.print(); | ||
(function(){ | ||
var testTable1 = beautyLogOs.table.new("checks"); | ||
testTable1.push(['check1','success']); | ||
testTable1.push(['check2','error']); | ||
testTable1.push(['check3','error']); | ||
testTable1.print(); | ||
var testTable2 = beautyLogOs.table.new("custom",["Column1".red,"Column2".blue,"Column3".cyan]); | ||
testTable2.push(["Hey","this","works"]); | ||
testTable2.print(); | ||
})(); | ||
console.log("*** end table test ***"); |
117802
2608
58