-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
NB10328
authored and
NB10328
committed
Nov 11, 2020
1 parent
591f545
commit 9b80726
Showing
7 changed files
with
1,460 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
language: node_js | ||
node_js: | ||
- 12.18 | ||
before_install: | ||
- npm install -g mocha |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,152 @@ | ||
# ascii-table3 | ||
Beautiful ASCII table renderer | ||
Ascii Table 3 | ||
============= | ||
|
||
![Build stats](https://travis-ci.com/AllMightySauron/ascii-table2.png) | ||
|
||
ascii-table2 is an pure ascii table renderer and beautifier, heavily inspired by the `ascii-table` package created by Beau Sorensen <[email protected]> (http://github.com/sorensen). The original package lacked support for multiple table styles and that is what motivated me to create this new one. | ||
|
||
Existing code for `ascii-table` should run fine with very few changes (see examples below). | ||
|
||
Table of Contents | ||
----------------- | ||
|
||
* [Usage](#usage) | ||
- [Examples](#examples) | ||
* [Basic usage](#basic-usage) | ||
* [Using styles](#using-styles) | ||
* [API](#api) | ||
- [Static Methods](#static-methods) | ||
* [align(direction, val, len, [pad])](#asciitablealigndirection-val-len-pad) | ||
* [alignLeft(val, len, [pad])](#asciitablealignleftval-len-pad) | ||
* [alignCenter(val, len, [pad])](#asciitablealigncenterval-len-pad) | ||
* [alignRight(val, len, [pad])](#asciitablealignrightval-len-pad) | ||
* [alignAuto(val, len, [pad])](#asciitablealignautoval-len-pad) | ||
* [arrayFill(len, [val])](#asciitablearrayfilllen-val) | ||
- [Class methods](#class-methods) | ||
* [constructor([title])](#asciitablefactorytitle) | ||
|
||
Usage | ||
----- | ||
|
||
Node.js | ||
|
||
```js | ||
var AsciiTable2 = require('ascii-table2'); | ||
``` | ||
|
||
Examples | ||
-------- | ||
|
||
### Basic usage | ||
|
||
Tables are created programmatically. | ||
|
||
```js | ||
var AsciiTable2 = require('ascii-table2'); | ||
|
||
// create table | ||
var table = | ||
new AsciiTable2.AsciiTable2('Sample table') | ||
.setHeading('Name', 'Age', 'Eye color') | ||
.setAlign(3, AsciiTable2.AlignmentEnum.CENTER) | ||
.addRowMatrix([ | ||
['John', 23, 'green'], | ||
['Mary', 16, 'brown'], | ||
['Rita', 47, 'blue'], | ||
['Peter', 8, 'brown'] | ||
]); | ||
|
||
console.log(table.toString()); | ||
``` | ||
|
||
``` | ||
+-------------------+ | ||
| Sample table | | ||
+-----+---+---------+ | ||
|Name |Age|Eye color| | ||
+-----+---+---------+ | ||
|John | 23| green | | ||
|Mary | 16| brown | | ||
|Rita | 47| blue | | ||
|Peter| 8| brown | | ||
+-----+---+---------+ | ||
``` | ||
|
||
We can make simpler tables without a title or headings as well. | ||
|
||
```js | ||
var table = new AsciiTable2.AsciiTable2(); | ||
|
||
table | ||
.addRow('a', 'apple', 'Some longer string') | ||
.addRow('b', 'banana', 'hi') | ||
.addRow('c', 'carrot', 'meow') | ||
.addRow('e', 'elephants'); | ||
|
||
console.log(table.toString()); | ||
``` | ||
|
||
``` | ||
+-+---------+------------------+ | ||
|a|apple |Some longer string| | ||
|b|banana |hi | | ||
|c|carrot |meow | | ||
|e|elephants| | | ||
+-+---------+------------------+ | ||
``` | ||
|
||
### Using styles | ||
|
||
Tables may be rendered using different styles. | ||
|
||
``` | ||
var AsciiTable2 = require('./ascii-table2'); | ||
// create table | ||
var table = | ||
new AsciiTable2.AsciiTable2('Sample table') | ||
.setHeading('Name', 'Age', 'Eye color') | ||
.setAlign(3, AsciiTable2.AlignmentEnum.CENTER) | ||
.addRowMatrix([ | ||
['John', 23, 'green'], | ||
['Mary', 16, 'brown'], | ||
['Rita', 47, 'blue'], | ||
['Peter', 8, 'brown'] | ||
]); | ||
table.setStyle('compact'); | ||
console.log(table.toString()); | ||
``` | ||
|
||
``` | ||
------------------- | ||
Sample table | ||
------------------- | ||
Name Age Eye color | ||
----- --- --------- | ||
John 23 green | ||
Mary 16 brown | ||
Rita 47 blue | ||
Peter 8 brown | ||
``` | ||
|
||
These styles range from simple to more elaborate. | ||
|
||
``` | ||
table.setStyle('unicode-single'); | ||
console.log(table.toString()); | ||
``` | ||
|
||
``` | ||
┌───────────────────┐ | ||
│ Sample table │ | ||
├─────┬───┬─────────┤ | ||
│Name │Age│Eye color│ | ||
├─────┼───┼─────────┤ | ||
│John │ 23│ green │ | ||
│Mary │ 16│ brown │ | ||
│Rita │ 47│ blue │ | ||
│Peter│ 8│ brown │ | ||
└─────┴───┴─────────┘ | ||
``` | ||
|
Oops, something went wrong.