diff --git a/advanced-usage.md b/advanced-usage.md index 939e4f4..5458c3d 100644 --- a/advanced-usage.md +++ b/advanced-usage.md @@ -7,12 +7,12 @@ │ hello │ howdy │ └───────┴───────┘ ```javascript - var table = new Table({style:{head:[],border:[]}}); + let table = new Table({ style: { head: [], border: [] } }); table.push( - [{colSpan:2,content:'greetings'}], - [{colSpan:2,content:'greetings'}], - ['hello','howdy'] + [{ colSpan: 2, content: 'greetings' }], + [{ colSpan: 2, content: 'greetings' }], + ['hello', 'howdy'] ); ``` @@ -27,12 +27,12 @@ │ greetings │ └───────────────┘ ```javascript - var table = new Table({style:{head:[],border:[]}}); + let table = new Table({ style: { head: [], border: [] } }); table.push( - ['hello','howdy'], - [{colSpan:2,content:'greetings'}], - [{colSpan:2,content:'greetings'}] + ['hello', 'howdy'], + [{ colSpan: 2, content: 'greetings' }], + [{ colSpan: 2, content: 'greetings' }] ); ``` @@ -45,10 +45,10 @@ │ │ │ howdy │ └───────────┴───────────┴───────┘ ```javascript - var table = new Table({style:{head:[],border:[]}}); + let table = new Table({ style: { head: [], border: [] } }); table.push( - [{rowSpan:2,content:'greetings'},{rowSpan:2,content:'greetings',vAlign:'center'},'hello'], + [{ rowSpan: 2, content: 'greetings' }, { rowSpan: 2, content: 'greetings', vAlign: 'center' }, 'hello'], ['howdy'] ); @@ -62,10 +62,10 @@ │ howdy │ │ greetings │ └───────┴───────────┴───────────┘ ```javascript - var table = new Table({style:{head:[],border:[]}}); + let table = new Table({ style: { head: [], border: [] } }); table.push( - ['hello',{rowSpan:2,content:'greetings'},{rowSpan:2,content:'greetings',vAlign:'bottom'}], + ['hello', { rowSpan: 2, content: 'greetings' }, { rowSpan: 2, content: 'greetings', vAlign: 'bottom' }], ['howdy'] ); @@ -81,12 +81,16 @@ │ o │ k │ │ │ │ └───┴───┴──┴──┴────┘ ```javascript - var table = new Table({style:{head:[],border:[]}}); + let table = new Table({ style: { head: [], border: [] } }); table.push( - [{content:'hello',colSpan:2},{rowSpan:2, colSpan:2,content:'sup'},{rowSpan:3,content:'hi'}], - [{content:'howdy',colSpan:2}], - ['o','k','',''] + [ + { content: 'hello', colSpan: 2 }, + { rowSpan: 2, colSpan: 2, content: 'sup' }, + { rowSpan: 3, content: 'hi' }, + ], + [{ content: 'howdy', colSpan: 2 }], + ['o', 'k', '', ''] ); ``` @@ -99,10 +103,10 @@ │ howdy │ │ │ └───────┴───────────┴───────────┘ ```javascript - var table = new Table({style:{head:[],border:[]}}); + let table = new Table({ style: { head: [], border: [] } }); table.push( - ['hello',{rowSpan:2,content:'greetings\nfriends'},{rowSpan:2,content:'greetings\nfriends'}], + ['hello', { rowSpan: 2, content: 'greetings\nfriends' }, { rowSpan: 2, content: 'greetings\nfriends' }], ['howdy'] ); @@ -118,12 +122,16 @@ │ o │ k │ │ │ │ └───┴───┴──┴──┴────┘ ```javascript - var table = new Table({style:{head:[],border:[]}}); + let table = new Table({ style: { head: [], border: [] } }); table.push( - [{content:'hello',colSpan:2},{rowSpan:2, colSpan:2,content:'sup\nman\nhey'},{rowSpan:3,content:'hi\nyo'}], - [{content:'howdy',colSpan:2}], - ['o','k','',''] + [ + { content: 'hello', colSpan: 2 }, + { rowSpan: 2, colSpan: 2, content: 'sup\nman\nhey' }, + { rowSpan: 3, content: 'hi\nyo' }, + ], + [{ content: 'howdy', colSpan: 2 }], + ['o', 'k', '', ''] ); ``` @@ -138,11 +146,11 @@ │ d │ │ └───┴───┘ ```javascript - var table = new Table({style:{head:[],border:[]}}); + let table = new Table({ style: { head: [], border: [] } }); table.push( - [{content:'a',rowSpan:2},'b'], - [{content:'c',rowSpan:2}], + [{ content: 'a', rowSpan: 2 }, 'b'], + [{ content: 'c', rowSpan: 2 }], ['d'] ); @@ -160,13 +168,13 @@ │ │ │ └───┴──────┘ ```javascript - var table = new Table({style:{head:[],border:[]}}); + let table = new Table({ style: { head: [], border: [] } }); //notice we only create 3 cells here, but the table ends up having 6. table.push( - [{content:'a',rowSpan:3,colSpan:2},'b'], + [{ content: 'a', rowSpan: 3, colSpan: 2 }, 'b'], [], - [{content:'c',rowSpan:2,colSpan:2}], + [{ content: 'c', rowSpan: 2, colSpan: 2 }], [] ); ``` @@ -178,7 +186,10 @@ │ hi… │ └───────┘ ```javascript - var table = new Table({rowHeights:[2],style:{head:[],border:[]}}); + let table = new Table({ + rowHeights: [2], + style: { head: [], border: [] }, + }); table.push(['hello\nhi\nsup']); @@ -192,10 +203,10 @@ │ hi │ hi │ └──────┴──────┘ ```javascript - var table = new Table({style:{head:[],border:[]}}); + let table = new Table({ style: { head: [], border: [] } }); table.push( - [{colSpan:2,content:'hello there'}], + [{ colSpan: 2, content: 'hello there' }], ['hi', 'hi'] ); @@ -209,11 +220,14 @@ │ hi │ hi │ └────┴────────┘ ```javascript - var table = new Table({colWidths:[4],style:{head:[],border:[]}}); + let table = new Table({ + colWidths: [4], + style: { head: [], border: [] }, + }); table.push( - [{colSpan:2,content:'hello there'}], - ['hi',{hAlign:'center',content:'hi'}] + [{ colSpan: 2, content: 'hello there' }], + ['hi', { hAlign: 'center', content: 'hi' }] ); ``` @@ -226,11 +240,14 @@ │ hi │ hi │ └────────┴────┘ ```javascript - var table = new Table({colWidths:[null, 4],style:{head:[],border:[]}}); + let table = new Table({ + colWidths: [null, 4], + style: { head: [], border: [] }, + }); table.push( - [{colSpan:2,content:'hello there'}], - [{hAlign:'right',content:'hi'}, 'hi'] + [{ colSpan: 2, content: 'hello there' }], + [{ hAlign: 'right', content: 'hi' }, 'hi'] ); ``` @@ -239,7 +256,10 @@ ##### feel free to use colors in your content strings, column widths will be calculated correctly ![table image](./examples/screenshots/truncation-with-colors.png) ```javascript - var table = new Table({colWidths:[5],style:{head:[],border:[]}}); + let table = new Table({ + colWidths: [5], + style: { head: [], border: [] }, + }); table.push([colors.red('hello')]); diff --git a/basic-usage.md b/basic-usage.md index 6d95524..0bc35dc 100644 --- a/basic-usage.md +++ b/basic-usage.md @@ -2,9 +2,9 @@ ![table image](./examples/screenshots/basic-usage-with-colors.png) ```javascript // By default, headers will be red, and borders will be grey - var table = new Table({head:['a','b']}); + let table = new Table({ head: ['a', 'b'] }); - table.push(['c','d']); + table.push(['c', 'd']); ``` @@ -21,18 +21,18 @@ // For most of these examples, and most of the unit tests we disable colors. // It makes unit tests easier to write/understand, and allows these pages to // display the examples as text instead of screen shots. - var table = new Table({ - head: ['Rel', 'Change', 'By', 'When'] - , style: { - head: [] //disable colors in header cells - , border: [] //disable colors for the border - } - , colWidths: [6, 21, 25, 17] //set the widths of each column (optional) + let table = new Table({ + head: ['Rel', 'Change', 'By', 'When'], + style: { + head: [], //disable colors in header cells + border: [], //disable colors for the border + }, + colWidths: [6, 21, 25, 17], //set the widths of each column (optional) }); table.push( - ['v0.1', 'Testing something cool', 'rauchg@gmail.com', '7 minutes ago'] - , ['v0.1', 'Testing something cool', 'rauchg@gmail.com', '8 minutes ago'] + ['v0.1', 'Testing something cool', 'rauchg@gmail.com', '7 minutes ago'], + ['v0.1', 'Testing something cool', 'rauchg@gmail.com', '8 minutes ago'] ); ``` @@ -45,11 +45,13 @@ │v0.1│Testing something cool│ └────┴──────────────────────┘ ```javascript - var table = new Table({ style: {'padding-left':0, 'padding-right':0, head:[], border:[]} }); + let table = new Table({ + style: { 'padding-left': 0, 'padding-right': 0, head: [], border: [] }, + }); table.push( - {'v0.1': 'Testing something cool'} - , {'v0.1': 'Testing something cool'} + { 'v0.1': 'Testing something cool' }, + { 'v0.1': 'Testing something cool' } ); ``` @@ -64,11 +66,14 @@ │Header 4│v0.1 │Testing something cool│ └────────┴────────┴──────────────────────┘ ```javascript - var table = new Table({ head: ["", "Header 1", "Header 2"], style: {'padding-left':0, 'padding-right':0, head:[], border:[]} }); // clear styles to prevent color output + let table = new Table({ + head: ['', 'Header 1', 'Header 2'], + style: { 'padding-left': 0, 'padding-right': 0, head: [], border: [] }, + }); // clear styles to prevent color output table.push( - {"Header 3": ['v0.1', 'Testing something cool'] } - , {"Header 4": ['v0.1', 'Testing something cool'] } + { 'Header 3': ['v0.1', 'Testing something cool'] }, + { 'Header 4': ['v0.1', 'Testing something cool'] } ); ``` @@ -81,30 +86,30 @@ ║ frob │ bar │ quuz ║ ╚══════╧═════╧══════╝ ```javascript - var table = new Table({ + let table = new Table({ chars: { - 'top': '═' - , 'top-mid': '╤' - , 'top-left': '╔' - , 'top-right': '╗' - , 'bottom': '═' - , 'bottom-mid': '╧' - , 'bottom-left': '╚' - , 'bottom-right': '╝' - , 'left': '║' - , 'left-mid': '╟' - , 'right': '║' - , 'right-mid': '╢' + top: '═', + 'top-mid': '╤', + 'top-left': '╔', + 'top-right': '╗', + bottom: '═', + 'bottom-mid': '╧', + 'bottom-left': '╚', + 'bottom-right': '╝', + left: '║', + 'left-mid': '╟', + right: '║', + 'right-mid': '╢', }, style: { - head: [] - , border: [] - } + head: [], + border: [], + }, }); table.push( - ['foo', 'bar', 'baz'] - , ['frob', 'bar', 'quuz'] + ['foo', 'bar', 'baz'], + ['frob', 'bar', 'quuz'] ); ``` @@ -113,12 +118,9 @@ ##### Use ansi colors (i.e. colors.js) to style text within the cells at will, even across multiple lines ![table image](./examples/screenshots/multi-line-colors.png) ```javascript - var table = new Table({style:{border:[],header:[]}}); + let table = new Table({ style: { border: [], header: [] } }); - table.push([ - colors.red('Hello\nhow\nare\nyou?'), - colors.blue('I\nam\nfine\nthanks!') - ]); + table.push([colors.red('Hello\nhow\nare\nyou?'), colors.blue('I\nam\nfine\nthanks!')]); ``` @@ -131,16 +133,13 @@ │ you? │ │ └───────┴─────────┘ ```javascript - var table = new Table({ - style:{border:[],header:[]}, - colWidths:[7,9], - wordWrap:true + let table = new Table({ + style: { border: [], header: [] }, + colWidths: [7, 9], + wordWrap: true, }); - table.push([ - 'Hello how are you?', - 'I am fine thanks!' - ]); + table.push(['Hello how are you?', 'I am fine thanks!']); ``` diff --git a/examples/basic-usage-examples.js b/examples/basic-usage-examples.js index 5f186b2..9a9154c 100644 --- a/examples/basic-usage-examples.js +++ b/examples/basic-usage-examples.js @@ -1,6 +1,9 @@ const Table = require('../src/table'); const colors = require('@colors/colors/safe'); +// prettier-ignore +// Disable prettier so that examples are formatted more clearly + module.exports = function (runTest) { function it(name, fn) { let result = fn(); @@ -69,7 +72,10 @@ module.exports = function (runTest) { style: { 'padding-left': 0, 'padding-right': 0, head: [], border: [] }, }); - table.push({ 'v0.1': 'Testing something cool' }, { 'v0.1': 'Testing something cool' }); + table.push( + { 'v0.1': 'Testing something cool' }, + { 'v0.1': 'Testing something cool' } + ); return table; } @@ -136,7 +142,10 @@ module.exports = function (runTest) { }, }); - table.push(['foo', 'bar', 'baz'], ['frob', 'bar', 'quuz']); + table.push( + ['foo', 'bar', 'baz'], + ['frob', 'bar', 'quuz'] + ); return table; } diff --git a/examples/col-and-row-span-examples.js b/examples/col-and-row-span-examples.js index d14488a..77b3e0e 100644 --- a/examples/col-and-row-span-examples.js +++ b/examples/col-and-row-span-examples.js @@ -1,6 +1,9 @@ const Table = require('../src/table'); const colors = require('@colors/colors/safe'); +// prettier-ignore +// Disable prettier so that examples are formatted more clearly + module.exports = function (runTest) { function it(name, fn) { let result = fn(); @@ -11,7 +14,11 @@ module.exports = function (runTest) { function makeTable() { let table = new Table({ style: { head: [], border: [] } }); - table.push([{ colSpan: 2, content: 'greetings' }], [{ colSpan: 2, content: 'greetings' }], ['hello', 'howdy']); + table.push( + [{ colSpan: 2, content: 'greetings' }], + [{ colSpan: 2, content: 'greetings' }], + ['hello', 'howdy'] + ); return table; } @@ -33,7 +40,11 @@ module.exports = function (runTest) { function makeTable() { let table = new Table({ style: { head: [], border: [] } }); - table.push(['hello', 'howdy'], [{ colSpan: 2, content: 'greetings' }], [{ colSpan: 2, content: 'greetings' }]); + table.push( + ['hello', 'howdy'], + [{ colSpan: 2, content: 'greetings' }], + [{ colSpan: 2, content: 'greetings' }] + ); return table; } @@ -184,7 +195,11 @@ module.exports = function (runTest) { function makeTable() { let table = new Table({ style: { head: [], border: [] } }); - table.push([{ content: 'a', rowSpan: 2 }, 'b'], [{ content: 'c', rowSpan: 2 }], ['d']); + table.push( + [{ content: 'a', rowSpan: 2 }, 'b'], + [{ content: 'c', rowSpan: 2 }], + ['d'] + ); return table; } @@ -199,7 +214,12 @@ module.exports = function (runTest) { let table = new Table({ style: { head: [], border: [] } }); //notice we only create 3 cells here, but the table ends up having 6. - table.push([{ content: 'a', rowSpan: 3, colSpan: 2 }, 'b'], [], [{ content: 'c', rowSpan: 2, colSpan: 2 }], []); + table.push( + [{ content: 'a', rowSpan: 3, colSpan: 2 }, 'b'], + [], + [{ content: 'c', rowSpan: 2, colSpan: 2 }], + [] + ); return table; } @@ -239,7 +259,10 @@ module.exports = function (runTest) { function makeTable() { let table = new Table({ style: { head: [], border: [] } }); - table.push([{ colSpan: 2, content: 'hello there' }], ['hi', 'hi']); + table.push( + [{ colSpan: 2, content: 'hello there' }], + ['hi', 'hi'] + ); return table; } @@ -256,7 +279,10 @@ module.exports = function (runTest) { style: { head: [], border: [] }, }); - table.push([{ colSpan: 2, content: 'hello there' }], ['hi', { hAlign: 'center', content: 'hi' }]); + table.push( + [{ colSpan: 2, content: 'hello there' }], + ['hi', { hAlign: 'center', content: 'hi' }] + ); return table; } @@ -273,7 +299,10 @@ module.exports = function (runTest) { style: { head: [], border: [] }, }); - table.push([{ colSpan: 2, content: 'hello there' }], [{ hAlign: 'right', content: 'hi' }, 'hi']); + table.push( + [{ colSpan: 2, content: 'hello there' }], + [{ hAlign: 'right', content: 'hi' }, 'hi'] + ); return table; }