table 6.0.6 → 6.1.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 (68) hide show
  1. package/README.md +52 -1
  2. package/dist/alignString.js +6 -7
  3. package/dist/alignString.js.flow +5 -4
  4. package/dist/alignTableData.js +1 -2
  5. package/dist/calculateCellHeight.js +3 -4
  6. package/dist/calculateCellHeight.js.flow +2 -2
  7. package/dist/calculateCellWidthIndex.js +1 -2
  8. package/dist/calculateMaximumColumnWidthIndex.js +1 -2
  9. package/dist/calculateRowHeightIndex.js +6 -9
  10. package/dist/calculateRowHeightIndex.js.flow +5 -4
  11. package/dist/createStream.js +13 -16
  12. package/dist/createStream.js.flow +12 -13
  13. package/dist/drawBorder.js +58 -53
  14. package/dist/drawBorder.js.flow +43 -55
  15. package/dist/drawHorizontalContent.js +41 -0
  16. package/dist/drawHorizontalContent.js.flow +31 -0
  17. package/dist/drawRow.js +21 -6
  18. package/dist/drawRow.js.flow +18 -4
  19. package/dist/drawTable.js +12 -11
  20. package/dist/drawTable.js.flow +24 -13
  21. package/dist/getBorderCharacters.js +1 -2
  22. package/dist/index.js +1 -2
  23. package/dist/makeConfig.js +19 -13
  24. package/dist/makeConfig.js.flow +16 -7
  25. package/dist/makeStreamConfig.js +17 -11
  26. package/dist/makeStreamConfig.js.flow +14 -5
  27. package/dist/mapDataUsingRowHeightIndex.js +4 -7
  28. package/dist/mapDataUsingRowHeightIndex.js.flow +3 -3
  29. package/dist/padTableData.js +1 -2
  30. package/dist/schemas/config.json +6 -0
  31. package/dist/schemas/streamConfig.json +3 -0
  32. package/dist/stringifyTableData.js +1 -2
  33. package/dist/table.js +14 -3
  34. package/dist/table.js.flow +13 -1
  35. package/dist/truncateTableData.js +3 -4
  36. package/dist/truncateTableData.js.flow +2 -2
  37. package/dist/validateConfig.js +1 -4
  38. package/dist/validateConfig.js.flow +0 -1
  39. package/dist/validateTableData.js +1 -2
  40. package/dist/validators.js +247 -186
  41. package/dist/wrapCell.js +1 -2
  42. package/dist/wrapString.js +1 -2
  43. package/dist/wrapWord.js +1 -2
  44. package/package.json +14 -8
  45. package/dist/alignString.js.map +0 -1
  46. package/dist/alignTableData.js.map +0 -1
  47. package/dist/calculateCellHeight.js.map +0 -1
  48. package/dist/calculateCellWidthIndex.js.map +0 -1
  49. package/dist/calculateMaximumColumnWidthIndex.js.map +0 -1
  50. package/dist/calculateRowHeightIndex.js.map +0 -1
  51. package/dist/createStream.js.map +0 -1
  52. package/dist/drawBorder.js.map +0 -1
  53. package/dist/drawRow.js.map +0 -1
  54. package/dist/drawTable.js.map +0 -1
  55. package/dist/getBorderCharacters.js.map +0 -1
  56. package/dist/index.js.map +0 -1
  57. package/dist/makeConfig.js.map +0 -1
  58. package/dist/makeStreamConfig.js.map +0 -1
  59. package/dist/mapDataUsingRowHeightIndex.js.map +0 -1
  60. package/dist/padTableData.js.map +0 -1
  61. package/dist/stringifyTableData.js.map +0 -1
  62. package/dist/table.js.map +0 -1
  63. package/dist/truncateTableData.js.map +0 -1
  64. package/dist/validateConfig.js.map +0 -1
  65. package/dist/validateTableData.js.map +0 -1
  66. package/dist/wrapCell.js.map +0 -1
  67. package/dist/wrapString.js.map +0 -1
  68. package/dist/wrapWord.js.map +0 -1
@@ -5,9 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
 
8
- var _flatten2 = _interopRequireDefault(require("lodash/flatten"));
9
-
10
- var _times2 = _interopRequireDefault(require("lodash/times"));
8
+ var _lodash = _interopRequireDefault(require("lodash.flatten"));
11
9
 
12
10
  var _wrapCell = _interopRequireDefault(require("./wrapCell"));
13
11
 
