table 6.2.0 → 6.3.0

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 (84) hide show
  1. package/README.md +1 -1
  2. package/dist/src/alignString.js +64 -0
  3. package/dist/src/alignTableData.js +21 -0
  4. package/dist/src/calculateCellHeight.js +17 -0
  5. package/dist/src/calculateCellWidthIndex.js +17 -0
  6. package/dist/src/calculateMaximumColumnWidthIndex.js +25 -0
  7. package/dist/src/calculateRowHeightIndex.js +30 -0
  8. package/dist/src/createStream.js +74 -0
  9. package/dist/src/drawBorder.js +55 -0
  10. package/dist/src/drawHorizontalContent.js +19 -0
  11. package/dist/src/drawRow.js +17 -0
  12. package/dist/src/drawTable.js +38 -0
  13. package/dist/src/getBorderCharacters.js +83 -0
  14. package/dist/{index.js.flow → src/index.d.ts} +2 -6
  15. package/dist/src/index.js +24 -0
  16. package/dist/src/makeConfig.js +59 -0
  17. package/dist/src/makeStreamConfig.js +60 -0
  18. package/dist/src/mapDataUsingRowHeightIndex.js +27 -0
  19. package/dist/src/padTableData.js +11 -0
  20. package/dist/src/stringifyTableData.js +8 -0
  21. package/dist/src/table.js +28 -0
  22. package/dist/src/truncateTableData.js +20 -0
  23. package/dist/src/types/api.d.ts +99 -0
  24. package/dist/src/types/api.js +3 -0
  25. package/dist/src/types/internal.js +3 -0
  26. package/dist/src/validateConfig.js +27 -0
  27. package/dist/src/validateTableData.js +29 -0
  28. package/dist/{validators.js → src/validators.js} +0 -0
  29. package/dist/src/wrapCell.js +33 -0
  30. package/dist/src/wrapString.js +25 -0
  31. package/dist/src/wrapWord.js +29 -0
  32. package/package.json +33 -25
  33. package/dist/alignString.js +0 -107
  34. package/dist/alignString.js.flow +0 -97
  35. package/dist/alignTableData.js +0 -34
  36. package/dist/alignTableData.js.flow +0 -21
  37. package/dist/calculateCellHeight.js +0 -37
  38. package/dist/calculateCellHeight.js.flow +0 -24
  39. package/dist/calculateCellWidthIndex.js +0 -27
  40. package/dist/calculateCellWidthIndex.js.flow +0 -17
  41. package/dist/calculateMaximumColumnWidthIndex.js +0 -36
  42. package/dist/calculateMaximumColumnWidthIndex.js.flow +0 -27
  43. package/dist/calculateRowHeightIndex.js +0 -45
  44. package/dist/calculateRowHeightIndex.js.flow +0 -36
  45. package/dist/createStream.js +0 -124
  46. package/dist/createStream.js.flow +0 -125
  47. package/dist/drawBorder.js +0 -115
  48. package/dist/drawBorder.js.flow +0 -89
  49. package/dist/drawHorizontalContent.js +0 -41
  50. package/dist/drawHorizontalContent.js.flow +0 -31
  51. package/dist/drawRow.js +0 -41
  52. package/dist/drawRow.js.flow +0 -29
  53. package/dist/drawTable.js +0 -60
  54. package/dist/drawTable.js.flow +0 -64
  55. package/dist/getBorderCharacters.js +0 -118
  56. package/dist/getBorderCharacters.js.flow +0 -120
  57. package/dist/index.js +0 -31
  58. package/dist/makeConfig.js +0 -100
  59. package/dist/makeConfig.js.flow +0 -85
  60. package/dist/makeStreamConfig.js +0 -107
  61. package/dist/makeStreamConfig.js.flow +0 -92
  62. package/dist/mapDataUsingRowHeightIndex.js +0 -41
  63. package/dist/mapDataUsingRowHeightIndex.js.flow +0 -34
  64. package/dist/padTableData.js +0 -23
  65. package/dist/padTableData.js.flow +0 -14
  66. package/dist/schemas/config.json +0 -26
  67. package/dist/schemas/shared.json +0 -98
  68. package/dist/schemas/streamConfig.json +0 -23
  69. package/dist/stringifyTableData.js +0 -21
  70. package/dist/stringifyTableData.js.flow +0 -11
  71. package/dist/table.js +0 -121
  72. package/dist/table.js.flow +0 -108
  73. package/dist/truncateTableData.js +0 -30
  74. package/dist/truncateTableData.js.flow +0 -18
  75. package/dist/validateConfig.js +0 -40
  76. package/dist/validateConfig.js.flow +0 -27
  77. package/dist/validateTableData.js +0 -54
  78. package/dist/validateTableData.js.flow +0 -44
  79. package/dist/wrapCell.js +0 -47
  80. package/dist/wrapCell.js.flow +0 -35
  81. package/dist/wrapString.js +0 -39
  82. package/dist/wrapString.js.flow +0 -29
  83. package/dist/wrapWord.js +0 -46
  84. package/dist/wrapWord.js.flow +0 -39
