Skip to content

Commit 67b96a2

Browse files
nam-hlenhle-mgmtp
andauthored
[docs] Improve doc (#170)
* Improve doc * Fix * Fix 2 * Fix 3 * Fix 4 * docs: generate docs Co-authored-by: Nam Hoang Le <[email protected]>
1 parent 4ac6f00 commit 67b96a2

24 files changed

+606
-787
lines changed

Diff for: .README/README.md

+27-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Table
22

3+
> Produces a string that represents array data in a text table.
4+
35
[![Travis build status](http://img.shields.io/travis/gajus/table/master.svg?style=flat-square)](https://travis-ci.org/gajus/table)
46
[![Coveralls](https://img.shields.io/coveralls/gajus/table.svg?style=flat-square)](https://coveralls.io/github/gajus/table)
57
[![NPM version](http://img.shields.io/npm/v/table.svg?style=flat-square)](https://www.npmjs.org/package/table)
@@ -8,8 +10,6 @@
810

911
{"gitdown": "contents"}
1012

11-
Produces a string that represents array data in a text table.
12-
1313
![Demo of table displaying a list of missions to the Moon.](./.README/demo.png)
1414

1515
## Features
@@ -22,16 +22,30 @@ Produces a string that represents array data in a text table.
2222
* Configurable column width.
2323
* Text wrapping.
2424

25+
## Install
26+
27+
{"gitdown": "include", "file": "./install.md"}
28+
29+
## Usage
30+
2531
{"gitdown": "include", "file": "./usage.md"}
2632

27-
{"gitdown": "include", "file": "./usage/cell_content_alignment.md"}
28-
{"gitdown": "include", "file": "./usage/column_width.md"}
29-
{"gitdown": "include", "file": "./usage/custom_border.md"}
30-
{"gitdown": "include", "file": "./usage/draw_vertical_line.md"}
31-
{"gitdown": "include", "file": "./usage/draw_horizontal_line.md"}
32-
{"gitdown": "include", "file": "./usage/single_line_mode.md"}
33-
{"gitdown": "include", "file": "./usage/padding_cell_content.md"}
34-
{"gitdown": "include", "file": "./usage/predefined_border_templates.md"}
35-
{"gitdown": "include", "file": "./usage/streaming.md"}
36-
{"gitdown": "include", "file": "./usage/text_truncation.md"}
37-
{"gitdown": "include", "file": "./usage/text_wrapping.md"}
33+
## API
34+
35+
{"gitdown": "include", "file": "./api/table/index.md"}
36+
{"gitdown": "include", "file": "./api/table/border.md"}
37+
{"gitdown": "include", "file": "./api/table/draw_vertical_line.md"}
38+
{"gitdown": "include", "file": "./api/table/draw_horizontal_line.md"}
39+
{"gitdown": "include", "file": "./api/table/single_line.md"}
40+
41+
{"gitdown": "include", "file": "./api/table/columns/index.md"}
42+
{"gitdown": "include", "file": "./api/table/columns/width.md"}
43+
{"gitdown": "include", "file": "./api/table/columns/alignment.md"}
44+
{"gitdown": "include", "file": "./api/table/columns/padding.md"}
45+
{"gitdown": "include", "file": "./api/table/columns/truncate.md"}
46+
{"gitdown": "include", "file": "./api/table/columns/wrapWord.md"}
47+
{"gitdown": "include", "file": "./api/table/column_default.md"}
48+
49+
{"gitdown": "include", "file": "./api/stream/index.md"}
50+
51+
{"gitdown": "include", "file": "./api/get_border_characters.md"}

Diff for: .README/usage/predefined_border_templates.md renamed to .README/api/get_border_characters.md

+17-20
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
1-
### Predefined Border Templates
1+
### getBorderCharacters
2+
3+
**Parameter:**
4+
- **_template_**
5+
- Type: `'honeywell' | 'norc' | 'ramac' | 'void'`
6+
- Required: `true`
27

38
You can load one of the predefined border templates using `getBorderCharacters` function.
49

510
```js
6-
import {
7-
table,
8-
getBorderCharacters
9-
} from 'table';
10-
11-
let config,
12-
data;
11+
import { table, getBorderCharacters } from 'table';
1312

14-
data = [
13+
const data = [
1514
['0A', '0B', '0C'],
1615
['1A', '1B', '1C'],
1716
['2A', '2B', '2C']
1817
];
1918

20-
config = {
19+
const config = {
2120
border: getBorderCharacters(`name of the template`)
2221
};
2322

24-
table(data, config);
23+
console.log(table(data, config));
2524
```
2625

2726
```
@@ -55,7 +54,7 @@ table(data, config);
5554
| 2A | 2B | 2C |
5655
+----+----+----+
5756
58-
# void (no borders; see "bordless table" section of the documentation)
57+
# void (no borders; see "borderless table" section of the documentation)
5958
6059
0A 0B 0C
6160
@@ -69,23 +68,21 @@ Raise [an issue](https://github.com/gajus/table/issues) if you'd like to contrib
6968

7069
#### Borderless Table
7170

72-
Simply using "void" border character template creates a table with a lot of unnecessary spacing.
71+
Simply using `void` border character template creates a table with a lot of unnecessary spacing.
7372

74-
To create a more plesant to the eye table, reset the padding and remove the joining rows, e.g.
73+
To create a more pleasant to the eye table, reset the padding and remove the joining rows, e.g.
7574

7675
```js
77-
let output;
7876

79-
output = table(data, {
80-
border: getBorderCharacters(`void`),
77+
const output = table(data, {
78+
border: getBorderCharacters('void'),
8179
columnDefault: {
8280
paddingLeft: 0,
8381
paddingRight: 1
8482
},
85-
drawHorizontalLine: () => {
86-
return false
83+
drawHorizontalLine: () => false
8784
}
88-
});
85+
);
8986

9087
console.log(output);
9188
```
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,29 @@
1-
### Streaming
1+
### createStream
22

33
`table` package exports `createStream` function used to draw a table and append rows.
44

5-
`createStream` requires `{number} columnDefault.width` and `{number} columnCount` configuration properties.
5+
Parameter:
6+
- _**config:**_ the same as `table`'s, except `config.columnDefault.width` and `config.columnCount` must be provided.
67

7-
```js
8-
import {
9-
createStream
10-
} from 'table';
118

12-
let config,
13-
stream;
9+
```js
10+
import { createStream } from 'table';
1411

15-
config = {
12+
const config = {
1613
columnDefault: {
1714
width: 50
1815
},
1916
columnCount: 1
2017
};
2118

22-
stream = createStream(config);
19+
const stream = createStream(config);
2320

2421
setInterval(() => {
2522
stream.write([new Date()]);
2623
}, 500);
2724
```
2825

29-
![Streaming current date.](./.README/streaming.gif)
26+
![Streaming current date.](./.README/api/stream/streaming.gif)
3027

3128
`table` package uses ANSI escape codes to overwrite the output of the last line when a new row is printed.
3229

@@ -35,38 +32,29 @@ The underlying implementation is explained in this [Stack Overflow answer](http:
3532
Streaming supports all of the configuration properties and functionality of a static table (such as auto text wrapping, alignment and padding), e.g.
3633

3734
```js
38-
import {
39-
createStream
40-
} from 'table';
35+
import { createStream } from 'table';
4136

4237
import _ from 'lodash';
4338

44-
let config,
45-
stream,
46-
i;
47-
48-
config = {
39+
const config = {
4940
columnDefault: {
5041
width: 50
5142
},
5243
columnCount: 3,
53-
columns: {
54-
0: {
44+
columns: [
45+
{
5546
width: 10,
5647
alignment: 'right'
5748
},
58-
1: {
59-
alignment: 'center',
60-
},
61-
2: {
62-
width: 10
63-
}
64-
}
49+
{ alignment: 'center' },
50+
{ width: 10 }
51+
52+
]
6553
};
6654

67-
stream = createStream(config);
55+
const stream = createStream(config);
6856

69-
i = 0;
57+
let i = 0;
7058

7159
setInterval(() => {
7260
let random;
@@ -77,4 +65,4 @@ setInterval(() => {
7765
}, 500);
7866
```
7967

80-
![Streaming random data.](./.README/streaming-random.gif)
68+
![Streaming random data.](./.README/api/stream/streaming-random.gif)
File renamed without changes.
File renamed without changes.

Diff for: .README/usage/custom_border.md renamed to .README/api/table/border.md

+12-11
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
1-
### Custom Border
1+
##### config.border
22

3-
`{object} config.border` property describes characters used to draw the table border.
3+
Type: `{ [type: string]: string }`\
4+
Default: `honeywell` [template](#getbordercharacters)
45

5-
```js
6-
let config,
7-
data,
8-
output;
6+
Custom borders. The keys are any of:
7+
- `topLeft`, `topRight`, `topBody`,`topJoin`
8+
- `bottomLeft`, `bottomRight`, `bottomBody`, `bottomJoin`
9+
- `joinLeft`, `joinRight`, `joinBody`, `joinJoin`
10+
- `bodyLeft`, `bodyRight`, `bodyJoin`
911

10-
data = [
12+
```js
13+
const data = [
1114
['0A', '0B', '0C'],
1215
['1A', '1B', '1C'],
1316
['2A', '2B', '2C']
1417
];
1518

16-
config = {
19+
const config = {
1720
border: {
1821
topBody: ``,
1922
topJoin: ``,
@@ -36,9 +39,7 @@ config = {
3639
}
3740
};
3841

39-
output = table(data, config);
40-
41-
console.log(output);
42+
console.log(table(data, config));
4243
```
4344

4445
```

Diff for: .README/api/table/column_default.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
##### config.columnDefault
2+
3+
Type: `Column`\
4+
Default: `{}`
5+
6+
The default configuration for all columns. Column-specific settings will overwrite the default values.

Diff for: .README/usage/cell_content_alignment.md renamed to .README/api/table/columns/alignment.md

+11-16
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,30 @@
1-
### Cell Content Alignment
1+
###### config.columns[*].alignment
22

3-
`{string} config.columns[{number}].alignment` property controls content horizontal alignment within a cell.
3+
Type: `'center' | 'justify' | 'left' | 'right'`\
4+
Default: `'left'`
45

5-
Valid values are: "left", "right", "center" and "justify".
6+
Cell content horizontal alignment
67

78
```js
8-
let config,
9-
data,
10-
output;
11-
12-
data = [
9+
const data = [
1310
['0A', '0B', '0C', '0D 0E 0F'],
1411
['1A', '1B', '1C', '1D 1E 1F'],
1512
['2A', '2B', '2C', '2D 2E 2F'],
1613
];
1714

18-
config = {
15+
const config = {
1916
columnDefault: {
2017
width: 10,
2118
},
2219
columns: [
23-
{alignment: 'left'},
24-
{alignment: 'center'},
25-
{alignment: 'right'},
26-
{alignment: 'justify'},
20+
{ alignment: 'left' },
21+
{ alignment: 'center' },
22+
{ alignment: 'right' },
23+
{ alignment: 'justify' }
2724
],
2825
};
2926

30-
output = table(data, config);
31-
32-
console.log(output);
27+
console.log(table(data, config));
3328
```
3429

3530
```

Diff for: .README/api/table/columns/index.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
##### config.columns
2+
3+
Type: `Column[] | { [columnIndex: number]: Column }`\
4+
Column specific configurations.

Diff for: .README/usage/padding_cell_content.md renamed to .README/api/table/columns/padding.md

+22-15
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,40 @@
1-
### Padding Cell Content
1+
###### config.columns[*].paddingLeft
22

3-
`{number} config.columns[{number}].paddingLeft` and `{number} config.columns[{number}].paddingRight` properties control content padding within a cell. Property value represents a number of whitespaces used to pad the content.
3+
Type: `number`\
4+
Default: `1`
45

5-
```js
6-
let config,
7-
data,
8-
output;
6+
The number of whitespaces used to pad the content on the left.
7+
8+
###### config.columns[*].paddingRight
9+
10+
Type: `number`\
11+
Default: `1`
12+
13+
The number of whitespaces used to pad the content on the right.
914

10-
data = [
15+
The `paddingLeft` and `paddingRight` options do not count on the column width. So the column has `width = 5`, `paddingLeft = 2` and `paddingRight = 2` will have the total width is `9`.
16+
17+
18+
```js
19+
const data = [
1120
['0A', 'AABBCC', '0C'],
1221
['1A', '1B', '1C'],
1322
['2A', '2B', '2C']
1423
];
1524

16-
config = {
17-
columns: {
18-
0: {
25+
const config = {
26+
columns: [
27+
{
1928
paddingLeft: 3
2029
},
21-
1: {
30+
{
2231
width: 2,
2332
paddingRight: 3
2433
}
25-
}
34+
]
2635
};
2736

28-
output = table(data, config);
29-
30-
console.log(output);
37+
console.log(table(data, config));
3138
```
3239

3340
```

0 commit comments

Comments
 (0)