@@ -22,7 +20,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
22
20
  const mapDataUsingRowHeightIndex = (unmappedRows, rowHeightIndex, config) => {
23
21
  const tableWidth = unmappedRows[0].length;
24
22
  const mappedRows = unmappedRows.map((cells, index0) => {
25
- const rowHeight = (0, _times2.default)(rowHeightIndex[index0], () => {
23
+ const rowHeight = Array.from(new Array(rowHeightIndex[index0]), () => {
26
24
  return new Array(tableWidth).fill('');
27
25
  }); // rowHeight
28
26
  // [{row index within rowSaw; index2}]
@@ -36,9 +34,8 @@ const mapDataUsingRowHeightIndex = (unmappedRows, rowHeightIndex, config) => {
36
34
  });
37
35
  return rowHeight;
38
36
  });
39
- return (0, _flatten2.default)(mappedRows);
37
+ return (0, _lodash.default)(mappedRows);
40
38
  };
41
39
 
42
40
  var _default = mapDataUsingRowHeightIndex;
43
- exports.default = _default;
44
- //# sourceMappingURL=mapDataUsingRowHeightIndex.js.map
41
+ exports.default = _default;
@@ -1,4 +1,4 @@
1
- import _ from 'lodash';
1
+ import flatten from 'lodash.flatten';
2
2
  import wrapCell from './wrapCell';
3
3
 
4
4
  /**
@@ -11,7 +11,7 @@ export default (unmappedRows, rowHeightIndex, config) => {
11
11
  const tableWidth = unmappedRows[0].length;
12
12
 
13
13
  const mappedRows = unmappedRows.map((cells, index0) => {
14
- const rowHeight = _.times(rowHeightIndex[index0], () => {
14
+ const rowHeight = Array.from(new Array(rowHeightIndex[index0]), () => {
15
15
  return new Array(tableWidth).fill('');
16
16
  });
17
17
 
@@ -30,5 +30,5 @@ export default (unmappedRows, rowHeightIndex, config) => {
30
30
  return rowHeight;
31
31
  });
32
32
 
33
- return _.flatten(mappedRows);
33
+ return flatten(mappedRows);
34
34
  };
@@ -20,5 +20,4 @@ const padTableData = (rows, config) => {
20
20
  };
21
21
 
22
22
  var _default = padTableData;
23
- exports.default = _default;
24
- //# sourceMappingURL=padTableData.js.map
23
+ exports.default = _default;
@@ -12,8 +12,14 @@
12
12
  "columnDefault": {
13
13
  "$ref": "shared.json#/definitions/column"
14
14
  },
15
+ "drawVerticalLine": {
16
+ "typeof": "function"
17
+ },
15
18
  "drawHorizontalLine": {
16
19
  "typeof": "function"
20
+ },
21
+ "singleLine": {
22
+ "typeof": "boolean"
17
23
  }
18
24
  },
19
25
  "additionalProperties": false
@@ -14,6 +14,9 @@
14
14
  },
15
15
  "columnCount": {
16
16
  "type": "number"
17
+ },
18
+ "drawVerticalLine": {
19
+ "typeof": "function"
17
20
  }
18
21
  },
19
22
  "additionalProperties": false
@@ -18,5 +18,4 @@ const stringifyTableData = rows => {
18
18
  };
19
19
 
20
20
  var _default = stringifyTableData;
21
- exports.default = _default;
22
- //# sourceMappingURL=stringifyTableData.js.map
21
+ exports.default = _default;
package/dist/table.js CHANGED
@@ -64,6 +64,17 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
64
64
  * @property {string} joinJoin
65
65
  */
66
66
 
67
+ /**
68
+ * Used to tell whether to draw a vertical line.
69
+ * This callback is called for each non-content line of the table.
70
+ * The default behavior is to always return true.
71
+ *
72
+ * @typedef {Function} drawVerticalLine
73
+ * @param {number} index
74
+ * @param {number} size
75
+ * @returns {boolean}
76
+ */
77
+
67
78
  /**
68
79
  * Used to tell whether to draw a horizontal line.
69
80
  * This callback is called for each non-content line of the table.
@@ -80,6 +91,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
80
91
  * @property {table~border} border
81
92
  * @property {table~columns[]} columns Column specific configuration.
82
93
  * @property {table~columns} columnDefault Default values for all columns. Column specific settings overwrite the default values.
94
+ * @property {table~drawVerticalLine} drawVerticalLine
83
95
  * @property {table~drawHorizontalLine} drawHorizontalLine
84
96
  * @property {table~singleLine} singleLine Horizontal lines inside the table are not drawn.
85
97
  */
@@ -102,9 +114,8 @@ const table = (data, userConfig = {}) => {
102
114
  rows = (0, _alignTableData.default)(rows, config);
103
115
  rows = (0, _padTableData.default)(rows, config);
104
116
  const cellWidthIndex = (0, _calculateCellWidthIndex.default)(rows[0]);
105
- return (0, _drawTable.default)(rows, config.border, cellWidthIndex, rowHeightIndex, config.drawHorizontalLine, config.singleLine);
117
+ return (0, _drawTable.default)(rows, cellWidthIndex, rowHeightIndex, config);
106
118
  };
107
119
 
108
120
  var _default = table;
109
- exports.default = _default;
110
- //# sourceMappingURL=table.js.map
121
+ exports.default = _default;
@@ -46,6 +46,17 @@ import validateTableData from './validateTableData';
46
46
  * @property {string} joinJoin
47
47
  */
48
48
 
49
+ /**
50
+ * Used to tell whether to draw a vertical line.
51
+ * This callback is called for each non-content line of the table.
52
+ * The default behavior is to always return true.
53
+ *
54
+ * @typedef {Function} drawVerticalLine
55
+ * @param {number} index
56
+ * @param {number} size
57
+ * @returns {boolean}
58
+ */
59
+
49
60
  /**
50
61
  * Used to tell whether to draw a horizontal line.
51
62
  * This callback is called for each non-content line of the table.
@@ -62,6 +73,7 @@ import validateTableData from './validateTableData';
62
73
  * @property {table~border} border
63
74
  * @property {table~columns[]} columns Column specific configuration.
64
75
  * @property {table~columns} columnDefault Default values for all columns. Column specific settings overwrite the default values.
76
+ * @property {table~drawVerticalLine} drawVerticalLine
65
77
  * @property {table~drawHorizontalLine} drawHorizontalLine
66
78
  * @property {table~singleLine} singleLine Horizontal lines inside the table are not drawn.
67
79
  */
@@ -92,5 +104,5 @@ export default (data, userConfig = {}) => {
92
104
 
93
105
  const cellWidthIndex = calculateCellWidthIndex(rows[0]);
94
106
 
95
- return drawTable(rows, config.border, cellWidthIndex, rowHeightIndex, config.drawHorizontalLine, config.singleLine);
107
+ return drawTable(rows, cellWidthIndex, rowHeightIndex, config);
96
108
  };
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
 
8
- var _truncate2 = _interopRequireDefault(require("lodash/truncate"));
8
+ var _lodash = _interopRequireDefault(require("lodash.truncate"));
9
9
 
10
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
11
 
@@ -18,7 +18,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
18
18
  const truncateTableData = (rows, config) => {
19
19
  return rows.map(cells => {
20
20
  return cells.map((content, index) => {
21
- return (0, _truncate2.default)(content, {
21
+ return (0, _lodash.default)(content, {
22
22
  length: config.columns[index].truncate
23
23
  });
24
24
  });
@@ -26,5 +26,4 @@ const truncateTableData = (rows, config) => {
26
26
  };
27
27
 
28
28
  var _default = truncateTableData;
29
- exports.default = _default;
30
- //# sourceMappingURL=truncateTableData.js.map
29
+ exports.default = _default;
@@ -1,4 +1,4 @@
1
- import _ from 'lodash';
1
+ import truncate from 'lodash.truncate';
2
2
 
3
3
  /**
4
4
  * @todo Make it work with ASCII content.
@@ -9,7 +9,7 @@ import _ from 'lodash';
9
9
  export default (rows, config) => {
10
10
  return rows.map((cells) => {
11
11
  return cells.map((content, index) => {
12
- return _.truncate(content, {
12
+ return truncate(content, {
13
13
  length: config.columns[index].truncate,
14
14
  });
15
15
  });
@@ -9,8 +9,6 @@ var _validators = _interopRequireDefault(require("../dist/validators"));
9
9
 
10
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
11
 
12
- // eslint-disable-next-line import/default
13
-
14
12
  /**
15
13
  * @param {string} schemaId
16
14
  * @param {formatData~config} config
@@ -39,5 +37,4 @@ const validateConfig = (schemaId, config = {}) => {
39
37
  };
40
38
 
41
39
  var _default = validateConfig;
42
- exports.default = _default;
43
- //# sourceMappingURL=validateConfig.js.map
40
+ exports.default = _default;
@@ -1,4 +1,3 @@
1
- // eslint-disable-next-line import/default
2
1
  import validators from '../dist/validators';
3
2
 
4
3
  /**
@@ -51,5 +51,4 @@ const validateTableData = rows => {
51
51
  };
52
52
 
53
53
  var _default = validateTableData;
54
- exports.default = _default;
55
- //# sourceMappingURL=validateTableData.js.map
54
+ exports.default = _default;