@@ -1,89 +0,0 @@
1
- import drawHorizontalContent from './drawHorizontalContent';
2
-
3
- /**
4
- * @typedef drawBorder~border
5
- * @property {string} left
6
- * @property {string} right
7
- * @property {string} body
8
- * @property {string} join
9
- */
10
-
11
- /**
12
- * @param {number[]} columnSizeIndex
13
- * @param {object} config
14
- * @param {drawBorder~border} config.border
15
- * @param {Function} config.drawVerticalLine
16
- * @returns {string}
17
- */
18
- const drawBorder = (columnSizeIndex, {border, drawVerticalLine}) => {
19
- const columns = columnSizeIndex.map((size) => {
20
- return border.body.repeat(size);
21
- });
22
-
23
- return drawHorizontalContent(columns, {
24
- drawVerticalLine,
25
- separator: border,
26
- });
27
- };
28
-
29
- /**
30
- * @param {number[]} columnSizeIndex
31
- * @param {table~config} config
32
- * @returns {string}
33
- */
34
- const drawBorderTop = (columnSizeIndex, {border, drawVerticalLine}) => {
35
- const result = drawBorder(columnSizeIndex, {border: {
36
- body: border.topBody,
37
- join: border.topJoin,
38
- left: border.topLeft,
39
- right: border.topRight,
40
- },
41
- drawVerticalLine});
42
-
43
- if (result === '\n') {
44
- return '';
45
- }
46
-
47
- return result;
48
- };
49
-
50
- /**
51
- * @param {number[]} columnSizeIndex
52
- * @param {table~config} config
53
- * @returns {string}
54
- */
55
- const drawBorderJoin = (columnSizeIndex, {border, drawVerticalLine}) => {
56
- return drawBorder(columnSizeIndex, {
57
- border: {
58
- body: border.joinBody,
59
- join: border.joinJoin,
60
- left: border.joinLeft,
61
- right: border.joinRight,
62
- },
63
- drawVerticalLine,
64
- });
65
- };
66
-
67
- /**
68
- * @param {number[]} columnSizeIndex
69
- * @param {table~config} config
70
- * @returns {string}
71
- */
72
- const drawBorderBottom = (columnSizeIndex, {border, drawVerticalLine}) => {
73
- return drawBorder(columnSizeIndex, {
74
- border: {
75
- body: border.bottomBody,
76
- join: border.bottomJoin,
77
- left: border.bottomLeft,
78
- right: border.bottomRight,
79
- },
80
- drawVerticalLine,
81
- });
82
- };
83
-
84
- export {
85
- drawBorder,
86
- drawBorderBottom,
87
- drawBorderJoin,
88
- drawBorderTop,
89
- };
@@ -1,41 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- /**
9
- * @typedef {object} drawHorizontalContent~separator
10
- * @property {string} left
11
- * @property {string} right
12
- * @property {string} join
13
- */
14
-
15
- /**
16
- * @param {string[]} columns
17
- * @param {object} config
18
- * @param {drawHorizontalContent~separator} config.separator
19
- * @param {Function} config.drawVerticalLine
20
- * @returns {string}
21
- */
22
- const drawHorizontalContent = (columns, {
23
- separator,
24
- drawVerticalLine
25
- }) => {
26
- const columnCount = columns.length;
27
- const result = [];
28
- result.push(drawVerticalLine(0, columnCount) ? separator.left : '');
29
- columns.forEach((column, index) => {
30
- result.push(column);
31
-
32
- if (index + 1 < columnCount) {
33
- result.push(drawVerticalLine(index + 1, columnCount) ? separator.join : '');
34
- }
35
- });
36
- result.push(drawVerticalLine(columnCount, columnCount) ? separator.right : '');
37
- return result.join('') + '\n';
38
- };
39
-
40
- var _default = drawHorizontalContent;
41
- exports.default = _default;
@@ -1,31 +0,0 @@
1
- /**
2
- * @typedef {object} drawHorizontalContent~separator
3
- * @property {string} left
4
- * @property {string} right
5
- * @property {string} join
6
- */
7
-
8
- /**
9
- * @param {string[]} columns
10
- * @param {object} config
11
- * @param {drawHorizontalContent~separator} config.separator
12
- * @param {Function} config.drawVerticalLine
13
- * @returns {string}
14
- */
15
- export default (columns, {separator, drawVerticalLine}) => {
16
- const columnCount = columns.length;
17
- const result = [];
18
-
19
- result.push(drawVerticalLine(0, columnCount) ? separator.left : '');
20
-
21
- columns.forEach((column, index) => {
22
- result.push(column);
23
-
24
- if (index + 1 < columnCount) {
25
- result.push(drawVerticalLine(index + 1, columnCount) ? separator.join : '');
26
- }
27
- });
28
- result.push(drawVerticalLine(columnCount, columnCount) ? separator.right : '');
29
-
30
- return result.join('') + '\n';
31
- };
package/dist/drawRow.js DELETED
@@ -1,41 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _drawHorizontalContent = _interopRequireDefault(require("./drawHorizontalContent"));
9
-
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
12
- /**
13
- * @typedef {object} drawRow~border
14
- * @property {string} bodyLeft
15
- * @property {string} bodyRight
16
- * @property {string} bodyJoin
17
- */
18
-
19
- /**
20
- * @param {string[]} columns
21
- * @param {object} config
22
- * @param {border} config.border
23
- * @param {Function} config.drawVerticalLine
24
- * @returns {string}
25
- */
26
- const drawRow = (columns, {
27
- border,
28
- drawVerticalLine
29
- }) => {
30
- return (0, _drawHorizontalContent.default)(columns, {
31
- drawVerticalLine,
32
- separator: {
33
- join: border.bodyJoin,
34
- left: border.bodyLeft,
35
- right: border.bodyRight
36
- }
37
- });
38
- };
39
-
40
- var _default = drawRow;
41
- exports.default = _default;
@@ -1,29 +0,0 @@
1
- import drawHorizontalContent from './drawHorizontalContent';
2
-
3
- /**
4
- * @typedef {object} drawRow~border
5
- * @property {string} bodyLeft
6
- * @property {string} bodyRight
7
- * @property {string} bodyJoin
8
- */
9
-
10
- /**
11
- * @param {string[]} columns
12
- * @param {object} config
13
- * @param {border} config.border
14
- * @param {Function} config.drawVerticalLine
15
- * @returns {string}
16
- */
17
- export default (columns, {
18
- border,
19
- drawVerticalLine,
20
- }) => {
21
- return drawHorizontalContent(columns, {
22
- drawVerticalLine,
23
- separator: {
24
- join: border.bodyJoin,
25
- left: border.bodyLeft,
26
- right: border.bodyRight,
27
- },
28
- });
29
- };
package/dist/drawTable.js DELETED
@@ -1,60 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _drawBorder = require("./drawBorder");
9
-
10
- var _drawRow = _interopRequireDefault(require("./drawRow"));
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
- /**
15
- * @param {string[][]} rows
16
- * @param {Array} columnSizeIndex
17
- * @param {Array} rowSpanIndex
18
- * @param {table~config} config
19
- * @returns {string}
20
- */
21
- const drawTable = (rows, columnSizeIndex, rowSpanIndex, config) => {
22
- const {
23
- drawHorizontalLine,
24
- singleLine
25
- } = config;
26
- let output;
27
- let realRowIndex;
28
- let rowHeight;
29
- const rowCount = rows.length;
30
- realRowIndex = 0;
31
- output = '';
32
-
33
- if (drawHorizontalLine(realRowIndex, rowCount)) {
34
- output += (0, _drawBorder.drawBorderTop)(columnSizeIndex, config);
35
- }
36
-
37
- rows.forEach((row, index0) => {
38
- output += (0, _drawRow.default)(row, config);
39
-
40
- if (!rowHeight) {
41
- rowHeight = rowSpanIndex[realRowIndex];
42
- realRowIndex++;
43
- }
44
-
45
- rowHeight--;
46
-
47
- if (!singleLine && rowHeight === 0 && index0 !== rowCount - 1 && drawHorizontalLine(realRowIndex, rowCount)) {
48
- output += (0, _drawBorder.drawBorderJoin)(columnSizeIndex, config);
49
- }
50
- });
51
-
52
- if (drawHorizontalLine(realRowIndex, rowCount)) {
53
- output += (0, _drawBorder.drawBorderBottom)(columnSizeIndex, config);
54
- }
55
-
56
- return output;
57
- };
58
-
59
- var _default = drawTable;
60
- exports.default = _default;
@@ -1,64 +0,0 @@
1
- import {
2
- drawBorderTop, drawBorderJoin, drawBorderBottom,
3
- } from './drawBorder';
4
- import drawRow from './drawRow';
5
-
6
- /**
7
- * @param {string[][]} rows
8
- * @param {Array} columnSizeIndex
9
- * @param {Array} rowSpanIndex
10
- * @param {table~config} config
11
- * @returns {string}
12
- */
13
- export default (
14
- rows,
15
- columnSizeIndex,
16
- rowSpanIndex,
17
- config,
18
- ) => {
19
- const {
20
- drawHorizontalLine,
21
- singleLine,
22
- } = config;
23
-
24
- let output;
25
- let realRowIndex;
26
- let rowHeight;
27
-
28
- const rowCount = rows.length;
29
-
30
- realRowIndex = 0;
31
-
32
- output = '';
33
-
34
- if (drawHorizontalLine(realRowIndex, rowCount)) {
35
- output += drawBorderTop(columnSizeIndex, config);
36
- }
37
-
38
- rows.forEach((row, index0) => {
39
- output += drawRow(row, config);
40
-
41
- if (!rowHeight) {
42
- rowHeight = rowSpanIndex[realRowIndex];
43
-
44
- realRowIndex++;
45
- }
46
-
47
- rowHeight--;
48
-
49
- if (
50
- !singleLine &&
51
- rowHeight === 0 &&
52
- index0 !== rowCount - 1 &&
53
- drawHorizontalLine(realRowIndex, rowCount)
54
- ) {
55
- output += drawBorderJoin(columnSizeIndex, config);
56
- }
57
- });
58
-
59
- if (drawHorizontalLine(realRowIndex, rowCount)) {
60
- output += drawBorderBottom(columnSizeIndex, config);
61
- }
62
-
63
- return output;
64
- };
@@ -1,118 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- /* eslint-disable sort-keys-fix/sort-keys-fix */
9
-
10
- /**
11
- * @typedef border
12
- * @property {string} topBody
13
- * @property {string} topJoin
14
- * @property {string} topLeft
15
- * @property {string} topRight
16
- * @property {string} bottomBody
17
- * @property {string} bottomJoin
18
- * @property {string} bottomLeft
19
- * @property {string} bottomRight
20
- * @property {string} bodyLeft
21
- * @property {string} bodyRight
22
- * @property {string} bodyJoin
23
- * @property {string} joinBody
24
- * @property {string} joinLeft
25
- * @property {string} joinRight
26
- * @property {string} joinJoin
27
- */
28
-
29
- /**
30
- * @param {string} name
31
- * @returns {border}
32
- */
33
- const getBorderCharacters = name => {
34
- if (name === 'honeywell') {
35
- return {
36
- topBody: '═',
37
- topJoin: '╤',
38
- topLeft: '╔',
39
- topRight: '╗',
40
- bottomBody: '═',
41
- bottomJoin: '╧',
42
- bottomLeft: '╚',
43
- bottomRight: '╝',
44
- bodyLeft: '║',
45
- bodyRight: '║',
46
- bodyJoin: '│',
47
- joinBody: '─',
48
- joinLeft: '╟',
49
- joinRight: '╢',
50
- joinJoin: '┼'
51
- };
52
- }
53
-
54
- if (name === 'norc') {
55
- return {
56
- topBody: '─',
57
- topJoin: '┬',
58
- topLeft: '┌',
59
- topRight: '┐',
60
- bottomBody: '─',
61
- bottomJoin: '┴',
62
- bottomLeft: '└',
63
- bottomRight: '┘',
64
- bodyLeft: '│',
65
- bodyRight: '│',
66
- bodyJoin: '│',
67
- joinBody: '─',
68
- joinLeft: '├',
69
- joinRight: '┤',
70
- joinJoin: '┼'
71
- };
72
- }
73
-
74
- if (name === 'ramac') {
75
- return {
76
- topBody: '-',
77
- topJoin: '+',
78
- topLeft: '+',
79
- topRight: '+',
80
- bottomBody: '-',
81
- bottomJoin: '+',
82
- bottomLeft: '+',
83
- bottomRight: '+',
84
- bodyLeft: '|',
85
- bodyRight: '|',
86
- bodyJoin: '|',
87
- joinBody: '-',
88
- joinLeft: '|',
89
- joinRight: '|',
90
- joinJoin: '|'
91
- };
92
- }
93
-
94
- if (name === 'void') {
95
- return {
96
- topBody: '',
97
- topJoin: '',
98
- topLeft: '',
99
- topRight: '',
100
- bottomBody: '',
101
- bottomJoin: '',
102
- bottomLeft: '',
103
- bottomRight: '',
104
- bodyLeft: '',
105
- bodyRight: '',
106
- bodyJoin: '',
107
- joinBody: '',
108
- joinLeft: '',
109
- joinRight: '',
110
- joinJoin: ''
111
- };
112
- }
113
-
114
- throw new Error('Unknown border template "' + name + '".');
115
- };
116
-
117
- var _default = getBorderCharacters;
118
- exports.default = _default;
@@ -1,120 +0,0 @@
1
- /* eslint-disable sort-keys-fix/sort-keys-fix */
2
-
3
- /**
4
- * @typedef border
5
- * @property {string} topBody
6
- * @property {string} topJoin
7
- * @property {string} topLeft
8
- * @property {string} topRight
9
- * @property {string} bottomBody
10
- * @property {string} bottomJoin
11
- * @property {string} bottomLeft
12
- * @property {string} bottomRight
13
- * @property {string} bodyLeft
14
- * @property {string} bodyRight
15
- * @property {string} bodyJoin
16
- * @property {string} joinBody
17
- * @property {string} joinLeft
18
- * @property {string} joinRight
19
- * @property {string} joinJoin
20
- */
21
-
22
- /**
23
- * @param {string} name
24
- * @returns {border}
25
- */
26
- export default (name) => {
27
- if (name === 'honeywell') {
28
- return {
29
- topBody: '═',
30
- topJoin: '╤',
31
- topLeft: '╔',
32
- topRight: '╗',
33
-
34
- bottomBody: '═',
35
- bottomJoin: '╧',
36
- bottomLeft: '╚',
37
- bottomRight: '╝',
38
-
39
- bodyLeft: '║',
40
- bodyRight: '║',
41
- bodyJoin: '│',
42
-
43
- joinBody: '─',
44
- joinLeft: '╟',
45
- joinRight: '╢',
46
- joinJoin: '┼',
47
- };
48
- }
49
-
50
- if (name === 'norc') {
51
- return {
52
- topBody: '─',
53
- topJoin: '┬',
54
- topLeft: '┌',
55
- topRight: '┐',
56
-
57
- bottomBody: '─',
58
- bottomJoin: '┴',
59
- bottomLeft: '└',
60
- bottomRight: '┘',
61
-
62
- bodyLeft: '│',
63
- bodyRight: '│',
64
- bodyJoin: '│',
65
-
66
- joinBody: '─',
67
- joinLeft: '├',
68
- joinRight: '┤',
69
- joinJoin: '┼',
70
- };
71
- }
72
-
73
- if (name === 'ramac') {
74
- return {
75
- topBody: '-',
76
- topJoin: '+',
77
- topLeft: '+',
78
- topRight: '+',
79
-
80
- bottomBody: '-',
81
- bottomJoin: '+',
82
- bottomLeft: '+',
83
- bottomRight: '+',
84
-
85
- bodyLeft: '|',
86
- bodyRight: '|',
87
- bodyJoin: '|',
88
-
89
- joinBody: '-',
90
- joinLeft: '|',
91
- joinRight: '|',
92
- joinJoin: '|',
93
- };
94
- }
95
-
96
- if (name === 'void') {
97
- return {
98
- topBody: '',
99
- topJoin: '',
100
- topLeft: '',
101
- topRight: '',
102
-
103
- bottomBody: '',
104
- bottomJoin: '',
105
- bottomLeft: '',
106
- bottomRight: '',
107
-
108
- bodyLeft: '',
109
- bodyRight: '',
110
- bodyJoin: '',
111
-
112
- joinBody: '',
113
- joinLeft: '',
114
- joinRight: '',
115
- joinJoin: '',
116
- };
117
- }
118
-
119
- throw new Error('Unknown border template "' + name + '".');
120
- };
package/dist/index.js DELETED
@@ -1,31 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, "createStream", {
7
- enumerable: true,
8
- get: function () {
9
- return _createStream.default;
10
- }
11
- });
12
- Object.defineProperty(exports, "getBorderCharacters", {
13
- enumerable: true,
14
- get: function () {
15
- return _getBorderCharacters.default;
16
- }
17
- });
18
- Object.defineProperty(exports, "table", {
19
- enumerable: true,
20
- get: function () {
21
- return _table.default;
22
- }
23
- });
24
-
25
- var _createStream = _interopRequireDefault(require("./createStream"));
26
-
27
- var _getBorderCharacters = _interopRequireDefault(require("./getBorderCharacters"));
28
-
29
- var _table = _interopRequireDefault(require("./table"));
30
-
31
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }