table 3.8.2 → 4.0.3

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.
Files changed (56) hide show
  1. package/README.md +35 -16
  2. package/dist/alignString.js +19 -842
  3. package/dist/alignTableData.js +4 -226
  4. package/dist/calculateCellHeight.js +6 -343
  5. package/dist/calculateCellWidthIndex.js +2 -112
  6. package/dist/calculateMaximumColumnWidthIndex.js +5 -299
  7. package/dist/calculateRowHeightIndex.js +8 -333
  8. package/dist/createStream.js +19 -814
  9. package/dist/drawBorder.js +11 -292
  10. package/dist/drawRow.js +1 -69
  11. package/dist/drawTable.js +7 -474
  12. package/dist/getBorderCharacters.js +1 -315
  13. package/dist/index.js +4 -28
  14. package/dist/makeConfig.js +15 -544
  15. package/dist/makeStreamConfig.js +13 -587
  16. package/dist/mapDataUsingRowHeightIndex.js +9 -349
  17. package/dist/padTableData.js +5 -166
  18. package/dist/schemas/config.json +2 -2
  19. package/dist/schemas/streamConfig.json +2 -2
  20. package/dist/stringifyTableData.js +4 -116
  21. package/dist/table.js +5 -203
  22. package/dist/truncateTableData.js +3 -147
  23. package/dist/validateConfig.js +20 -23
  24. package/dist/validateStreamConfig.js +17 -19
  25. package/dist/validateTableData.js +11 -528
  26. package/dist/wrapString.js +3 -135
  27. package/dist/wrapWord.js +4 -257
  28. package/package.json +27 -24
  29. package/test/README/usage/basic.js +0 -25
  30. package/test/README/usage/cell_content_alignment.js +0 -45
  31. package/test/README/usage/column_width.js +0 -33
  32. package/test/README/usage/custom_border.js +0 -50
  33. package/test/README/usage/draw_horizontal_line.js +0 -41
  34. package/test/README/usage/expectTable.js +0 -13
  35. package/test/README/usage/moon_mission.js +0 -67
  36. package/test/README/usage/padding_cell_content.js +0 -39
  37. package/test/README/usage/predefined_border_templates.js +0 -91
  38. package/test/README/usage/streaming.js +0 -56
  39. package/test/README/usage/text_truncating.js +0 -32
  40. package/test/README/usage/text_wrapping.js +0 -67
  41. package/test/alignString.js +0 -102
  42. package/test/calculateCellHeight.js +0 -44
  43. package/test/calculateCellWidthIndex.js +0 -20
  44. package/test/calculateMaximumColumnWidthIndex.js +0 -59
  45. package/test/calculateRowHeightIndex.js +0 -78
  46. package/test/config.js +0 -43
  47. package/test/configSamples.js +0 -153
  48. package/test/createStream.js +0 -41
  49. package/test/drawBorder.js +0 -71
  50. package/test/makeConfig.js +0 -75
  51. package/test/mapDataUsingRowHeightIndex.js +0 -119
  52. package/test/streamConfig.js +0 -43
  53. package/test/streamConfigSamples.js +0 -151
  54. package/test/validateTableData.js +0 -65
  55. package/test/wrapString.js +0 -45
  56. package/test/wrapWord.js +0 -32
package/README.md CHANGED
@@ -1,4 +1,5 @@
1
- <h1 id="table">Table</h1>
1
+ <a name="table"></a>
2
+ # Table
2
3
 
3
4
  [![Travis build status](http://img.shields.io/travis/gajus/table/master.svg?style=flat)](https://travis-ci.org/gajus/table)
4
5
  [![NPM version](http://img.shields.io/npm/v/table.svg?style=flat)](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
  ![Demo of table displaying a list of missions to the Moon.](./.README/demo.png)
24
25
 
25
- <h2 id="table-features">Features</h2>
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
- <h2 id="table-usage">Usage</h2>
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 table from 'table';
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
- <h3 id="table-usage-cell-content-alignment">Cell Content Alignment</h3>
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
- <h3 id="table-usage-column-width">Column Width</h3>
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
- <h3 id="table-usage-custom-border">Custom Border</h3>
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
- <h3 id="table-usage-draw-horizontal-line">Draw Horizontal Line</h3>
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
- <h3 id="table-usage-padding-cell-content">Padding Cell Content</h3>
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
- <h3 id="table-usage-predefined-border-templates">Predefined Border Templates</h3>
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 table, {
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
- <h4 id="table-usage-predefined-border-templates-borderless-table">Borderless Table</h4>
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
 
@@ -438,7 +454,7 @@ output = table(data, {
438
454
  paddingLeft: 0,
439
455
  paddingRight: 1
440
456
  },
441
- drawJoin: () => {
457
+ drawHorizontalLine: () => {
442
458
  return false
443
459
  }
444
460
  });
@@ -452,7 +468,8 @@ console.log(output);
452
468
  2A 2B 2C
453
469
  ```
454
470
 
455
- <h3 id="table-usage-streaming">Streaming</h3>
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
  ![Streaming random data.](./.README/streaming-random.gif)
535
- <h3 id="table-usage-text-truncation">Text Truncation</h3>
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
- <h3 id="table-usage-text-wrapping">Text Wrapping</h3>
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