table 6.7.3 → 6.7.4

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 (148) hide show
  1. package/dist/{alignString.d.ts → src/alignString.d.ts} +0 -0
  2. package/dist/{alignString.js → src/alignString.js} +4 -3
  3. package/dist/{alignTableData.d.ts → src/alignTableData.d.ts} +0 -0
  4. package/dist/{alignTableData.js → src/alignTableData.js} +2 -1
  5. package/dist/{calculateCellHeight.d.ts → src/calculateCellHeight.d.ts} +0 -0
  6. package/dist/{calculateCellHeight.js → src/calculateCellHeight.js} +2 -1
  7. package/dist/{calculateCellWidths.d.ts → src/calculateCellWidths.d.ts} +0 -0
  8. package/dist/{calculateCellWidths.js → src/calculateCellWidths.js} +1 -0
  9. package/dist/{calculateColumnWidths.d.ts → src/calculateColumnWidths.d.ts} +0 -0
  10. package/dist/{calculateColumnWidths.js → src/calculateColumnWidths.js} +2 -1
  11. package/dist/{calculateRowHeights.d.ts → src/calculateRowHeights.d.ts} +0 -0
  12. package/dist/{calculateRowHeights.js → src/calculateRowHeights.js} +2 -1
  13. package/dist/{createStream.d.ts → src/createStream.d.ts} +0 -0
  14. package/dist/{createStream.js → src/createStream.js} +14 -13
  15. package/dist/{drawBorder.d.ts → src/drawBorder.d.ts} +3 -3
  16. package/dist/{drawBorder.js → src/drawBorder.js} +2 -1
  17. package/dist/{drawContent.d.ts → src/drawContent.d.ts} +0 -0
  18. package/dist/{drawContent.js → src/drawContent.js} +1 -0
  19. package/dist/{drawHeader.d.ts → src/drawHeader.d.ts} +0 -0
  20. package/dist/{drawHeader.js → src/drawHeader.js} +7 -6
  21. package/dist/{drawRow.d.ts → src/drawRow.d.ts} +0 -0
  22. package/dist/{drawRow.js → src/drawRow.js} +2 -1
  23. package/dist/{drawTable.d.ts → src/drawTable.d.ts} +0 -0
  24. package/dist/{drawTable.js → src/drawTable.js} +7 -6
  25. package/dist/{generated → src/generated}/validators.d.ts +0 -0
  26. package/dist/{generated → src/generated}/validators.js +1 -0
  27. package/dist/{getBorderCharacters.d.ts → src/getBorderCharacters.d.ts} +0 -0
  28. package/dist/{getBorderCharacters.js → src/getBorderCharacters.js} +1 -0
  29. package/dist/{index.d.ts → src/index.d.ts} +0 -0
  30. package/dist/{index.js → src/index.js} +1 -0
  31. package/dist/{makeStreamConfig.d.ts → src/makeStreamConfig.d.ts} +0 -0
  32. package/dist/{makeStreamConfig.js → src/makeStreamConfig.js} +3 -2
  33. package/dist/{makeTableConfig.d.ts → src/makeTableConfig.d.ts} +0 -0
  34. package/dist/{makeTableConfig.js → src/makeTableConfig.js} +4 -3
  35. package/dist/{mapDataUsingRowHeights.d.ts → src/mapDataUsingRowHeights.d.ts} +0 -0
  36. package/dist/{mapDataUsingRowHeights.js → src/mapDataUsingRowHeights.js} +2 -1
  37. package/dist/{padTableData.d.ts → src/padTableData.d.ts} +0 -0
  38. package/dist/{padTableData.js → src/padTableData.js} +2 -1
  39. package/dist/{stringifyTableData.d.ts → src/stringifyTableData.d.ts} +0 -0
  40. package/dist/{stringifyTableData.js → src/stringifyTableData.js} +2 -1
  41. package/dist/{table.d.ts → src/table.d.ts} +0 -0
  42. package/dist/src/table.js +27 -0
  43. package/dist/{truncateTableData.d.ts → src/truncateTableData.d.ts} +0 -0
  44. package/dist/{truncateTableData.js → src/truncateTableData.js} +3 -2
  45. package/dist/{types → src/types}/api.d.ts +0 -0
  46. package/dist/{types → src/types}/api.js +1 -0
  47. package/dist/{types → src/types}/internal.d.ts +0 -0
  48. package/dist/{types → src/types}/internal.js +1 -0
  49. package/dist/{utils.d.ts → src/utils.d.ts} +0 -0
  50. package/dist/{utils.js → src/utils.js} +4 -3
  51. package/dist/{validateConfig.d.ts → src/validateConfig.d.ts} +0 -0
  52. package/dist/{validateConfig.js → src/validateConfig.js} +2 -0
  53. package/dist/{validateTableData.d.ts → src/validateTableData.d.ts} +0 -0
  54. package/dist/{validateTableData.js → src/validateTableData.js} +2 -1
  55. package/dist/{wrapCell.d.ts → src/wrapCell.d.ts} +0 -0
  56. package/dist/{wrapCell.js → src/wrapCell.js} +4 -3
  57. package/dist/{wrapString.d.ts → src/wrapString.d.ts} +0 -0
  58. package/dist/{wrapString.js → src/wrapString.js} +4 -3
  59. package/dist/{wrapWord.d.ts → src/wrapWord.d.ts} +0 -0
  60. package/dist/{wrapWord.js → src/wrapWord.js} +5 -4
  61. package/dist/test/README/api/getBorderCharacters.d.ts +1 -0
  62. package/dist/test/README/api/getBorderCharacters.js +76 -0
  63. package/dist/test/README/api/stream/streaming.d.ts +1 -0
  64. package/dist/test/README/api/stream/streaming.js +41 -0
  65. package/dist/test/README/api/table/border.d.ts +1 -0
  66. package/dist/test/README/api/table/border.js +45 -0
  67. package/dist/test/README/api/table/column/alignment.d.ts +1 -0
  68. package/dist/test/README/api/table/column/alignment.js +34 -0
  69. package/dist/test/README/api/table/column/padding.d.ts +1 -0
  70. package/dist/test/README/api/table/column/padding.js +36 -0
  71. package/dist/test/README/api/table/column/truncate.d.ts +1 -0
  72. package/dist/test/README/api/table/column/truncate.js +29 -0
  73. package/dist/test/README/api/table/column/verticalAlignment.d.ts +1 -0
  74. package/dist/test/README/api/table/column/verticalAlignment.js +28 -0
  75. package/dist/test/README/api/table/column/width.d.ts +1 -0
  76. package/dist/test/README/api/table/column/width.js +30 -0
  77. package/dist/test/README/api/table/column/wrapWord.d.ts +1 -0
  78. package/dist/test/README/api/table/column/wrapWord.js +51 -0
  79. package/dist/test/README/api/table/drawHorizontalLine.d.ts +1 -0
  80. package/dist/test/README/api/table/drawHorizontalLine.js +33 -0
  81. package/dist/test/README/api/table/drawVerticalLine.d.ts +1 -0
  82. package/dist/test/README/api/table/drawVerticalLine.js +35 -0
  83. package/dist/test/README/api/table/header.d.ts +1 -0
  84. package/dist/test/README/api/table/header.js +35 -0
  85. package/dist/test/README/api/table/singleLine.d.ts +1 -0
  86. package/dist/test/README/api/table/singleLine.js +35 -0
  87. package/dist/test/README/demo.d.ts +1 -0
  88. package/dist/test/README/demo.js +71 -0
  89. package/dist/test/README/usage.d.ts +1 -0
  90. package/dist/test/README/usage.js +24 -0
  91. package/dist/test/alignString.d.ts +1 -0
  92. package/dist/test/alignString.js +124 -0
  93. package/dist/test/alignTableData.d.ts +1 -0
  94. package/dist/test/alignTableData.js +63 -0
  95. package/dist/test/calculateCellHeight.d.ts +1 -0
  96. package/dist/test/calculateCellHeight.js +28 -0
  97. package/dist/test/calculateCellWidths.d.ts +1 -0
  98. package/dist/test/calculateCellWidths.js +27 -0
  99. package/dist/test/calculateColumnWidths.d.ts +1 -0
  100. package/dist/test/calculateColumnWidths.js +54 -0
  101. package/dist/test/calculateRowHeights.d.ts +1 -0
  102. package/dist/test/calculateRowHeights.js +61 -0
  103. package/dist/test/createStream.d.ts +1 -0
  104. package/dist/test/createStream.js +122 -0
  105. package/dist/test/drawBorder.d.ts +1 -0
  106. package/dist/test/drawBorder.js +139 -0
  107. package/dist/test/drawHeader.d.ts +1 -0
  108. package/dist/test/drawHeader.js +172 -0
  109. package/dist/test/drawRow.d.ts +1 -0
  110. package/dist/test/drawRow.js +54 -0
  111. package/dist/test/getBorderCharacters.d.ts +1 -0
  112. package/dist/test/getBorderCharacters.js +104 -0
  113. package/dist/test/makeConfig.d.ts +1 -0
  114. package/dist/test/makeConfig.js +152 -0
  115. package/dist/test/makeStreamConfig.d.ts +1 -0
  116. package/dist/test/makeStreamConfig.js +106 -0
  117. package/dist/test/mapDataUsingRowHeights.d.ts +1 -0
  118. package/dist/test/mapDataUsingRowHeights.js +150 -0
  119. package/dist/test/padTableData.d.ts +1 -0
  120. package/dist/test/padTableData.js +62 -0
  121. package/dist/test/streamConfigSamples.d.ts +6 -0
  122. package/dist/test/streamConfigSamples.js +287 -0
  123. package/dist/test/stringifyTableData.d.ts +1 -0
  124. package/dist/test/stringifyTableData.js +17 -0
  125. package/dist/test/table.d.ts +1 -0
  126. package/dist/test/table.js +171 -0
  127. package/dist/test/tableConfigSamples.d.ts +5 -0
  128. package/dist/test/tableConfigSamples.js +202 -0
  129. package/dist/test/truncateTableData.d.ts +1 -0
  130. package/dist/test/truncateTableData.js +92 -0
  131. package/dist/test/utils.d.ts +7 -0
  132. package/dist/test/utils.js +23 -0
  133. package/dist/test/validateConfig.d.ts +1 -0
  134. package/dist/test/validateConfig.js +36 -0
  135. package/dist/test/validateStreamConfig.d.ts +1 -0
  136. package/dist/test/validateStreamConfig.js +39 -0
  137. package/dist/test/validateTableConfig.d.ts +1 -0
  138. package/dist/test/validateTableConfig.js +35 -0
  139. package/dist/test/validateTableData.d.ts +1 -0
  140. package/dist/test/validateTableData.js +106 -0
  141. package/dist/test/wrapCell.d.ts +1 -0
  142. package/dist/test/wrapCell.js +114 -0
  143. package/dist/test/wrapString.d.ts +1 -0
  144. package/dist/test/wrapString.js +45 -0
  145. package/dist/test/wrapWord.d.ts +1 -0
  146. package/dist/test/wrapWord.js +94 -0
  147. package/package.json +12 -26
  148. package/dist/table.js +0 -26
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const src_1 = require("../../src");
4
+ const utils_1 = require("../utils");
5
+ describe('README.md usage/', () => {
6
+ it('basic', () => {
7
+ const data = [
8
+ ['0A', '0B', '0C'],
9
+ ['1A', '1B', '1C'],
10
+ ['2A', '2B', '2C'],
11
+ ];
12
+ const output = (0, src_1.table)(data);
13
+ (0, utils_1.expectTable)(output, `
14
+ ╔════╤════╤════╗
15
+ ║ 0A │ 0B │ 0C ║
16
+ ╟────┼────┼────╢
17
+ ║ 1A │ 1B │ 1C ║
18
+ ╟────┼────┼────╢
19
+ ║ 2A │ 2B │ 2C ║
20
+ ╚════╧════╧════╝
21
+ `);
22
+ });
23
+ });
24
+ //# sourceMappingURL=usage.js.map
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+ /* eslint-disable max-nested-callbacks */
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const chai_1 = require("chai");
8
+ const chalk_1 = __importDefault(require("chalk"));
9
+ const alignString_1 = require("../src/alignString");
10
+ const utils_1 = require("./utils");
11
+ describe('alignString', () => {
12
+ context('subject parameter value width is greater than the container width', () => {
13
+ it('throws an error', () => {
14
+ (0, chai_1.expect)(() => {
15
+ (0, alignString_1.alignString)('aa', 1, 'left');
16
+ }).to.throw(Error, 'Subject parameter value width cannot be greater than the container width.');
17
+ });
18
+ });
19
+ context('subject parameter value', () => {
20
+ context('0 width', () => {
21
+ it('produces a string consisting of container width number of whitespace characters', () => {
22
+ (0, chai_1.expect)((0, alignString_1.alignString)('', 5, 'left')).to.equal(' ', 'left');
23
+ (0, chai_1.expect)((0, alignString_1.alignString)('', 5, 'center')).to.equal(' ', 'center');
24
+ (0, chai_1.expect)((0, alignString_1.alignString)('', 5, 'justify')).to.equal(' ', 'justify');
25
+ (0, chai_1.expect)((0, alignString_1.alignString)('', 5, 'right')).to.equal(' ', 'right');
26
+ });
27
+ });
28
+ context('plain text', () => {
29
+ context('alignment', () => {
30
+ context('left', () => {
31
+ it('pads the string on the right side using a whitespace character', () => {
32
+ (0, chai_1.expect)((0, alignString_1.alignString)('aa', 6, 'left')).to.equal('aa ');
33
+ });
34
+ });
35
+ context('right', () => {
36
+ it('pads the string on the left side using a whitespace character', () => {
37
+ (0, chai_1.expect)((0, alignString_1.alignString)('aa', 6, 'right')).to.equal(' aa');
38
+ });
39
+ });
40
+ context('center', () => {
41
+ it('pads the string on both sides using a whitespace character', () => {
42
+ (0, chai_1.expect)((0, alignString_1.alignString)('aa', 8, 'center')).to.equal(' aa ');
43
+ });
44
+ context('uneven number of available with', () => {
45
+ it('floors the available width; adds extra space to the end of the string', () => {
46
+ (0, chai_1.expect)((0, alignString_1.alignString)('aa', 7, 'center')).to.equal(' aa ');
47
+ });
48
+ });
49
+ });
50
+ context('justify', () => {
51
+ it('align left if not contain spaces', () => {
52
+ (0, chai_1.expect)((0, alignString_1.alignString)('aa', 5, 'justify')).to.equal('aa ');
53
+ });
54
+ it('add missing spaces between two words', () => {
55
+ (0, chai_1.expect)((0, alignString_1.alignString)('a a', 5, 'justify')).to.equal('a a');
56
+ (0, chai_1.expect)((0, alignString_1.alignString)('a a', 5, 'justify')).to.equal('a a');
57
+ (0, chai_1.expect)((0, alignString_1.alignString)('a a', 5, 'justify')).to.equal('a a');
58
+ });
59
+ it('multiple words, distribute spaces from left to right when maximum adding spaces in one place are not greater than 3', () => {
60
+ (0, chai_1.expect)((0, alignString_1.alignString)('a b c', 5, 'justify')).to.equal('a b c');
61
+ (0, chai_1.expect)((0, alignString_1.alignString)('a b c', 6, 'justify')).to.equal('a b c');
62
+ (0, chai_1.expect)((0, alignString_1.alignString)('a b c', 7, 'justify')).to.equal('a b c');
63
+ (0, chai_1.expect)((0, alignString_1.alignString)('a b c', 8, 'justify')).to.equal('a b c');
64
+ (0, chai_1.expect)((0, alignString_1.alignString)('a b c', 9, 'justify')).to.equal('a b c');
65
+ (0, chai_1.expect)((0, alignString_1.alignString)('a b c', 10, 'justify')).to.equal('a b c');
66
+ (0, chai_1.expect)((0, alignString_1.alignString)('a b c', 11, 'justify')).to.equal('a b c');
67
+ (0, chai_1.expect)((0, alignString_1.alignString)('a b c', 12, 'justify')).to.equal('a b c ');
68
+ (0, chai_1.expect)((0, alignString_1.alignString)('a bbb cc d', 11, 'justify')).to.equal('a bbb cc d');
69
+ (0, chai_1.expect)((0, alignString_1.alignString)('a bbb cc d', 12, 'justify')).to.equal('a bbb cc d');
70
+ (0, chai_1.expect)((0, alignString_1.alignString)('a bbb cc d', 13, 'justify')).to.equal('a bbb cc d');
71
+ (0, chai_1.expect)((0, alignString_1.alignString)('a bbb cc d', 14, 'justify')).to.equal('a bbb cc d');
72
+ });
73
+ });
74
+ });
75
+ });
76
+ context('text containing ANSI escape codes', () => {
77
+ context('alignment', () => {
78
+ context('left', () => {
79
+ it('pads the string on the right side using a whitespace character', () => {
80
+ (0, chai_1.expect)((0, alignString_1.alignString)(chalk_1.default.red('aa'), 6, 'left')).to.equal(chalk_1.default.red('aa') + ' ');
81
+ });
82
+ });
83
+ context('right', () => {
84
+ it('pads the string on the left side using a whitespace character', () => {
85
+ (0, chai_1.expect)((0, alignString_1.alignString)(chalk_1.default.red('aa'), 6, 'right')).to.equal(' ' + chalk_1.default.red('aa'));
86
+ });
87
+ });
88
+ context('center', () => {
89
+ it('pads the string on both sides using a whitespace character', () => {
90
+ (0, chai_1.expect)((0, alignString_1.alignString)(chalk_1.default.red('aa'), 6, 'center')).to.equal(' ' + chalk_1.default.red('aa') + ' ');
91
+ });
92
+ context('uneven number of available with', () => {
93
+ it('floors the available width; adds extra space to the end of the string', () => {
94
+ (0, chai_1.expect)((0, alignString_1.alignString)(chalk_1.default.red('aa'), 7, 'center')).to.equal(' ' + chalk_1.default.red('aa') + ' ');
95
+ });
96
+ });
97
+ });
98
+ context('justify', () => {
99
+ it('align left if not contain spaces', () => {
100
+ (0, chai_1.expect)((0, alignString_1.alignString)(chalk_1.default.red('aa'), 5, 'justify')).to.equal(chalk_1.default.red('aa') + ' ');
101
+ });
102
+ it('add missing spaces between two words', () => {
103
+ (0, chai_1.expect)((0, alignString_1.alignString)((0, utils_1.stringToRed)('a a'), 5, 'justify')).to.equal((0, utils_1.stringToRed)('a a'));
104
+ (0, chai_1.expect)((0, alignString_1.alignString)((0, utils_1.stringToRed)('a a'), 5, 'justify')).to.equal((0, utils_1.stringToRed)('a a'));
105
+ (0, chai_1.expect)((0, alignString_1.alignString)((0, utils_1.stringToRed)('a a'), 5, 'justify')).to.equal((0, utils_1.stringToRed)('a a'));
106
+ });
107
+ it('multiple words, uneven spaces add from left to right', () => {
108
+ (0, chai_1.expect)((0, alignString_1.alignString)((0, utils_1.stringToRed)('a b c'), 5, 'justify')).to.equal((0, utils_1.stringToRed)('a b c'));
109
+ (0, chai_1.expect)((0, alignString_1.alignString)((0, utils_1.stringToRed)('a b c'), 6, 'justify')).to.equal((0, utils_1.stringToRed)('a b c'));
110
+ (0, chai_1.expect)((0, alignString_1.alignString)((0, utils_1.stringToRed)('a b c'), 7, 'justify')).to.equal((0, utils_1.stringToRed)('a b c'));
111
+ (0, chai_1.expect)((0, alignString_1.alignString)((0, utils_1.stringToRed)('a b c'), 8, 'justify')).to.equal((0, utils_1.stringToRed)('a b c'));
112
+ (0, chai_1.expect)((0, alignString_1.alignString)((0, utils_1.stringToRed)('a b c'), 9, 'justify')).to.equal((0, utils_1.stringToRed)('a b c'));
113
+ (0, chai_1.expect)((0, alignString_1.alignString)((0, utils_1.stringToRed)('a b c'), 10, 'justify')).to.equal((0, utils_1.stringToRed)('a b c'));
114
+ (0, chai_1.expect)((0, alignString_1.alignString)((0, utils_1.stringToRed)('a bbb cc d'), 11, 'justify')).to.equal((0, utils_1.stringToRed)('a bbb cc d'));
115
+ (0, chai_1.expect)((0, alignString_1.alignString)((0, utils_1.stringToRed)('a bbb cc d'), 12, 'justify')).to.equal((0, utils_1.stringToRed)('a bbb cc d'));
116
+ (0, chai_1.expect)((0, alignString_1.alignString)((0, utils_1.stringToRed)('a bbb cc d'), 13, 'justify')).to.equal((0, utils_1.stringToRed)('a bbb cc d'));
117
+ (0, chai_1.expect)((0, alignString_1.alignString)((0, utils_1.stringToRed)('a bbb cc d'), 14, 'justify')).to.equal((0, utils_1.stringToRed)('a bbb cc d'));
118
+ });
119
+ });
120
+ });
121
+ });
122
+ });
123
+ });
124
+ //# sourceMappingURL=alignString.js.map
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ /* eslint-disable max-nested-callbacks */
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const chai_1 = require("chai");
8
+ const chalk_1 = __importDefault(require("chalk"));
9
+ const alignTableData_1 = require("../src/alignTableData");
10
+ const makeTableConfig_1 = require("../src/makeTableConfig");
11
+ describe('alignTableData', () => {
12
+ context('when the string width is equal to column width config', () => {
13
+ it('returns the unchange string', () => {
14
+ const rows = [['aaa'], [chalk_1.default.red('bbb')]];
15
+ (0, chai_1.expect)((0, alignTableData_1.alignTableData)(rows, (0, makeTableConfig_1.makeTableConfig)(rows, {
16
+ columns: {
17
+ 0: {
18
+ width: 3,
19
+ },
20
+ },
21
+ }))).to.deep.equal(rows);
22
+ });
23
+ });
24
+ context('when the string is different from the column width config', () => {
25
+ it('aligns cells with column width and alignment config', () => {
26
+ const rows = [['a', 'b', 'c'],
27
+ [chalk_1.default.red('a'), chalk_1.default.red('b'), chalk_1.default.red('c')]];
28
+ (0, chai_1.expect)((0, alignTableData_1.alignTableData)(rows, (0, makeTableConfig_1.makeTableConfig)(rows, {
29
+ columnDefault: {
30
+ width: 3,
31
+ },
32
+ columns: {
33
+ 0: {
34
+ alignment: 'left',
35
+ },
36
+ 1: {
37
+ alignment: 'right',
38
+ },
39
+ 2: {
40
+ alignment: 'center',
41
+ },
42
+ },
43
+ }))).to.deep.equal([['a ', ' b', ' c '], [
44
+ chalk_1.default.red('a') + ' ', ' ' + chalk_1.default.red('b'), ' ' + chalk_1.default.red('c') + ' ',
45
+ ]]);
46
+ });
47
+ });
48
+ context('when the string is longer then column width', () => {
49
+ it('throws an error', () => {
50
+ const rows = [['aaaa']];
51
+ (0, chai_1.expect)(() => {
52
+ (0, alignTableData_1.alignTableData)(rows, (0, makeTableConfig_1.makeTableConfig)(rows, {
53
+ columns: {
54
+ 0: {
55
+ width: 3,
56
+ },
57
+ },
58
+ }));
59
+ }).to.throw(Error, 'Subject parameter value width cannot be greater than the container width.');
60
+ });
61
+ });
62
+ });
63
+ //# sourceMappingURL=alignTableData.js.map
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ /* eslint-disable max-nested-callbacks */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const chai_1 = require("chai");
5
+ const calculateCellHeight_1 = require("../src/calculateCellHeight");
6
+ describe('calculateCellHeight', () => {
7
+ describe('value', () => {
8
+ it('contains newlines', () => {
9
+ (0, chai_1.expect)((0, calculateCellHeight_1.calculateCellHeight)('a\nb\nc', 10)).to.equal(3);
10
+ });
11
+ it('contains newlines and will be wrapped', () => {
12
+ (0, chai_1.expect)((0, calculateCellHeight_1.calculateCellHeight)('aa\nbbb\nc', 2)).to.equal(4);
13
+ });
14
+ });
15
+ describe('context width', () => {
16
+ context('is lesser than the column width', () => {
17
+ it('has height 1', () => {
18
+ (0, chai_1.expect)((0, calculateCellHeight_1.calculateCellHeight)('foo', 10)).to.equal(1);
19
+ });
20
+ });
21
+ context('is 2 and half times greater than the column width', () => {
22
+ it('has height 3', () => {
23
+ (0, chai_1.expect)((0, calculateCellHeight_1.calculateCellHeight)('aabbc', 2)).to.equal(3);
24
+ });
25
+ });
26
+ });
27
+ });
28
+ //# sourceMappingURL=calculateCellHeight.js.map
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const chai_1 = require("chai");
4
+ const calculateCellWidths_1 = require("../src/calculateCellWidths");
5
+ describe('calculateCellWidths', () => {
6
+ context('all cells have different width', () => {
7
+ it('describes each cell contents width', () => {
8
+ const cellWidths = (0, calculateCellWidths_1.calculateCellWidths)([
9
+ 'a',
10
+ 'aaa',
11
+ 'aaaaaa',
12
+ ]);
13
+ (0, chai_1.expect)(cellWidths[0]).to.equal(1, 'first column');
14
+ (0, chai_1.expect)(cellWidths[1]).to.equal(3, 'second column');
15
+ (0, chai_1.expect)(cellWidths[2]).to.equal(6, 'third column');
16
+ });
17
+ });
18
+ context('cell contains newline characters', () => {
19
+ it('picks the longest line length', () => {
20
+ const cellWidths = (0, calculateCellWidths_1.calculateCellWidths)([
21
+ 'aaaa\naa',
22
+ ]);
23
+ (0, chai_1.expect)(cellWidths[0]).to.equal(4);
24
+ });
25
+ });
26
+ });
27
+ //# sourceMappingURL=calculateCellWidths.js.map
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,54 @@
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 chai_1 = require("chai");
7
+ const chalk_1 = __importDefault(require("chalk"));
8
+ const calculateColumnWidths_1 = __importDefault(require("../src/calculateColumnWidths"));
9
+ describe('calculateColumnWidths', () => {
10
+ it('calculates the maximum column value index', () => {
11
+ const columnWidths = (0, calculateColumnWidths_1.default)([
12
+ [
13
+ '',
14
+ 'a',
15
+ 'b',
16
+ 'c',
17
+ ],
18
+ [
19
+ '',
20
+ 'a',
21
+ 'bbbbbbbbbb',
22
+ 'c',
23
+ ],
24
+ [
25
+ '',
26
+ '',
27
+ 'b',
28
+ 'ccccc',
29
+ ],
30
+ ]);
31
+ (0, chai_1.expect)(columnWidths).to.deep.equal([0, 1, 10, 5]);
32
+ });
33
+ context('cell values contain ANSI codes', () => {
34
+ it('uses visual width of the string', () => {
35
+ const columnWidths = (0, calculateColumnWidths_1.default)([
36
+ [
37
+ chalk_1.default.red('aaaaa'),
38
+ ],
39
+ ]);
40
+ (0, chai_1.expect)(columnWidths[0]).to.equal(5);
41
+ });
42
+ });
43
+ context('cell values contain fullwidth characters', () => {
44
+ it('uses visual width of the string', () => {
45
+ const columnWidths = (0, calculateColumnWidths_1.default)([
46
+ [
47
+ chalk_1.default.red('古'),
48
+ ],
49
+ ]);
50
+ (0, chai_1.expect)(columnWidths[0]).to.equal(2);
51
+ });
52
+ });
53
+ });
54
+ //# sourceMappingURL=calculateColumnWidths.js.map
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ /* eslint-disable max-nested-callbacks */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const chai_1 = require("chai");
5
+ const calculateRowHeights_1 = require("../src/calculateRowHeights");
6
+ const makeTableConfig_1 = require("../src/makeTableConfig");
7
+ describe('calculateRowHeights', () => {
8
+ context('single column', () => {
9
+ context('cell content width is lesser than column width', () => {
10
+ it('is equal to 1', () => {
11
+ const data = [['aaa']];
12
+ const config = (0, makeTableConfig_1.makeTableConfig)(data, {
13
+ columns: {
14
+ 0: {
15
+ width: 10,
16
+ wrapWord: false,
17
+ },
18
+ },
19
+ });
20
+ const rowHeights = (0, calculateRowHeights_1.calculateRowHeights)(data, config);
21
+ (0, chai_1.expect)(rowHeights[0]).to.equal(1);
22
+ });
23
+ });
24
+ context('cell content width is twice the size of the column width', () => {
25
+ it('is equal to 2', () => {
26
+ const data = [['aaabbb']];
27
+ const config = (0, makeTableConfig_1.makeTableConfig)(data, {
28
+ columns: {
29
+ 0: {
30
+ width: 3,
31
+ wrapWord: false,
32
+ },
33
+ },
34
+ });
35
+ const rowHeights = (0, calculateRowHeights_1.calculateRowHeights)(data, config);
36
+ (0, chai_1.expect)(rowHeights[0]).to.equal(2);
37
+ });
38
+ });
39
+ });
40
+ context('multiple columns', () => {
41
+ context('multiple cell content width is greater than the column width', () => {
42
+ it('uses the largest height', () => {
43
+ const data = [
44
+ ['aaabbb'],
45
+ ['aaabbb'],
46
+ ];
47
+ const config = (0, makeTableConfig_1.makeTableConfig)(data, {
48
+ columns: {
49
+ 0: {
50
+ width: 2,
51
+ wrapWord: false,
52
+ },
53
+ },
54
+ });
55
+ const rowHeights = (0, calculateRowHeights_1.calculateRowHeights)(data, config);
56
+ (0, chai_1.expect)(rowHeights[0]).to.equal(3);
57
+ });
58
+ });
59
+ });
60
+ });
61
+ //# sourceMappingURL=calculateRowHeights.js.map
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,122 @@
1
+ "use strict";
2
+ /* eslint-disable max-nested-callbacks */
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
6
+ }) : (function(o, m, k, k2) {
7
+ if (k2 === undefined) k2 = k;
8
+ o[k2] = m[k];
9
+ }));
10
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
11
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
12
+ }) : function(o, v) {
13
+ o["default"] = v;
14
+ });
15
+ var __importStar = (this && this.__importStar) || function (mod) {
16
+ if (mod && mod.__esModule) return mod;
17
+ var result = {};
18
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
19
+ __setModuleDefault(result, mod);
20
+ return result;
21
+ };
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ const chai_1 = require("chai");
24
+ // eslint-disable-next-line import/no-namespace
25
+ const Sinon = __importStar(require("sinon"));
26
+ const src_1 = require("../src");
27
+ describe('createStream', () => {
28
+ context('"config.columnDefault.width" property is not provided', () => {
29
+ it('throws an error', () => {
30
+ (0, chai_1.expect)(() => {
31
+ (0, src_1.createStream)({
32
+ columnCount: 1,
33
+ columnDefault: {},
34
+ });
35
+ }).to.throw(Error, 'Must provide config.columnDefault.width when creating a stream.');
36
+ });
37
+ });
38
+ context('Table data cell count does not match the columnCount.', () => {
39
+ it('throws an error', () => {
40
+ (0, chai_1.expect)(() => {
41
+ const stream = (0, src_1.createStream)({
42
+ columnCount: 10,
43
+ columnDefault: {
44
+ width: 10,
45
+ },
46
+ });
47
+ stream.write(['foo']);
48
+ }).to.throw(Error, 'Row cell count does not match the config.columnCount.');
49
+ });
50
+ });
51
+ context('normal stream', () => {
52
+ let stub;
53
+ beforeEach(() => {
54
+ stub = Sinon.stub(process.stdout, 'write');
55
+ });
56
+ afterEach(() => {
57
+ stub.restore();
58
+ stub.resetHistory();
59
+ });
60
+ it('process.stdout.write calls twice with proper arguments', () => {
61
+ const stream = (0, src_1.createStream)({
62
+ border: (0, src_1.getBorderCharacters)('ramac'),
63
+ columnCount: 3,
64
+ columnDefault: {
65
+ width: 2,
66
+ },
67
+ columns: {
68
+ 0: {
69
+ alignment: 'right',
70
+ paddingLeft: 3,
71
+ },
72
+ 1: {
73
+ alignment: 'center',
74
+ paddingRight: 2,
75
+ },
76
+ 2: {
77
+ alignment: 'left',
78
+ width: 5,
79
+ },
80
+ },
81
+ });
82
+ stream.write(['a b', 'ccc', 'd']);
83
+ stream.write(['e', 'f', 'g']);
84
+ Sinon.assert.callCount(stub, 2);
85
+ Sinon.assert.calledWithExactly(stub.getCall(0), '+------+-----+-------+\n| a | cc | d |\n| b | c | |\n+------+-----+-------+');
86
+ Sinon.assert.calledWithExactly(stub.getCall(1), '\r\u001b[K|------|-----|-------|\n| e | f | g |\n+------+-----+-------+');
87
+ });
88
+ context('given custom drawVerticalLine', () => {
89
+ it('use the callback to draw vertical lines', () => {
90
+ const stream = (0, src_1.createStream)({
91
+ columnCount: 2,
92
+ columnDefault: {
93
+ width: 2,
94
+ },
95
+ drawVerticalLine: (index) => {
96
+ return index === 1;
97
+ },
98
+ });
99
+ stream.write(['a', 'b']);
100
+ Sinon.assert.callCount(stub, 1);
101
+ Sinon.assert.calledOnceWithExactly(stub, '════╤════\n a │ b \n════╧════');
102
+ });
103
+ });
104
+ context('append empty row', () => {
105
+ it('does not add a new line', () => {
106
+ const stream = (0, src_1.createStream)({
107
+ border: (0, src_1.getBorderCharacters)('void'),
108
+ columnCount: 1,
109
+ columnDefault: {
110
+ width: 2,
111
+ },
112
+ });
113
+ stream.write(['a']);
114
+ stream.write(['']);
115
+ stream.write(['a']);
116
+ Sinon.assert.calledWithExactly(stub.getCall(1), '');
117
+ Sinon.assert.calledWithExactly(stub.getCall(2), '\n a');
118
+ });
119
+ });
120
+ });
121
+ });
122
+ //# sourceMappingURL=createStream.js.map
@@ -0,0 +1 @@
1
+ export {};