table 6.0.9 → 6.3.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.
Files changed (107) hide show
  1. package/README.md +53 -1
  2. package/dist/src/alignString.d.ts +6 -0
  3. package/dist/src/alignString.js +64 -0
  4. package/dist/src/alignTableData.d.ts +3 -0
  5. package/dist/src/alignTableData.js +21 -0
  6. package/dist/src/calculateCellHeight.d.ts +2 -0
  7. package/dist/src/calculateCellHeight.js +17 -0
  8. package/dist/src/calculateCellWidthIndex.d.ts +6 -0
  9. package/dist/src/calculateCellWidthIndex.js +17 -0
  10. package/dist/src/calculateMaximumColumnWidthIndex.d.ts +6 -0
  11. package/dist/src/calculateMaximumColumnWidthIndex.js +25 -0
  12. package/dist/src/calculateRowHeightIndex.d.ts +6 -0
  13. package/dist/src/calculateRowHeightIndex.js +30 -0
  14. package/dist/src/createStream.d.ts +3 -0
  15. package/dist/src/createStream.js +74 -0
  16. package/dist/src/drawBorder.d.ts +25 -0
  17. package/dist/src/drawBorder.js +55 -0
  18. package/dist/src/drawHorizontalContent.d.ts +11 -0
  19. package/dist/src/drawHorizontalContent.js +19 -0
  20. package/dist/src/drawRow.d.ts +7 -0
  21. package/dist/src/drawRow.js +17 -0
  22. package/dist/src/drawTable.d.ts +3 -0
  23. package/dist/src/drawTable.js +38 -0
  24. package/dist/src/getBorderCharacters.d.ts +3 -0
  25. package/dist/src/getBorderCharacters.js +83 -0
  26. package/dist/{index.js.flow → src/index.d.ts} +2 -6
  27. package/dist/src/index.js +24 -0
  28. package/dist/src/makeConfig.d.ts +8 -0
  29. package/dist/src/makeConfig.js +59 -0
  30. package/dist/src/makeStreamConfig.d.ts +8 -0
  31. package/dist/src/makeStreamConfig.js +60 -0
  32. package/dist/src/mapDataUsingRowHeightIndex.d.ts +3 -0
  33. package/dist/src/mapDataUsingRowHeightIndex.js +27 -0
  34. package/dist/src/padTableData.d.ts +3 -0
  35. package/dist/src/padTableData.js +11 -0
  36. package/dist/src/stringifyTableData.d.ts +3 -0
  37. package/dist/src/stringifyTableData.js +8 -0
  38. package/dist/src/table.d.ts +3 -0
  39. package/dist/src/table.js +28 -0
  40. package/dist/src/truncateTableData.d.ts +6 -0
  41. package/dist/src/truncateTableData.js +20 -0
  42. package/dist/src/types/api.d.ts +100 -0
  43. package/dist/src/types/api.js +3 -0
  44. package/dist/src/types/internal.d.ts +1 -0
  45. package/dist/src/types/internal.js +3 -0
  46. package/dist/src/validateConfig.d.ts +3 -0
  47. package/dist/src/validateConfig.js +27 -0
  48. package/dist/src/validateTableData.d.ts +2 -0
  49. package/dist/src/validateTableData.js +29 -0
  50. package/dist/{validators.js → src/validators.js} +54 -14
  51. package/dist/src/wrapCell.d.ts +9 -0
  52. package/dist/src/wrapCell.js +33 -0
  53. package/dist/src/wrapString.d.ts +10 -0
  54. package/dist/src/wrapString.js +25 -0
  55. package/dist/src/wrapWord.d.ts +2 -0
  56. package/dist/src/wrapWord.js +29 -0
  57. package/package.json +32 -25
  58. package/dist/alignString.js +0 -107
  59. package/dist/alignString.js.flow +0 -97
  60. package/dist/alignTableData.js +0 -34
  61. package/dist/alignTableData.js.flow +0 -21
  62. package/dist/calculateCellHeight.js +0 -37
  63. package/dist/calculateCellHeight.js.flow +0 -24
  64. package/dist/calculateCellWidthIndex.js +0 -27
  65. package/dist/calculateCellWidthIndex.js.flow +0 -17
  66. package/dist/calculateMaximumColumnWidthIndex.js +0 -36
  67. package/dist/calculateMaximumColumnWidthIndex.js.flow +0 -27
  68. package/dist/calculateRowHeightIndex.js +0 -45
  69. package/dist/calculateRowHeightIndex.js.flow +0 -36
  70. package/dist/createStream.js +0 -124
  71. package/dist/createStream.js.flow +0 -125
  72. package/dist/drawBorder.js +0 -109
  73. package/dist/drawBorder.js.flow +0 -101
  74. package/dist/drawRow.js +0 -25
  75. package/dist/drawRow.js.flow +0 -15
  76. package/dist/drawTable.js +0 -58
  77. package/dist/drawTable.js.flow +0 -53
  78. package/dist/getBorderCharacters.js +0 -118
  79. package/dist/getBorderCharacters.js.flow +0 -120
  80. package/dist/index.js +0 -31
  81. package/dist/makeConfig.js +0 -91
  82. package/dist/makeConfig.js.flow +0 -76
  83. package/dist/makeStreamConfig.js +0 -97
  84. package/dist/makeStreamConfig.js.flow +0 -83
  85. package/dist/mapDataUsingRowHeightIndex.js +0 -41
  86. package/dist/mapDataUsingRowHeightIndex.js.flow +0 -34
  87. package/dist/padTableData.js +0 -23
  88. package/dist/padTableData.js.flow +0 -14
  89. package/dist/schemas/config.json +0 -23
  90. package/dist/schemas/shared.json +0 -98
  91. package/dist/schemas/streamConfig.json +0 -20
  92. package/dist/stringifyTableData.js +0 -21
  93. package/dist/stringifyTableData.js.flow +0 -11
  94. package/dist/table.js +0 -109
  95. package/dist/table.js.flow +0 -96
  96. package/dist/truncateTableData.js +0 -29
  97. package/dist/truncateTableData.js.flow +0 -17
  98. package/dist/validateConfig.js +0 -40
  99. package/dist/validateConfig.js.flow +0 -27
  100. package/dist/validateTableData.js +0 -54
  101. package/dist/validateTableData.js.flow +0 -44
  102. package/dist/wrapCell.js +0 -47
  103. package/dist/wrapCell.js.flow +0 -35
  104. package/dist/wrapString.js +0 -39
  105. package/dist/wrapString.js.flow +0 -29
  106. package/dist/wrapWord.js +0 -46
  107. package/dist/wrapWord.js.flow +0 -39
