@@ -17,40 +17,40 @@ exports.create = function(headers, rows) {
1717 for ( var i = 0 ; i < rows . length ; i ++ ) {
1818 addTableRow ( rows [ i ] ) ;
1919 }
20- }
20+ } ;
2121
2222// Define list of columns for the table
2323exports . fieldNames = function ( names ) {
2424 addTableHeader ( names ) ;
25- }
25+ } ;
2626
2727// Add a single row to the table
2828exports . addRow = function ( row ) {
2929 addTableRow ( row ) ;
30- }
30+ } ;
3131
3232// Convert the table to string
3333exports . toString = function ( ) {
3434 return tableToString ( ) ;
35- }
35+ } ;
3636
3737// Write the table string to the console
3838exports . print = function ( ) {
3939 console . log ( tableToString ( ) ) ;
40- }
40+ } ;
4141
4242// Write the table string to the console as HTML table formats
4343exports . html = function ( attributes ) {
4444 return tableToHTML ( attributes ) ;
45- }
45+ } ;
4646
4747// Create the table from a CSV file
4848exports . csv = function ( filename ) {
4949 var stream = fs . createReadStream ( filename ) ;
5050 line_counter = 0 ;
5151 var csvStream = csv ( )
5252 . on ( "data" , function ( data ) {
53- if ( line_counter == 0 ) {
53+ if ( line_counter === 0 ) {
5454 addTableHeader ( data ) ;
5555 line_counter += 1 ;
5656 } else {
@@ -62,67 +62,67 @@ exports.csv = function(filename) {
6262 console . log ( tableToString ( ) ) ;
6363 } ) ;
6464 stream . pipe ( csvStream ) ;
65- }
65+ } ;
6666
6767// Create the table from a JSON file
6868exports . json = function ( filename ) {
6969 var jsondata = JSON . parse ( fs . readFileSync ( filename , 'utf8' ) ) ;
7070 for ( var i = 0 ; i < jsondata . length ; i ++ ) {
7171 rowKeys = Object . keys ( jsondata [ i ] ) ;
72- rowVals = [ ]
72+ rowVals = [ ] ;
7373 for ( var k = 0 ; k < rowKeys . length ; k ++ ) {
7474 rowVals . push ( jsondata [ i ] [ rowKeys [ k ] ] ) ;
7575 }
76- if ( table . columnNames . length == 0 ) {
76+ if ( table . columnNames . length === 0 ) {
7777 addTableHeader ( rowKeys ) ;
7878 }
7979 addTableRow ( rowVals ) ;
8080 }
8181 console . log ( tableToString ( ) ) ;
82- }
82+ } ;
8383
8484// Sort the table given a column in ascending or descending order
8585exports . sortTable = function ( colname , reverse ) {
8686 var reverseSort = false ;
87- if ( typeof ( reverse ) == "boolean" && reverse == true ) {
87+ if ( typeof ( reverse ) === "boolean" && reverse = == true ) {
8888 reverseSort = true ;
8989 }
9090 sortTableByColumn ( colname , reverseSort ) ;
91- }
91+ } ;
9292
9393// Delete a single row from the table given row number
9494exports . deleteRow = function ( rownum ) {
9595 if ( rownum <= table . rows . length && rownum > 0 ) {
9696 table . rows . splice ( rownum - 1 , 1 ) ;
9797 }
98- }
98+ } ;
9999
100100// Clear the contents from the table, but keep columns and structure
101101exports . clearTable = function ( ) {
102102 table . rows = [ ] ;
103- }
103+ } ;
104104
105105// Delete the entire table
106106exports . deleteTable = function ( ) {
107107 table = { "columnNames" : [ ] , "rows" : [ ] , "maxWidth" : [ ] } ;
108- }
108+ } ;
109109
110110// Draw a line based on the max width of each column and return
111111var drawLine = function ( ) {
112112 arrayLength = 0 ;
113113 for ( var i = 0 ; i < table . maxWidth . length ; i ++ ) {
114114 arrayLength += table . maxWidth [ i ] ;
115115 }
116- return '+' + Array ( arrayLength + table . maxWidth . length * 3 ) . join ( '-' ) + '+'
117- }
116+ return '+' + Array ( arrayLength + table . maxWidth . length * 3 ) . join ( '-' ) + '+' ;
117+ } ;
118118
119119// Helper method to add column names of the table and add maxwidth for each column element
120120var addTableHeader = function ( names ) {
121121 table . columnNames = names ;
122122 for ( var i = 0 ; i < names . length ; i ++ ) {
123123 table . maxWidth . push ( names [ i ] . length ) ;
124124 }
125- }
125+ } ;
126126
127127// Helper method to add a row to the table and re-adjust max width of each row element
128128var addTableRow = function ( row ) {
@@ -132,15 +132,15 @@ var addTableRow = function(row) {
132132 table . maxWidth [ i ] = row [ i ] . toString ( ) . length ;
133133 }
134134 }
135- }
135+ } ;
136136
137137// Convert the table to string and return
138138var tableToString = function ( ) {
139139 // Define final table string as empty string
140140 finalTable = "" ;
141141
142142 // If no columns present, return empty string
143- if ( table . columnNames . length == 0 ) {
143+ if ( table . columnNames . length === 0 ) {
144144 return finalTable ;
145145 }
146146
@@ -152,7 +152,7 @@ var tableToString = function() {
152152 // Adjust for max width of the column and pad spaces
153153 if ( table . columnNames [ i ] . length < table . maxWidth [ i ] ) {
154154 lengthDifference = table . maxWidth [ i ] - table . columnNames [ i ] . length ;
155- columnString += Array ( lengthDifference + 1 ) . join ( ' ' )
155+ columnString += Array ( lengthDifference + 1 ) . join ( ' ' ) ;
156156 }
157157 columnString += " | " ;
158158 }
@@ -161,14 +161,14 @@ var tableToString = function() {
161161 finalTable += drawLine ( ) + "\n" ;
162162
163163 // Construct the table body
164- for ( var i = 0 ; i < table . rows . length ; i ++ ) {
164+ for ( i = 0 ; i < table . rows . length ; i ++ ) {
165165 var tempRowString = "| " ;
166166 for ( var k = 0 ; k < table . rows [ i ] . length ; k ++ ) {
167167 tempRowString += table . rows [ i ] [ k ] ;
168168 // Adjust max width of each cell and pad spaces as necessary
169169 if ( table . rows [ i ] [ k ] . toString ( ) . length < table . maxWidth [ k ] ) {
170170 lengthDifference = table . maxWidth [ k ] - table . rows [ i ] [ k ] . toString ( ) . length ;
171- tempRowString += Array ( lengthDifference + 1 ) . join ( ' ' )
171+ tempRowString += Array ( lengthDifference + 1 ) . join ( ' ' ) ;
172172 }
173173 tempRowString += " | " ;
174174 }
@@ -186,15 +186,16 @@ var tableToString = function() {
186186// Convert the table to HTML table
187187var tableToHTML = function ( attributes ) {
188188 // If attributes provided, add them as inline properties, else create default table tag
189+ var htmlTable = "" ;
189190 if ( typeof attributes == "undefined" ) {
190- var htmlTable = "<table>" ;
191+ htmlTable = "<table>" ;
191192 } else {
192193 var attributeList = [ ] ;
193194 for ( var key in attributes ) {
194195 attributeList . push ( key + '="' + attributes [ key ] + '"' ) ;
195196 }
196197 var attributeString = attributeList . join ( " " ) ;
197- var htmlTable = "<table " + attributeString + ">" ;
198+ htmlTable = "<table " + attributeString + ">" ;
198199 }
199200
200201 // Define the table headers in <thead> from table column list
@@ -208,7 +209,7 @@ var tableToHTML = function(attributes) {
208209
209210 // Construct the table body from the array of rows
210211 var tableBody = "<tbody>" ;
211- for ( var i = 0 ; i < table . rows . length ; i ++ ) {
212+ for ( i = 0 ; i < table . rows . length ; i ++ ) {
212213 var rowData = "<tr>" ;
213214 for ( var k = 0 ; k < table . rows [ i ] . length ; k ++ ) {
214215 var cellData = "<td>" + table . rows [ i ] [ k ] + "</td>" ;
@@ -223,7 +224,7 @@ var tableToHTML = function(attributes) {
223224 htmlTable += "</table>" ;
224225
225226 return htmlTable ;
226- }
227+ } ;
227228
228229// Helper method to sort table given column name
229230var sortTableByColumn = function ( colname , reverse ) {
@@ -232,7 +233,7 @@ var sortTableByColumn = function(colname, reverse) {
232233
233234 // Comparator method which takes the column index and sort direction
234235 function Comparator ( a , b ) {
235- if ( reverse == true ) {
236+ if ( reverse === true ) {
236237 if ( a [ colindex ] < b [ colindex ] ) return 1 ;
237238 if ( a [ colindex ] > b [ colindex ] ) return - 1 ;
238239 return 0 ;
@@ -244,6 +245,6 @@ var sortTableByColumn = function(colname, reverse) {
244245 }
245246 // Sort array of table rows
246247 table . rows = table . rows . sort ( Comparator ) ;
247- }
248+ } ;
248249
249250exports . version = "0.3.0" ;
0 commit comments