π File Manager Pro
v10.0.3 | PHP: 8.1.34
Server: Apache
2026-06-22 13:35:50
π
/ (Root)
/
opt
/
alt
/
alt-nodejs9
/
root
/
usr
/
lib
/
node_modules
/
npm
/
node_modules.bundled
/
cli-table2
/
examples
π /opt/alt/alt-nodejs9/root/usr/lib/node_modules/npm/node_modules.bundled/cli-table2/examples
π Refresh
βοΈ
Editing: basic-usage-examples.js
Read Only
var Table = require('../src/table'); var colors = require('colors/safe'); module.exports = function(runTest) { function it(name, fn) { var result = fn(); runTest(name, result[0], result[1], result[2]); } it('Basic Usage',function(){ function makeTable(){ // By default, headers will be red, and borders will be grey var table = new Table({head:['a','b']}); table.push(['c','d']); return table; } var expected = [ colors.gray('ββββ') + colors.gray('β¬ββββ') , colors.gray('β') + colors.red(' a ') + colors.gray('β') + colors.red(' b ') + colors.gray('β') , colors.gray('ββββ') + colors.gray('βΌββββ€') , colors.gray('β') + (' c ') + colors.gray('β') + (' d ') + colors.gray('β') , colors.gray('ββββ') + colors.gray('β΄ββββ') ]; return [makeTable,expected,'basic-usage-with-colors']; }); it('Basic Usage - disable colors - (used often in the examples and tests)', function (){ function makeTable(){ // 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) }); table.push( ['v0.1', 'Testing something cool', 'rauchg@gmail.com', '7 minutes ago'] , ['v0.1', 'Testing something cool', 'rauchg@gmail.com', '8 minutes ago'] ); return table; } var expected = [ 'ββββββββ¬ββββββββββββββββββββββ¬ββββββββββββββββββββββββββ¬ββββββββββββββββββ' , 'β Rel β Change β By β When β' , 'ββββββββΌββββββββββββββββββββββΌββββββββββββββββββββββββββΌββββββββββββββββββ€' , 'β v0.1 β Testing something β¦ β rauchg@gmail.com β 7 minutes ago β' , 'ββββββββΌββββββββββββββββββββββΌββββββββββββββββββββββββββΌββββββββββββββββββ€' , 'β v0.1 β Testing something β¦ β rauchg@gmail.com β 8 minutes ago β' , 'ββββββββ΄ββββββββββββββββββββββ΄ββββββββββββββββββββββββββ΄ββββββββββββββββββ' ]; return [makeTable,expected]; }); it('Create vertical tables by adding objects a that specify key-value pairs', function() { function makeTable(){ var table = new Table({ style: {'padding-left':0, 'padding-right':0, head:[], border:[]} }); table.push( {'v0.1': 'Testing something cool'} , {'v0.1': 'Testing something cool'} ); return table; } var expected = [ 'ββββββ¬βββββββββββββββββββββββ' , 'βv0.1βTesting something coolβ' , 'ββββββΌβββββββββββββββββββββββ€' , 'βv0.1βTesting something coolβ' , 'ββββββ΄βββββββββββββββββββββββ' ]; return [makeTable,expected]; }); it('Cross tables are similar to vertical tables, but include an empty string for the first header', function() { function makeTable(){ var 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'] } ); return table; } var expected = [ 'ββββββββββ¬βββββββββ¬βββββββββββββββββββββββ' , 'β βHeader 1βHeader 2 β' , 'ββββββββββΌβββββββββΌβββββββββββββββββββββββ€' , 'βHeader 3βv0.1 βTesting something coolβ' , 'ββββββββββΌβββββββββΌβββββββββββββββββββββββ€' , 'βHeader 4βv0.1 βTesting something coolβ' , 'ββββββββββ΄βββββββββ΄βββββββββββββββββββββββ' ]; return [makeTable,expected]; }); it('Stylize the table with custom border characters', function (){ function makeTable(){ var table = new Table({ chars: { 'top': 'β' , 'top-mid': 'β€' , 'top-left': 'β' , 'top-right': 'β' , 'bottom': 'β' , 'bottom-mid': 'β§' , 'bottom-left': 'β' , 'bottom-right': 'β' , 'left': 'β' , 'left-mid': 'β' , 'right': 'β' , 'right-mid': 'β’' }, style: { head: [] , border: [] } }); table.push( ['foo', 'bar', 'baz'] , ['frob', 'bar', 'quuz'] ); return table; } var expected = [ 'ββββββββ€ββββββ€βββββββ' , 'β foo β bar β baz β' , 'ββββββββΌββββββΌβββββββ’' , 'β frob β bar β quuz β' , 'ββββββββ§ββββββ§βββββββ' ]; return [makeTable,expected]; }); it('Use ansi colors (i.e. colors.js) to style text within the cells at will, even across multiple lines',function(){ function makeTable(){ var table = new Table({style:{border:[],header:[]}}); table.push([ colors.red('Hello\nhow\nare\nyou?'), colors.blue('I\nam\nfine\nthanks!') ]); return table; } var expected = [ 'βββββββββ¬ββββββββββ' , 'β ' + colors.red('Hello') + ' β ' + colors.blue('I') + ' β' , 'β ' + colors.red('how') + ' β ' + colors.blue('am') + ' β' , 'β ' + colors.red('are') + ' β ' + colors.blue('fine') + ' β' , 'β ' + colors.red('you?') + ' β ' + colors.blue('thanks!') + ' β' , 'βββββββββ΄ββββββββββ' ]; return [makeTable,expected,'multi-line-colors']; }); it('Set `wordWrap` to true to make lines of text wrap instead of being truncated',function(){ function makeTable(){ var table = new Table({ style:{border:[],header:[]}, colWidths:[7,9], wordWrap:true }); table.push([ 'Hello how are you?', 'I am fine thanks!' ]); return table; } var expected = [ 'βββββββββ¬ββββββββββ' , 'β Hello β I am β' , 'β how β fine β' , 'β are β thanks! β' , 'β you? β β' , 'βββββββββ΄ββββββββββ' ]; return [makeTable,expected]; }); }; /* Expectation - ready to be copy/pasted and filled in. DO NOT DELETE THIS var expected = [ 'ββββ¬ββββ¬βββ¬βββ' , 'β β β β β' , 'ββββΌββββΌβββΌβββ€' , 'β β β¦ β β β' , 'ββββΌββββΌβββΌβββ€' , 'β β β¦ β β β' , 'ββββ΄ββββ΄βββ΄βββ' ]; */
πΎ Save Changes
β Cancel