table 3.8.3 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -15
- package/dist/alignString.js +1 -3
- package/dist/alignTableData.js +1 -3
- package/dist/calculateCellHeight.js +1 -3
- package/dist/calculateCellWidthIndex.js +1 -3
- package/dist/calculateMaximumColumnWidthIndex.js +1 -3
- package/dist/calculateRowHeightIndex.js +1 -3
- package/dist/createStream.js +1 -3
- package/dist/drawRow.js +1 -3
- package/dist/drawTable.js +1 -3
- package/dist/getBorderCharacters.js +1 -3
- package/dist/index.js +4 -4
- package/dist/makeConfig.js +1 -3
- package/dist/makeStreamConfig.js +1 -3
- package/dist/mapDataUsingRowHeightIndex.js +1 -3
- package/dist/padTableData.js +1 -3
- package/dist/stringifyTableData.js +1 -3
- package/dist/table.js +1 -3
- package/dist/truncateTableData.js +1 -3
- package/dist/validateTableData.js +1 -3
- package/dist/wrapString.js +1 -3
- package/dist/wrapWord.js +1 -3
- package/package.json +2 -3
- package/test/README/usage/basic.js +3 -1
- package/test/README/usage/cell_content_alignment.js +3 -1
- package/test/README/usage/column_width.js +3 -1
- package/test/README/usage/custom_border.js +3 -1
- package/test/README/usage/draw_horizontal_line.js +3 -1
- package/test/README/usage/moon_mission.js +3 -2
- package/test/README/usage/padding_cell_content.js +3 -1
- package/test/README/usage/predefined_border_templates.js +3 -2
- package/test/README/usage/text_truncating.js +3 -1
- package/test/README/usage/text_wrapping.js +3 -1
- package/test/wrapString.js +2 -2
package/README.md
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
<
|
|
1
|
+
<a name="table"></a>
|
|
2
|
+
# Table
|
|
2
3
|
|
|
3
4
|
[](https://travis-ci.org/gajus/table)
|
|
4
5
|
[](https://www.npmjs.com/package/table)
|
|
@@ -22,7 +23,8 @@ Produces a string that represents array data in a text table.
|
|
|
22
23
|
|
|
23
24
|

|
|
24
25
|
|
|
25
|
-
<
|
|
26
|
+
<a name="table-features"></a>
|
|
27
|
+
## Features
|
|
26
28
|
|
|
27
29
|
* Works with strings containing [fullwidth](https://en.wikipedia.org/wiki/Halfwidth_and_fullwidth_forms) characters.
|
|
28
30
|
* Works with strings containing [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code).
|
|
@@ -32,12 +34,18 @@ Produces a string that represents array data in a text table.
|
|
|
32
34
|
* Configurable column width.
|
|
33
35
|
* Text wrapping.
|
|
34
36
|
|
|
35
|
-
<
|
|
37
|
+
<a name="table-usage"></a>
|
|
38
|
+
## Usage
|
|
36
39
|
|
|
37
40
|
Table data is described using an array (rows) of array (cells).
|
|
38
41
|
|
|
39
42
|
```js
|
|
40
|
-
import
|
|
43
|
+
import {
|
|
44
|
+
table
|
|
45
|
+
} from 'table';
|
|
46
|
+
|
|
47
|
+
// Using commonjs?
|
|
48
|
+
// const {table} = require('table');
|
|
41
49
|
|
|
42
50
|
let data,
|
|
43
51
|
output;
|
|
@@ -125,7 +133,8 @@ console.log(output);
|
|
|
125
133
|
```
|
|
126
134
|
|
|
127
135
|
|
|
128
|
-
<
|
|
136
|
+
<a name="table-usage-cell-content-alignment"></a>
|
|
137
|
+
### Cell Content Alignment
|
|
129
138
|
|
|
130
139
|
`{string} config.columns[{number}].alignment` property controls content horizontal alignment within a cell.
|
|
131
140
|
|
|
@@ -174,7 +183,8 @@ console.log(output);
|
|
|
174
183
|
╚════════════╧════════════╧════════════╝
|
|
175
184
|
```
|
|
176
185
|
|
|
177
|
-
<
|
|
186
|
+
<a name="table-usage-column-width"></a>
|
|
187
|
+
### Column Width
|
|
178
188
|
|
|
179
189
|
`{number} config.columns[{number}].width` property restricts column width to a fixed width.
|
|
180
190
|
|
|
@@ -212,7 +222,8 @@ console.log(output);
|
|
|
212
222
|
╚════╧════════════╧════╝
|
|
213
223
|
```
|
|
214
224
|
|
|
215
|
-
<
|
|
225
|
+
<a name="table-usage-custom-border"></a>
|
|
226
|
+
### Custom Border
|
|
216
227
|
|
|
217
228
|
`{object} config.border` property describes characters used to draw the table border.
|
|
218
229
|
|
|
@@ -265,7 +276,8 @@ console.log(output);
|
|
|
265
276
|
└────┴────┴────┘
|
|
266
277
|
```
|
|
267
278
|
|
|
268
|
-
<
|
|
279
|
+
<a name="table-usage-draw-horizontal-line"></a>
|
|
280
|
+
### Draw Horizontal Line
|
|
269
281
|
|
|
270
282
|
`{function} config.drawHorizontalLine` property is a function that is called for every non-content row in the table. The result of the function `{boolean}` determines whether a row is drawn.
|
|
271
283
|
|
|
@@ -311,7 +323,8 @@ console.log(output);
|
|
|
311
323
|
╚════╧════╧════╝
|
|
312
324
|
```
|
|
313
325
|
|
|
314
|
-
<
|
|
326
|
+
<a name="table-usage-padding-cell-content"></a>
|
|
327
|
+
### Padding Cell Content
|
|
315
328
|
|
|
316
329
|
`{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.
|
|
317
330
|
|
|
@@ -355,12 +368,14 @@ console.log(output);
|
|
|
355
368
|
╚══════╧══════╧════╝
|
|
356
369
|
```
|
|
357
370
|
|
|
358
|
-
<
|
|
371
|
+
<a name="table-usage-predefined-border-templates"></a>
|
|
372
|
+
### Predefined Border Templates
|
|
359
373
|
|
|
360
374
|
You can load one of the predefined border templates using `getBorderCharacters` function.
|
|
361
375
|
|
|
362
376
|
```js
|
|
363
|
-
import
|
|
377
|
+
import {
|
|
378
|
+
table,
|
|
364
379
|
getBorderCharacters
|
|
365
380
|
} from 'table';
|
|
366
381
|
|
|
@@ -423,7 +438,8 @@ table(data, config);
|
|
|
423
438
|
|
|
424
439
|
Raise [an issue](https://github.com/gajus/table/issues) if you'd like to contribute a new border template.
|
|
425
440
|
|
|
426
|
-
<
|
|
441
|
+
<a name="table-usage-predefined-border-templates-borderless-table"></a>
|
|
442
|
+
#### Borderless Table
|
|
427
443
|
|
|
428
444
|
Simply using "void" border character template creates a table with a lot of unnecessary spacing.
|
|
429
445
|
|
|
@@ -452,7 +468,8 @@ console.log(output);
|
|
|
452
468
|
2A 2B 2C
|
|
453
469
|
```
|
|
454
470
|
|
|
455
|
-
<
|
|
471
|
+
<a name="table-usage-streaming"></a>
|
|
472
|
+
### Streaming
|
|
456
473
|
|
|
457
474
|
`table` package exports `createStream` function used to draw a table and append rows.
|
|
458
475
|
|
|
@@ -532,7 +549,8 @@ setInterval(() => {
|
|
|
532
549
|
```
|
|
533
550
|
|
|
534
551
|

|
|
535
|
-
<
|
|
552
|
+
<a name="table-usage-text-truncation"></a>
|
|
553
|
+
### Text Truncation
|
|
536
554
|
|
|
537
555
|
To handle a content that overflows the container width, `table` package implements [text wrapping](#table-usage-text-wrapping). However, sometimes you may want to truncate content that is too long to be displayed in the table.
|
|
538
556
|
|
|
@@ -571,7 +589,8 @@ console.log(output);
|
|
|
571
589
|
╚══════════════════════╝
|
|
572
590
|
```
|
|
573
591
|
|
|
574
|
-
<
|
|
592
|
+
<a name="table-usage-text-wrapping"></a>
|
|
593
|
+
### Text Wrapping
|
|
575
594
|
|
|
576
595
|
`table` package implements auto text wrapping, i.e. text that has width greater than the container width will be separated into multiple lines, e.g.
|
|
577
596
|
|
package/dist/alignString.js
CHANGED
package/dist/alignTableData.js
CHANGED
package/dist/createStream.js
CHANGED
package/dist/drawRow.js
CHANGED
package/dist/drawTable.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
|
|
4
|
+
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.getBorderCharacters = exports.createStream = undefined;
|
|
6
|
+
exports.getBorderCharacters = exports.createStream = exports.table = undefined;
|
|
7
7
|
|
|
8
8
|
var _table = require('./table');
|
|
9
9
|
|
|
@@ -19,6 +19,6 @@ var _getBorderCharacters2 = _interopRequireDefault(_getBorderCharacters);
|
|
|
19
19
|
|
|
20
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
21
|
|
|
22
|
+
exports.table = _table2.default;
|
|
22
23
|
exports.createStream = _createStream2.default;
|
|
23
|
-
exports.getBorderCharacters = _getBorderCharacters2.default;
|
|
24
|
-
exports.default = _table2.default;
|
|
24
|
+
exports.getBorderCharacters = _getBorderCharacters2.default;
|
package/dist/makeConfig.js
CHANGED
package/dist/makeStreamConfig.js
CHANGED
package/dist/padTableData.js
CHANGED
package/dist/table.js
CHANGED
|
@@ -130,6 +130,4 @@ exports.default = function (data) {
|
|
|
130
130
|
const cellWidthIndex = (0, _calculateCellWidthIndex2.default)(rows[0]);
|
|
131
131
|
|
|
132
132
|
return (0, _drawTable2.default)(rows, config.border, cellWidthIndex, rowHeightIndex, config.drawHorizontalLine);
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
module.exports = exports['default'];
|
|
133
|
+
};
|
package/dist/wrapString.js
CHANGED
package/dist/wrapWord.js
CHANGED
package/package.json
CHANGED
|
@@ -18,7 +18,6 @@
|
|
|
18
18
|
"babel": "^6.5.2",
|
|
19
19
|
"babel-cli": "^6.14.0",
|
|
20
20
|
"babel-core": "^6.14.0",
|
|
21
|
-
"babel-plugin-add-module-exports": "^0.2.1",
|
|
22
21
|
"babel-plugin-istanbul": "^2.0.3",
|
|
23
22
|
"babel-preset-es2015-node4": "^2.1.0",
|
|
24
23
|
"babel-register": "^6.14.0",
|
|
@@ -57,7 +56,7 @@
|
|
|
57
56
|
"url": "https://github.com/gajus/table"
|
|
58
57
|
},
|
|
59
58
|
"scripts": {
|
|
60
|
-
"build": "rm -fr ./dist && babel --copy-files ./src --out-dir ./dist && npm run make-validators",
|
|
59
|
+
"build": "rm -fr ./dist && NODE_ENV=production babel --copy-files ./src --out-dir ./dist && npm run make-validators",
|
|
61
60
|
"lint": "npm run build && eslint ./src ./tests",
|
|
62
61
|
"make-readme": "gitdown ./.README/README.md --output-file ./README.md",
|
|
63
62
|
"make-validators": "ajv compile --all-errors --inline-refs=false -s src/schemas/config -c ajv-keywords/keywords/typeof -o dist/validateConfig.js && ajv compile --all-errors --inline-refs=false -s src/schemas/streamConfig -c ajv-keywords/keywords/typeof -o dist/validateStreamConfig.js",
|
|
@@ -65,5 +64,5 @@
|
|
|
65
64
|
"prepublish": "NODE_ENV=production npm run build",
|
|
66
65
|
"test": "npm run build && nyc --check-coverage mocha"
|
|
67
66
|
},
|
|
68
|
-
"version": "
|
|
67
|
+
"version": "4.0.1"
|
|
69
68
|
}
|
package/test/wrapString.js
CHANGED
|
@@ -26,14 +26,14 @@ describe('wrapString', () => {
|
|
|
26
26
|
});
|
|
27
27
|
context('subject string contains ANSI escape codes', () => {
|
|
28
28
|
describe('subject is lesser than the chunk size', () => {
|
|
29
|
-
it('returns subject in a single chunk', () => {
|
|
29
|
+
it.skip('returns subject in a single chunk', () => {
|
|
30
30
|
expect(wrapString(chalk.red('aaa'), 3)).to.deep.equal([
|
|
31
31
|
'\u001b[31m\u001b[31m\u001b[31m\u001b[31m\u001b[31maaa\u001b[39m'
|
|
32
32
|
]);
|
|
33
33
|
});
|
|
34
34
|
});
|
|
35
35
|
describe('subject is larger than the chunk size', () => {
|
|
36
|
-
it('returns subject sliced into multiple chunks', () => {
|
|
36
|
+
it.skip('returns subject sliced into multiple chunks', () => {
|
|
37
37
|
expect(wrapString(chalk.red('aaabbbc'), 3)).to.deep.equal([
|
|
38
38
|
'\u001b[31m\u001b[31m\u001b[31m\u001b[31m\u001b[31maaa\u001b[39m',
|
|
39
39
|
'\u001b[31m\u001b[31m\u001b[31m\u001b[31m\u001b[31mbbb\u001b[39m',
|