package/README.md CHANGED
@@ -14,6 +14,7 @@
14
14
  * [Cell Content Alignment](#table-usage-cell-content-alignment)
15
15
  * [Column Width](#table-usage-column-width)
16
16
  * [Custom Border](#table-usage-custom-border)
17
+ * [Draw Vertical Line](#table-usage-draw-vertical-line)
17
18
  * [Draw Horizontal Line](#table-usage-draw-horizontal-line)
18
19
  * [Single Line Mode](#table-usage-single-line-mode)
19
20
  * [Padding Cell Content](#table-usage-padding-cell-content)
@@ -292,6 +293,57 @@ console.log(output);
292
293
  └────┴────┴────┘
293
294
  ```
294
295
 
296
+ <a name="table-usage-draw-vertical-line"></a>
297
+ ### Draw Vertical Line
298
+
299
+ `{function} config.drawVerticalLine` property is a function that is called for every non-content column in the table. The result of the function `{boolean}` determines whether a border is drawn.
300
+
301
+ ```js
302
+ let data,
303
+ output,
304
+ options;
305
+
306
+ data = [
307
+ ['0A', '0B', '0C'],
308
+ ['1A', '1B', '1C'],
309
+ ['2A', '2B', '2C'],
310
+ ['3A', '3B', '3C'],
311
+ ['4A', '4B', '4C']
312
+ ];
313
+
314
+ options = {
315
+ /**
316
+ * @typedef {function} drawVerticalLine
317
+ * @param {number} index
318
+ * @param {number} size
319
+ * @return {boolean}
320
+ */
321
+ drawVerticalLine: (index, size) => {
322
+ return index === 0 || index === size;
323
+ }
324
+ };
325
+
326
+ output = table(data, options);
327
+
328
+ console.log(output);
329
+
330
+ ```
331
+
332
+ ```
333
+ ╔════════════╗
334
+ ║ 0A 0B 0C ║
335
+ ╟────────────╢
336
+ ║ 1A 1B 1C ║
337
+ ╟────────────╢
338
+ ║ 2A 2B 2C ║
339
+ ╟────────────╢
340
+ ║ 3A 3B 3C ║
341
+ ╟────────────╢
342
+ ║ 4A 4B 4C ║
343
+ ╚════════════╝
344
+
345
+ ```
346
+
295
347
  <a name="table-usage-draw-horizontal-line"></a>
296
348
  ### Draw Horizontal Line
297
349
 
@@ -647,7 +699,7 @@ console.log(output);
647
699
  ║ t amet, consectetur ║
648
700
  ║ adipiscing elit. Pha ║
649
701
  ║ sellus pulvinar nibh ║
650
- ║ sed mauris conva... ║
702
+ ║ sed mauris convall… ║
651
703
  ╚══════════════════════╝
652
704
  ```
653
705
 
@@ -0,0 +1,6 @@
1
+ declare const _default: (subject: string, containerWidth: number, alignment: string) => string;
2
+ /**
3
+ * Pads a string to the left and/or right to position the subject
4
+ * text in a desired alignment within a container.
5
+ */
6
+ export default _default;
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const is_number_object_1 = __importDefault(require("is-number-object"));
7
+ const is_string_1 = __importDefault(require("is-string"));
8
+ const string_width_1 = __importDefault(require("string-width"));
9
+ const alignLeft = (subject, width) => {
10
+ return subject + ' '.repeat(width);
11
+ };
12
+ const alignRight = (subject, width) => {
13
+ return ' '.repeat(width) + subject;
14
+ };
15
+ const alignCenter = (subject, width) => {
16
+ let halfWidth;
17
+ halfWidth = width / 2;
18
+ if (width % 2 === 0) {
19
+ return ' '.repeat(halfWidth) + subject + ' '.repeat(halfWidth);
20
+ }
21
+ else {
22
+ halfWidth = Math.floor(halfWidth);
23
+ return ' '.repeat(halfWidth) + subject + ' '.repeat(halfWidth + 1);
24
+ }
25
+ };
26
+ const alignments = [
27
+ 'left',
28
+ 'right',
29
+ 'center',
30
+ ];
31
+ /**
32
+ * Pads a string to the left and/or right to position the subject
33
+ * text in a desired alignment within a container.
34
+ */
35
+ exports.default = (subject, containerWidth, alignment) => {
36
+ if (!is_string_1.default(subject)) {
37
+ throw new TypeError('Subject parameter value must be a string.');
38
+ }
39
+ if (!is_number_object_1.default(containerWidth)) {
40
+ throw new TypeError('Container width parameter value must be a number.');
41
+ }
42
+ const subjectWidth = string_width_1.default(subject);
43
+ if (subjectWidth > containerWidth) {
44
+ throw new Error('Subject parameter value width cannot be greater than the container width.');
45
+ }
46
+ if (!is_string_1.default(alignment)) {
47
+ throw new TypeError('Alignment parameter value must be a string.');
48
+ }
49
+ if (!alignments.includes(alignment)) {
50
+ throw new Error('Alignment parameter value must be a known alignment parameter value (left, right, center).');
51
+ }
52
+ if (subjectWidth === 0) {
53
+ return ' '.repeat(containerWidth);
54
+ }
55
+ const availableWidth = containerWidth - subjectWidth;
56
+ if (alignment === 'left') {
57
+ return alignLeft(subject, availableWidth);
58
+ }
59
+ if (alignment === 'right') {
60
+ return alignRight(subject, availableWidth);
61
+ }
62
+ return alignCenter(subject, availableWidth);
63
+ };
64
+ //# sourceMappingURL=alignString.js.map
@@ -0,0 +1,3 @@
1
+ import type { BaseConfig, Row } from './types/internal';
2
+ declare const _default: (rows: Row[], config: BaseConfig) => Row[];
3
+ export default _default;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const string_width_1 = __importDefault(require("string-width"));
7
+ const alignString_1 = __importDefault(require("./alignString"));
8
+ exports.default = (rows, config) => {
9
+ return rows.map((row) => {
10
+ return row.map((cell, index) => {
11
+ const column = config.columns[index];
12
+ if (string_width_1.default(cell) === column.width) {
13
+ return cell;
14
+ }
15
+ else {
16
+ return alignString_1.default(cell, column.width, column.alignment);
17
+ }
18
+ });
19
+ });
20
+ };
21
+ //# sourceMappingURL=alignTableData.js.map
@@ -0,0 +1,2 @@
1
+ declare const _default: (value: string, columnWidth: number, useWrapWord?: boolean) => number;
2
+ export default _default;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const is_string_1 = __importDefault(require("is-string"));
7
+ const wrapCell_1 = __importDefault(require("./wrapCell"));
8
+ exports.default = (value, columnWidth, useWrapWord = false) => {
9
+ if (!is_string_1.default(value)) {
10
+ throw new TypeError('Value must be a string.');
11
+ }
12
+ if (!Number.isInteger(columnWidth) || columnWidth < 1) {
13
+ throw new TypeError('Column width must be an integer greater than 0.');
14
+ }
15
+ return wrapCell_1.default(value, columnWidth, useWrapWord).length;
16
+ };
17
+ //# sourceMappingURL=calculateCellHeight.js.map
@@ -0,0 +1,6 @@
1
+ import type { Cell } from './types/internal';
2
+ declare const _default: (cells: Cell[]) => number[];
3
+ /**
4
+ * Calculates width of each cell contents.
5
+ */
6
+ export default _default;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const string_width_1 = __importDefault(require("string-width"));
7
+ /**
8
+ * Calculates width of each cell contents.
9
+ */
10
+ exports.default = (cells) => {
11
+ return cells.map((value) => {
12
+ return Math.max(...value.split('\n').map((line) => {
13
+ return string_width_1.default(line);
14
+ }));
15
+ });
16
+ };
17
+ //# sourceMappingURL=calculateCellWidthIndex.js.map
@@ -0,0 +1,6 @@
1
+ import type { Row } from './types/internal';
2
+ declare const _default: (rows: Row[]) => number[];
3
+ /**
4
+ * Produces an array of values that describe the largest value length (width) in every column.
5
+ */
6
+ export default _default;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const calculateCellWidthIndex_1 = __importDefault(require("./calculateCellWidthIndex"));
7
+ /**
8
+ * Produces an array of values that describe the largest value length (width) in every column.
9
+ */
10
+ exports.default = (rows) => {
11
+ if (!rows[0]) {
12
+ throw new Error('Dataset must have at least one row.');
13
+ }
14
+ const columns = new Array(rows[0].length).fill(0);
15
+ rows.forEach((row) => {
16
+ const columnWidthIndex = calculateCellWidthIndex_1.default(row);
17
+ columnWidthIndex.forEach((valueWidth, index0) => {
18
+ if (columns[index0] < valueWidth) {
19
+ columns[index0] = valueWidth;
20
+ }
21
+ });
22
+ });
23
+ return columns;
24
+ };
25
+ //# sourceMappingURL=calculateMaximumColumnWidthIndex.js.map
@@ -0,0 +1,6 @@
1
+ import type { BaseConfig, Row } from './types/internal';
2
+ declare const _default: (rows: Row[], config: BaseConfig) => number[];
3
+ /**
4
+ * Calculates the vertical row span index.
5
+ */
6
+ export default _default;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const is_boolean_object_1 = __importDefault(require("is-boolean-object"));
7
+ const is_number_object_1 = __importDefault(require("is-number-object"));
8
+ const calculateCellHeight_1 = __importDefault(require("./calculateCellHeight"));
9
+ /**
10
+ * Calculates the vertical row span index.
11
+ */
12
+ exports.default = (rows, config) => {
13
+ const tableWidth = rows[0].length;
14
+ const rowSpanIndex = [];
15
+ rows.forEach((cells) => {
16
+ const cellHeightIndex = new Array(tableWidth).fill(1);
17
+ cells.forEach((value, index1) => {
18
+ if (!is_number_object_1.default(config.columns[index1].width)) {
19
+ throw new TypeError('column[index].width must be a number.');
20
+ }
21
+ if (!is_boolean_object_1.default(config.columns[index1].wrapWord)) {
22
+ throw new TypeError('column[index].wrapWord must be a boolean.');
23
+ }
24
+ cellHeightIndex[index1] = calculateCellHeight_1.default(value, config.columns[index1].width, config.columns[index1].wrapWord);
25
+ });
26
+ rowSpanIndex.push(Math.max(...cellHeightIndex));
27
+ });
28
+ return rowSpanIndex;
29
+ };
30
+ //# sourceMappingURL=calculateRowHeightIndex.js.map
@@ -0,0 +1,3 @@
1
+ import type { StreamUserConfig, WritableStream } from './types/api';
2
+ declare const _default: (userConfig: StreamUserConfig) => WritableStream;
3
+ export default _default;
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const alignTableData_1 = __importDefault(require("./alignTableData"));
7
+ const calculateRowHeightIndex_1 = __importDefault(require("./calculateRowHeightIndex"));
8
+ const drawBorder_1 = require("./drawBorder");
9
+ const drawRow_1 = __importDefault(require("./drawRow"));
10
+ const makeStreamConfig_1 = __importDefault(require("./makeStreamConfig"));
11
+ const mapDataUsingRowHeightIndex_1 = __importDefault(require("./mapDataUsingRowHeightIndex"));
12
+ const padTableData_1 = __importDefault(require("./padTableData"));
13
+ const stringifyTableData_1 = __importDefault(require("./stringifyTableData"));
14
+ const truncateTableData_1 = __importDefault(require("./truncateTableData"));
15
+ const prepareData = (data, config) => {
16
+ let rows = stringifyTableData_1.default(data);
17
+ rows = truncateTableData_1.default(rows, config);
18
+ const rowHeightIndex = calculateRowHeightIndex_1.default(rows, config);
19
+ rows = mapDataUsingRowHeightIndex_1.default(rows, rowHeightIndex, config);
20
+ rows = alignTableData_1.default(rows, config);
21
+ rows = padTableData_1.default(rows, config);
22
+ return rows;
23
+ };
24
+ const create = (row, columnWidthIndex, config) => {
25
+ const rows = prepareData([row], config);
26
+ const body = rows.map((literalRow) => {
27
+ return drawRow_1.default(literalRow, config);
28
+ }).join('');
29
+ let output;
30
+ output = '';
31
+ output += drawBorder_1.drawBorderTop(columnWidthIndex, config);
32
+ output += body;
33
+ output += drawBorder_1.drawBorderBottom(columnWidthIndex, config);
34
+ output = output.trimEnd();
35
+ process.stdout.write(output);
36
+ };
37
+ const append = (row, columnWidthIndex, config) => {
38
+ const rows = prepareData([row], config);
39
+ const body = rows.map((literalRow) => {
40
+ return drawRow_1.default(literalRow, config);
41
+ }).join('');
42
+ let output = '';
43
+ const bottom = drawBorder_1.drawBorderBottom(columnWidthIndex, config);
44
+ if (bottom !== '\n') {
45
+ output = '\r\u001B[K';
46
+ }
47
+ output += drawBorder_1.drawBorderJoin(columnWidthIndex, config);
48
+ output += body;
49
+ output += bottom;
50
+ output = output.trimEnd();
51
+ process.stdout.write(output);
52
+ };
53
+ exports.default = (userConfig) => {
54
+ const config = makeStreamConfig_1.default(userConfig);
55
+ const columnWidthIndex = Object.values(config.columns).map((column) => {
56
+ return column.width + column.paddingLeft + column.paddingRight;
57
+ });
58
+ let empty = true;
59
+ return {
60
+ write: (row) => {
61
+ if (row.length !== config.columnCount) {
62
+ throw new Error('Row cell count does not match the config.columnCount.');
63
+ }
64
+ if (empty) {
65
+ empty = false;
66
+ create(row, columnWidthIndex, config);
67
+ }
68
+ else {
69
+ append(row, columnWidthIndex, config);
70
+ }
71
+ },
72
+ };
73
+ };
74
+ //# sourceMappingURL=createStream.js.map
@@ -0,0 +1,25 @@
1
+ import type { DrawVerticalLine } from './types/api';
2
+ import type { BottomBorderConfig, JoinBorderConfig, TopBorderConfig } from './types/internal';
3
+ declare type Separator = {
4
+ readonly left: string;
5
+ readonly right: string;
6
+ readonly body: string;
7
+ readonly join: string;
8
+ };
9
+ declare const drawBorder: (columnSizeIndex: number[], config: {
10
+ separator: Separator;
11
+ drawVerticalLine: DrawVerticalLine;
12
+ }) => string;
13
+ declare const drawBorderTop: (columnSizeIndex: number[], config: {
14
+ border: TopBorderConfig;
15
+ drawVerticalLine: DrawVerticalLine;
16
+ }) => string;
17
+ declare const drawBorderJoin: (columnSizeIndex: number[], config: {
18
+ border: JoinBorderConfig;
19
+ drawVerticalLine: DrawVerticalLine;
20
+ }) => string;
21
+ declare const drawBorderBottom: (columnSizeIndex: number[], config: {
22
+ border: BottomBorderConfig;
23
+ drawVerticalLine: DrawVerticalLine;
24
+ }) => string;
25
+ export { drawBorder, drawBorderBottom, drawBorderJoin, drawBorderTop, };
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.drawBorderTop = exports.drawBorderJoin = exports.drawBorderBottom = exports.drawBorder = void 0;
7
+ const drawHorizontalContent_1 = __importDefault(require("./drawHorizontalContent"));
8
+ const drawBorder = (columnSizeIndex, config) => {
9
+ const columns = columnSizeIndex.map((size) => {
10
+ return config.separator.body.repeat(size);
11
+ });
12
+ return drawHorizontalContent_1.default(columns, config);
13
+ };
14
+ exports.drawBorder = drawBorder;
15
+ const drawBorderTop = (columnSizeIndex, config) => {
16
+ const result = drawBorder(columnSizeIndex, {
17
+ ...config,
18
+ separator: {
19
+ body: config.border.topBody,
20
+ join: config.border.topJoin,
21
+ left: config.border.topLeft,
22
+ right: config.border.topRight,
23
+ },
24
+ });
25
+ if (result === '\n') {
26
+ return '';
27
+ }
28
+ return result;
29
+ };
30
+ exports.drawBorderTop = drawBorderTop;
31
+ const drawBorderJoin = (columnSizeIndex, config) => {
32
+ return drawBorder(columnSizeIndex, {
33
+ ...config,
34
+ separator: {
35
+ body: config.border.joinBody,
36
+ join: config.border.joinJoin,
37
+ left: config.border.joinLeft,
38
+ right: config.border.joinRight,
39
+ },
40
+ });
41
+ };
42
+ exports.drawBorderJoin = drawBorderJoin;
43
+ const drawBorderBottom = (columnSizeIndex, config) => {
44
+ return drawBorder(columnSizeIndex, {
45
+ ...config,
46
+ separator: {
47
+ body: config.border.bottomBody,
48
+ join: config.border.bottomJoin,
49
+ left: config.border.bottomLeft,
50
+ right: config.border.bottomRight,
51
+ },
52
+ });
53
+ };
54
+ exports.drawBorderBottom = drawBorderBottom;
55
+ //# sourceMappingURL=drawBorder.js.map
@@ -0,0 +1,11 @@
1
+ import type { DrawVerticalLine } from './types/api';
2
+ declare type Separator = {
3
+ readonly left: string;
4
+ readonly right: string;
5
+ readonly join: string;
6
+ };
7
+ export default function drawHorizontalContent(contents: string[], config: {
8
+ separator: Separator;
9
+ drawVerticalLine: DrawVerticalLine;
10
+ }): string;
11
+ export {};
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function drawHorizontalContent(contents, config) {
4
+ const { separator, drawVerticalLine } = config;
5
+ const contentSize = contents.length;
6
+ const result = [];
7
+ result.push(drawVerticalLine(0, contentSize) ? separator.left : '');
8
+ contents.forEach((content, index) => {
9
+ result.push(content);
10
+ // Only append the join separator if it is not the last content
11
+ if (index + 1 < contentSize) {
12
+ result.push(drawVerticalLine(index + 1, contentSize) ? separator.join : '');
13
+ }
14
+ });
15
+ result.push(drawVerticalLine(contentSize, contentSize) ? separator.right : '');
16
+ return result.join('') + '\n';
17
+ }
18
+ exports.default = drawHorizontalContent;
19
+ //# sourceMappingURL=drawHorizontalContent.js.map
@@ -0,0 +1,7 @@
1
+ import type { DrawVerticalLine } from './types/api';
2
+ import type { BodyBorderConfig, Row } from './types/internal';
3
+ declare const _default: (row: Row, config: {
4
+ border: BodyBorderConfig;
5
+ drawVerticalLine: DrawVerticalLine;
6
+ }) => string;
7
+ export default _default;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const drawHorizontalContent_1 = __importDefault(require("./drawHorizontalContent"));
7
+ exports.default = (row, config) => {
8
+ return drawHorizontalContent_1.default(row, {
9
+ ...config,
10
+ separator: {
11
+ join: config.border.bodyJoin,
12
+ left: config.border.bodyLeft,
13
+ right: config.border.bodyRight,
14
+ },
15
+ });
16
+ };
17
+ //# sourceMappingURL=drawRow.js.map
@@ -0,0 +1,3 @@
1
+ import type { TableConfig, Row } from './types/internal';
2
+ declare const _default: (rows: Row[], columnSizeIndex: number[], rowSpanIndex: number[], config: TableConfig) => string;
3
+ export default _default;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const drawBorder_1 = require("./drawBorder");
7
+ const drawRow_1 = __importDefault(require("./drawRow"));
8
+ exports.default = (rows, columnSizeIndex, rowSpanIndex, config) => {
9
+ const { drawHorizontalLine, singleLine, } = config;
10
+ let output;
11
+ let realRowIndex;
12
+ let rowHeight;
13
+ const rowCount = rows.length;
14
+ realRowIndex = 0;
15
+ output = '';
16
+ if (drawHorizontalLine(realRowIndex, rowCount)) {
17
+ output += drawBorder_1.drawBorderTop(columnSizeIndex, config);
18
+ }
19
+ rows.forEach((row, index0) => {
20
+ output += drawRow_1.default(row, config);
21
+ if (!rowHeight) {
22
+ rowHeight = rowSpanIndex[realRowIndex];
23
+ realRowIndex++;
24
+ }
25
+ rowHeight--;
26
+ if (!singleLine &&
27
+ rowHeight === 0 &&
28
+ index0 !== rowCount - 1 &&
29
+ drawHorizontalLine(realRowIndex, rowCount)) {
30
+ output += drawBorder_1.drawBorderJoin(columnSizeIndex, config);
31
+ }
32
+ });
33
+ if (drawHorizontalLine(realRowIndex, rowCount)) {
34
+ output += drawBorder_1.drawBorderBottom(columnSizeIndex, config);
35
+ }
36
+ return output;
37
+ };
38
+ //# sourceMappingURL=drawTable.js.map
@@ -0,0 +1,3 @@
1
+ import type { BorderConfig } from './types/api';
2
+ declare const _default: (name: string) => BorderConfig;
3
+ export default _default;
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ /* eslint-disable sort-keys-fix/sort-keys-fix */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.default = (name) => {
5
+ if (name === 'honeywell') {
6
+ return {
7
+ topBody: '═',
8
+ topJoin: '╤',
9
+ topLeft: '╔',
10
+ topRight: '╗',
11
+ bottomBody: '═',
12
+ bottomJoin: '╧',
13
+ bottomLeft: '╚',
14
+ bottomRight: '╝',
15
+ bodyLeft: '║',
16
+ bodyRight: '║',
17
+ bodyJoin: '│',
18
+ joinBody: '─',
19
+ joinLeft: '╟',
20
+ joinRight: '╢',
21
+ joinJoin: '┼',
22
+ };
23
+ }
24
+ if (name === 'norc') {
25
+ return {
26
+ topBody: '─',
27
+ topJoin: '┬',
28
+ topLeft: '┌',
29
+ topRight: '┐',
30
+ bottomBody: '─',
31
+ bottomJoin: '┴',
32
+ bottomLeft: '└',
33
+ bottomRight: '┘',
34
+ bodyLeft: '│',
35
+ bodyRight: '│',
36
+ bodyJoin: '│',
37
+ joinBody: '─',
38
+ joinLeft: '├',
39
+ joinRight: '┤',
40
+ joinJoin: '┼',
41
+ };
42
+ }
43
+ if (name === 'ramac') {
44
+ return {
45
+ topBody: '-',
46
+ topJoin: '+',
47
+ topLeft: '+',
48
+ topRight: '+',
49
+ bottomBody: '-',
50
+ bottomJoin: '+',
51
+ bottomLeft: '+',
52
+ bottomRight: '+',
53
+ bodyLeft: '|',
54
+ bodyRight: '|',
55
+ bodyJoin: '|',
56
+ joinBody: '-',
57
+ joinLeft: '|',
58
+ joinRight: '|',
59
+ joinJoin: '|',
60
+ };
61
+ }
62
+ if (name === 'void') {
63
+ return {
64
+ topBody: '',
65
+ topJoin: '',
66
+ topLeft: '',
67
+ topRight: '',
68
+ bottomBody: '',
69
+ bottomJoin: '',
70
+ bottomLeft: '',
71
+ bottomRight: '',
72
+ bodyLeft: '',
73
+ bodyRight: '',
74
+ bodyJoin: '',
75
+ joinBody: '',
76
+ joinLeft: '',
77
+ joinRight: '',
78
+ joinJoin: '',
79
+ };
80
+ }
81
+ throw new Error('Unknown border template "' + name + '".');
82
+ };
83
+ //# sourceMappingURL=getBorderCharacters.js.map
@@ -1,9 +1,5 @@
1
1
  import createStream from './createStream';
2
2
  import getBorderCharacters from './getBorderCharacters';
3
3
  import table from './table';
4
-
5
- export {
6
- table,
7
- createStream,
8
- getBorderCharacters,
9
- };
4
+ export { table, createStream, getBorderCharacters, };
5
+ export * from './types/api';