|
1 | 1 | /*jshint esversion: 6 */
|
2 | 2 |
|
3 | 3 | /**
|
4 |
| - * Type definition for table section style. |
5 |
| - * @typedef {Object} SectionStyle |
6 |
| - * @property {string} left The left border character. |
7 |
| - * @property {string} center The center border character. |
8 |
| - * @property {string} right The right border character. |
9 |
| - * @property {string} colSeparator The column separator character. |
10 |
| - */ |
11 |
| - |
12 |
| - /** |
13 |
| - * Borders style definition. |
14 |
| - * @typedef {Object} Borders |
15 |
| - * @property {SectionStyle} top The style for top section borders (above heading). |
16 |
| - * @property {SectionStyle} middle The style for middle section borders (between heading and data). |
17 |
| - * @property {SectionStyle} bottom The style for bottom section borders (below data). |
18 |
| - * @property {SectionStyle} data The style for data row borders. |
19 |
| - */ |
20 |
| - |
21 |
| -/** |
22 |
| - * Type definition for a table style. |
23 |
| - * @typedef {Object} Style |
24 |
| - * @property {string} name Style name. |
25 |
| - * @property {Borders} borders The border styles for each section. |
26 |
| - */ |
27 |
| - |
28 |
| -/** |
29 |
| - * @typedef {object} ColumnFormatJSON |
30 |
| - * @property {number[]} aligns Alignment setting for each data column. |
31 |
| - * @property {number[]} widths Width setting for each data column. |
32 |
| - * @property {boolean[]} wrappings Wrapping setting for each data column. |
33 |
| - */ |
34 |
| - |
35 |
| -/** |
36 |
| - * @typedef {object} FormattingJSON |
37 |
| - * @property {number} titleAlign Title alignment setting. |
38 |
| - * @property {ColumnFormatJSON} columns Format settings for each column. |
39 |
| - * @property {boolean} justify Whether to justify table columns. |
40 |
| - */ |
41 |
| - |
42 |
| -/** |
43 |
| - * @typedef {object} TableJSON |
44 |
| - * @property {string} title Table title text. |
45 |
| - * @property {string[]} heading Array of table column headings. |
46 |
| - * @property {string[][]} rows Array of table rows (each row contains an array of data columns). |
47 |
| - * @property {FormattingJSON} formatting Table formatting settings. |
| 4 | + * Type imports. |
| 5 | + * @typedef { import("./ascii-table3").SectionStyle } SectionStyle |
| 6 | + * @typedef { import("./ascii-table3").Borders } Borders |
| 7 | + * @typedef { import("./ascii-table3").Style } Style |
| 8 | + * @typedef { import("./ascii-table3").ColumnFormatJSON } ColumnFormatJSON |
| 9 | + * @typedef { import("./ascii-table3").FormattingJSON } FormattingJSON |
| 10 | + * @typedef { import("./ascii-table3").TableJSON } TableJSON |
48 | 11 | */
|
49 | 12 |
|
50 | 13 | /**
|
@@ -239,6 +202,12 @@ class AsciiTable3 {
|
239 | 202 | }
|
240 | 203 | }
|
241 | 204 |
|
| 205 | + /** |
| 206 | + * Wraps a string into multiple lines of a limited width. |
| 207 | + * @param {string} str The string to wrap. |
| 208 | + * @param {num} maxWidth The maximum width for the wrapped string. |
| 209 | + * @returns {string} The wrapped string. |
| 210 | + */ |
242 | 211 | static wordWrap(str, maxWidth) {
|
243 | 212 | // partition string
|
244 | 213 | const partArray = partition(String(str));
|
@@ -269,7 +238,7 @@ class AsciiTable3 {
|
269 | 238 | }
|
270 | 239 |
|
271 | 240 | /**
|
272 |
| - * Wraps a string into multiple lines of a limited width. |
| 241 | + * Wraps a string into multiple lines of a limited width (simple string, no ANSI chars). |
273 | 242 | * @param {string} str The string to wrap.
|
274 | 243 | * @param {num} maxWidth The maximum width for the wrapped string.
|
275 | 244 | * @returns {string} The wrapped string.
|
@@ -307,10 +276,11 @@ class AsciiTable3 {
|
307 | 276 |
|
308 | 277 | /**
|
309 | 278 | * Truncates a string up to a maximum number of characters (if needed).
|
| 279 | + * In case of truncation, '...' are appended to the end of the string. |
310 | 280 | * @static
|
311 | 281 | * @param {string} str The string to truncate.
|
312 | 282 | * @param {number} maxSize The string maximum size.
|
313 |
| - * @returns {string} The truncated string (in case of truncation, '...' are appended to the end). |
| 283 | + * @returns {string} The truncated string. |
314 | 284 | */
|
315 | 285 | static truncateString(str, maxSize) {
|
316 | 286 | const SUFIX = '...';
|
@@ -1296,7 +1266,7 @@ class AsciiTable3 {
|
1296 | 1266 |
|
1297 | 1267 | // full table width
|
1298 | 1268 | const maxWidth =
|
1299 |
| - colsWidth.reduce(function(a, b) { return a + b; }, 0) + // data column sizes |
| 1269 | + colsWidth.reduce(function(a, b) { return a + b; }, 0) + // data column sizes |
1300 | 1270 | (colsWidth.length - 1) * strlen(style.borders.data.colSeparator); // mid column separators
|
1301 | 1271 |
|
1302 | 1272 | var result = '';
|
|
0 commit comments