Name |
Date |
Size |
#Lines |
LOC |
||
---|---|---|---|---|---|---|
.. | - | - | ||||
src/ | 12-May-2024 | - | 987 | 807 | ||
CHANGELOG.md | D | 12-May-2024 | 2.8 KiB | 57 | 39 | |
LICENSE | D | 12-May-2024 | 1.1 KiB | 22 | 17 | |
README.md | D | 12-May-2024 | 7.4 KiB | 219 | 172 | |
index.d.ts | D | 12-May-2024 | 2.4 KiB | 96 | 81 | |
index.js | D | 12-May-2024 | 40 | 1 | 1 | |
package.json | D | 12-May-2024 | 3.1 KiB | 132 | 131 |
README.md
1cli-table3 2=============================================================================== 3 4[](https://www.npmjs.com/package/cli-table3) 5[](https://travis-ci.com/cli-table/cli-table3) 6 7This utility allows you to render unicode-aided tables on the command line from 8your node.js scripts. 9 10`cli-table3` is based on (and api compatible with) the original [cli-table](https://github.com/Automattic/cli-table), 11and [cli-table2](https://github.com/jamestalmage/cli-table2), which are both 12unmaintained. `cli-table3` includes all the additional features from 13`cli-table2`. 14 15 16 17## Features not in the original cli-table 18 19- Ability to make cells span columns and/or rows. 20- Ability to set custom styles per cell (border characters/colors, padding, etc). 21- Vertical alignment (top, bottom, center). 22- Automatic word wrapping. 23- More robust truncation of cell text that contains ansi color characters. 24- Better handling of text color that spans multiple lines. 25- API compatible with the original cli-table. 26- Exhaustive test suite including the entire original cli-table test suite. 27- Lots of examples auto-generated from the tests ([basic](https://github.com/cli-table/cli-table3/blob/master/basic-usage.md), [advanced](https://github.com/cli-table/cli-table3/blob/master/advanced-usage.md)). 28 29## Features 30 31- Customizable characters that constitute the table. 32- Color/background styling in the header through 33 [colors.js](http://github.com/marak/colors.js) 34- Column width customization 35- Text truncation based on predefined widths 36- Text alignment (left, right, center) 37- Padding (left, right) 38- Easy-to-use API 39 40## Installation 41 42```bash 43npm install cli-table3 44``` 45 46## How to use 47 48A portion of the unit test suite is used to generate examples: 49- [basic-usage](https://github.com/cli-table/cli-table3/blob/master/basic-usage.md) - covers basic uses. 50- [advanced](https://github.com/cli-table/cli-table3/blob/master/advanced-usage.md) - covers using the new column and row span features. 51 52This package is api compatible with the original [cli-table](https://github.com/Automattic/cli-table). 53So all the original documentation still applies (copied below). 54 55### Horizontal Tables 56```javascript 57var Table = require('cli-table3'); 58 59// instantiate 60var table = new Table({ 61 head: ['TH 1 label', 'TH 2 label'] 62 , colWidths: [100, 200] 63}); 64 65// table is an Array, so you can `push`, `unshift`, `splice` and friends 66table.push( 67 ['First value', 'Second value'] 68 , ['First value', 'Second value'] 69); 70 71console.log(table.toString()); 72``` 73 74### Vertical Tables 75```javascript 76var Table = require('cli-table3'); 77var table = new Table(); 78 79table.push( 80 { 'Some key': 'Some value' } 81 , { 'Another key': 'Another value' } 82); 83 84console.log(table.toString()); 85``` 86### Cross Tables 87Cross tables are very similar to vertical tables, with two key differences: 88 891. They require a `head` setting when instantiated that has an empty string as the first header 902. The individual rows take the general form of { "Header": ["Row", "Values"] } 91 92```javascript 93var Table = require('cli-table3'); 94var table = new Table({ head: ["", "Top Header 1", "Top Header 2"] }); 95 96table.push( 97 { 'Left Header 1': ['Value Row 1 Col 1', 'Value Row 1 Col 2'] } 98 , { 'Left Header 2': ['Value Row 2 Col 1', 'Value Row 2 Col 2'] } 99); 100 101console.log(table.toString()); 102``` 103 104### Custom styles 105The ```chars``` property controls how the table is drawn: 106```javascript 107var table = new Table({ 108 chars: { 'top': '═' , 'top-mid': '╤' , 'top-left': '╔' , 'top-right': '╗' 109 , 'bottom': '═' , 'bottom-mid': '╧' , 'bottom-left': '╚' , 'bottom-right': '╝' 110 , 'left': '║' , 'left-mid': '╟' , 'mid': '─' , 'mid-mid': '┼' 111 , 'right': '║' , 'right-mid': '╢' , 'middle': '│' } 112}); 113 114table.push( 115 ['foo', 'bar', 'baz'] 116 , ['frob', 'bar', 'quuz'] 117); 118 119console.log(table.toString()); 120// Outputs: 121// 122//╔══════╤═════╤══════╗ 123//║ foo │ bar │ baz ║ 124//╟──────┼─────┼──────╢ 125//║ frob │ bar │ quuz ║ 126//╚══════╧═════╧══════╝ 127``` 128 129Empty decoration lines will be skipped, to avoid vertical separator rows just 130set the 'mid', 'left-mid', 'mid-mid', 'right-mid' to the empty string: 131```javascript 132var table = new Table({ chars: {'mid': '', 'left-mid': '', 'mid-mid': '', 'right-mid': ''} }); 133table.push( 134 ['foo', 'bar', 'baz'] 135 , ['frobnicate', 'bar', 'quuz'] 136); 137 138console.log(table.toString()); 139// Outputs: (note the lack of the horizontal line between rows) 140//┌────────────┬─────┬──────┐ 141//│ foo │ bar │ baz │ 142//│ frobnicate │ bar │ quuz │ 143//└────────────┴─────┴──────┘ 144``` 145 146By setting all chars to empty with the exception of 'middle' being set to a 147single space and by setting padding to zero, it's possible to get the most 148compact layout with no decorations: 149```javascript 150var table = new Table({ 151 chars: { 'top': '' , 'top-mid': '' , 'top-left': '' , 'top-right': '' 152 , 'bottom': '' , 'bottom-mid': '' , 'bottom-left': '' , 'bottom-right': '' 153 , 'left': '' , 'left-mid': '' , 'mid': '' , 'mid-mid': '' 154 , 'right': '' , 'right-mid': '' , 'middle': ' ' }, 155 style: { 'padding-left': 0, 'padding-right': 0 } 156}); 157 158table.push( 159 ['foo', 'bar', 'baz'] 160 , ['frobnicate', 'bar', 'quuz'] 161); 162 163console.log(table.toString()); 164// Outputs: 165//foo bar baz 166//frobnicate bar quuz 167``` 168 169## Build Targets 170 171Clone the repository and run `yarn install` to install all its submodules, then run one of the following commands: 172 173###### Run the tests with coverage reports. 174```bash 175$ yarn test:coverage 176``` 177 178###### Run the tests every time a file changes. 179```bash 180$ yarn test:watch 181``` 182 183###### Update the documentation. 184```bash 185$ yarn docs 186``` 187 188## Credits 189 190- James Talmage - author <james.talmage@jrtechnical.com> ([jamestalmage](http://github.com/jamestalmage)) 191- Guillermo Rauch - author of the original cli-table <guillermo@learnboost.com> ([Guille](http://github.com/guille)) 192 193## License 194 195(The MIT License) 196 197Copyright (c) 2014 James Talmage <james.talmage@jrtechnical.com> 198 199Original cli-table code/documentation: Copyright (c) 2010 LearnBoost <dev@learnboost.com> 200 201Permission is hereby granted, free of charge, to any person obtaining 202a copy of this software and associated documentation files (the 203'Software'), to deal in the Software without restriction, including 204without limitation the rights to use, copy, modify, merge, publish, 205distribute, sublicense, and/or sell copies of the Software, and to 206permit persons to whom the Software is furnished to do so, subject to 207the following conditions: 208 209The above copyright notice and this permission notice shall be 210included in all copies or substantial portions of the Software. 211 212THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, 213EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 214MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 215IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 216CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 217TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 218SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 219