table 6.0.8 → 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 (106) hide show
  1. package/README.md +53 -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} +54 -14
  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 -26
  33. package/dist/alignString.js +0 -108
  34. package/dist/alignString.js.flow +0 -97
  35. package/dist/alignString.js.map +0 -1
  36. package/dist/alignTableData.js +0 -35
  37. package/dist/alignTableData.js.flow +0 -21
  38. package/dist/alignTableData.js.map +0 -1
  39. package/dist/calculateCellHeight.js +0 -38
  40. package/dist/calculateCellHeight.js.flow +0 -24
  41. package/dist/calculateCellHeight.js.map +0 -1
  42. package/dist/calculateCellWidthIndex.js +0 -28
  43. package/dist/calculateCellWidthIndex.js.flow +0 -17
  44. package/dist/calculateCellWidthIndex.js.map +0 -1
  45. package/dist/calculateMaximumColumnWidthIndex.js +0 -37
  46. package/dist/calculateMaximumColumnWidthIndex.js.flow +0 -27
  47. package/dist/calculateMaximumColumnWidthIndex.js.map +0 -1
  48. package/dist/calculateRowHeightIndex.js +0 -46
  49. package/dist/calculateRowHeightIndex.js.flow +0 -36
  50. package/dist/calculateRowHeightIndex.js.map +0 -1
  51. package/dist/createStream.js +0 -125
  52. package/dist/createStream.js.flow +0 -125
  53. package/dist/createStream.js.map +0 -1
  54. package/dist/drawBorder.js +0 -110
  55. package/dist/drawBorder.js.flow +0 -101
  56. package/dist/drawBorder.js.map +0 -1
  57. package/dist/drawRow.js +0 -26
  58. package/dist/drawRow.js.flow +0 -15
  59. package/dist/drawRow.js.map +0 -1
  60. package/dist/drawTable.js +0 -59
  61. package/dist/drawTable.js.flow +0 -53
  62. package/dist/drawTable.js.map +0 -1
  63. package/dist/getBorderCharacters.js +0 -119
  64. package/dist/getBorderCharacters.js.flow +0 -120
  65. package/dist/getBorderCharacters.js.map +0 -1
  66. package/dist/index.js +0 -32
  67. package/dist/index.js.map +0 -1
  68. package/dist/makeConfig.js +0 -92
  69. package/dist/makeConfig.js.flow +0 -76
  70. package/dist/makeConfig.js.map +0 -1
  71. package/dist/makeStreamConfig.js +0 -98
  72. package/dist/makeStreamConfig.js.flow +0 -83
  73. package/dist/makeStreamConfig.js.map +0 -1
  74. package/dist/mapDataUsingRowHeightIndex.js +0 -42
  75. package/dist/mapDataUsingRowHeightIndex.js.flow +0 -34
  76. package/dist/mapDataUsingRowHeightIndex.js.map +0 -1
  77. package/dist/padTableData.js +0 -24
  78. package/dist/padTableData.js.flow +0 -14
  79. package/dist/padTableData.js.map +0 -1
  80. package/dist/schemas/config.json +0 -23
  81. package/dist/schemas/shared.json +0 -98
  82. package/dist/schemas/streamConfig.json +0 -20
  83. package/dist/stringifyTableData.js +0 -22
  84. package/dist/stringifyTableData.js.flow +0 -11
  85. package/dist/stringifyTableData.js.map +0 -1
  86. package/dist/table.js +0 -110
  87. package/dist/table.js.flow +0 -96
  88. package/dist/table.js.map +0 -1
  89. package/dist/truncateTableData.js +0 -30
  90. package/dist/truncateTableData.js.flow +0 -17
  91. package/dist/truncateTableData.js.map +0 -1
  92. package/dist/validateConfig.js +0 -41
  93. package/dist/validateConfig.js.flow +0 -27
  94. package/dist/validateConfig.js.map +0 -1
  95. package/dist/validateTableData.js +0 -55
  96. package/dist/validateTableData.js.flow +0 -44
  97. package/dist/validateTableData.js.map +0 -1
  98. package/dist/wrapCell.js +0 -48
  99. package/dist/wrapCell.js.flow +0 -35
  100. package/dist/wrapCell.js.map +0 -1
  101. package/dist/wrapString.js +0 -40
  102. package/dist/wrapString.js.flow +0 -29
  103. package/dist/wrapString.js.map +0 -1
  104. package/dist/wrapWord.js +0 -47
  105. package/dist/wrapWord.js.flow +0 -39
  106. package/dist/wrapWord.js.map +0 -1
@@ -1,42 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _lodash = _interopRequireDefault(require("lodash.flatten"));
9
-
10
- var _wrapCell = _interopRequireDefault(require("./wrapCell"));
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
- /**
15
- * @param {Array} unmappedRows
16
- * @param {number[]} rowHeightIndex
17
- * @param {object} config
18
- * @returns {Array}
19
- */
20
- const mapDataUsingRowHeightIndex = (unmappedRows, rowHeightIndex, config) => {
21
- const tableWidth = unmappedRows[0].length;
22
- const mappedRows = unmappedRows.map((cells, index0) => {
23
- const rowHeight = Array.from(new Array(rowHeightIndex[index0]), () => {
24
- return new Array(tableWidth).fill('');
25
- }); // rowHeight
26
- // [{row index within rowSaw; index2}]
27
- // [{cell index within a virtual row; index1}]
28
-
29
- cells.forEach((value, index1) => {
30
- const cellLines = (0, _wrapCell.default)(value, config.columns[index1].width, config.columns[index1].wrapWord);
31
- cellLines.forEach((cellLine, index2) => {
32
- rowHeight[index2][index1] = cellLine;
33
- });
34
- });
35
- return rowHeight;
36
- });
37
- return (0, _lodash.default)(mappedRows);
38
- };
39
-
40
- var _default = mapDataUsingRowHeightIndex;
41
- exports.default = _default;
42
- //# sourceMappingURL=mapDataUsingRowHeightIndex.js.map
@@ -1,34 +0,0 @@
1
- import flatten from 'lodash.flatten';
2
- import wrapCell from './wrapCell';
3
-
4
- /**
5
- * @param {Array} unmappedRows
6
- * @param {number[]} rowHeightIndex
7
- * @param {object} config
8
- * @returns {Array}
9
- */
10
- export default (unmappedRows, rowHeightIndex, config) => {
11
- const tableWidth = unmappedRows[0].length;
12
-
13
- const mappedRows = unmappedRows.map((cells, index0) => {
14
- const rowHeight = Array.from(new Array(rowHeightIndex[index0]), () => {
15
- return new Array(tableWidth).fill('');
16
- });
17
-
18
- // rowHeight
19
- // [{row index within rowSaw; index2}]
20
- // [{cell index within a virtual row; index1}]
21
-
22
- cells.forEach((value, index1) => {
23
- const cellLines = wrapCell(value, config.columns[index1].width, config.columns[index1].wrapWord);
24
-
25
- cellLines.forEach((cellLine, index2) => {
26
- rowHeight[index2][index1] = cellLine;
27
- });
28
- });
29
-
30
- return rowHeight;
31
- });
32
-
33
- return flatten(mappedRows);
34
- };
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/mapDataUsingRowHeightIndex.js"],"names":["unmappedRows","rowHeightIndex","config","tableWidth","length","mappedRows","map","cells","index0","rowHeight","Array","from","fill","forEach","value","index1","cellLines","columns","width","wrapWord","cellLine","index2"],"mappings":";;;;;;;AAAA;;AACA;;;;AAEA;AACA;AACA;AACA;AACA;AACA;oCACgBA,Y,EAAcC,c,EAAgBC,M,KAAW;AACvD,QAAMC,UAAU,GAAGH,YAAY,CAAC,CAAD,CAAZ,CAAgBI,MAAnC;AAEA,QAAMC,UAAU,GAAGL,YAAY,CAACM,GAAb,CAAiB,CAACC,KAAD,EAAQC,MAAR,KAAmB;AACrD,UAAMC,SAAS,GAAGC,KAAK,CAACC,IAAN,CAAW,IAAID,KAAJ,CAAUT,cAAc,CAACO,MAAD,CAAxB,CAAX,EAA8C,MAAM;AACpE,aAAO,IAAIE,KAAJ,CAAUP,UAAV,EAAsBS,IAAtB,CAA2B,EAA3B,CAAP;AACD,KAFiB,CAAlB,CADqD,CAKrD;AACA;AACA;;AAEAL,IAAAA,KAAK,CAACM,OAAN,CAAc,CAACC,KAAD,EAAQC,MAAR,KAAmB;AAC/B,YAAMC,SAAS,GAAG,uBAASF,KAAT,EAAgBZ,MAAM,CAACe,OAAP,CAAeF,MAAf,EAAuBG,KAAvC,EAA8ChB,MAAM,CAACe,OAAP,CAAeF,MAAf,EAAuBI,QAArE,CAAlB;AAEAH,MAAAA,SAAS,CAACH,OAAV,CAAkB,CAACO,QAAD,EAAWC,MAAX,KAAsB;AACtCZ,QAAAA,SAAS,CAACY,MAAD,CAAT,CAAkBN,MAAlB,IAA4BK,QAA5B;AACD,OAFD;AAGD,KAND;AAQA,WAAOX,SAAP;AACD,GAlBkB,CAAnB;AAoBA,SAAO,qBAAQJ,UAAR,CAAP;AACD,C","sourcesContent":["import flatten from 'lodash.flatten';\nimport wrapCell from './wrapCell';\n\n/**\n * @param {Array} unmappedRows\n * @param {number[]} rowHeightIndex\n * @param {object} config\n * @returns {Array}\n */\nexport default (unmappedRows, rowHeightIndex, config) => {\n const tableWidth = unmappedRows[0].length;\n\n const mappedRows = unmappedRows.map((cells, index0) => {\n const rowHeight = Array.from(new Array(rowHeightIndex[index0]), () => {\n return new Array(tableWidth).fill('');\n });\n\n // rowHeight\n // [{row index within rowSaw; index2}]\n // [{cell index within a virtual row; index1}]\n\n cells.forEach((value, index1) => {\n const cellLines = wrapCell(value, config.columns[index1].width, config.columns[index1].wrapWord);\n\n cellLines.forEach((cellLine, index2) => {\n rowHeight[index2][index1] = cellLine;\n });\n });\n\n return rowHeight;\n });\n\n return flatten(mappedRows);\n};\n"],"file":"mapDataUsingRowHeightIndex.js"}
@@ -1,24 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- /**
9
- * @param {table~row[]} rows
10
- * @param {object} config
11
- * @returns {table~row[]}
12
- */
13
- const padTableData = (rows, config) => {
14
- return rows.map(cells => {
15
- return cells.map((value, index1) => {
16
- const column = config.columns[index1];
17
- return ' '.repeat(column.paddingLeft) + value + ' '.repeat(column.paddingRight);
18
- });
19
- });
20
- };
21
-
22
- var _default = padTableData;
23
- exports.default = _default;
24
- //# sourceMappingURL=padTableData.js.map
@@ -1,14 +0,0 @@
1
- /**
2
- * @param {table~row[]} rows
3
- * @param {object} config
4
- * @returns {table~row[]}
5
- */
6
- export default (rows, config) => {
7
- return rows.map((cells) => {
8
- return cells.map((value, index1) => {
9
- const column = config.columns[index1];
10
-
11
- return ' '.repeat(column.paddingLeft) + value + ' '.repeat(column.paddingRight);
12
- });
13
- });
14
- };
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/padTableData.js"],"names":["rows","config","map","cells","value","index1","column","columns","repeat","paddingLeft","paddingRight"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;sBACgBA,I,EAAMC,M,KAAW;AAC/B,SAAOD,IAAI,CAACE,GAAL,CAAUC,KAAD,IAAW;AACzB,WAAOA,KAAK,CAACD,GAAN,CAAU,CAACE,KAAD,EAAQC,MAAR,KAAmB;AAClC,YAAMC,MAAM,GAAGL,MAAM,CAACM,OAAP,CAAeF,MAAf,CAAf;AAEA,aAAO,IAAIG,MAAJ,CAAWF,MAAM,CAACG,WAAlB,IAAiCL,KAAjC,GAAyC,IAAII,MAAJ,CAAWF,MAAM,CAACI,YAAlB,CAAhD;AACD,KAJM,CAAP;AAKD,GANM,CAAP;AAOD,C","sourcesContent":["/**\n * @param {table~row[]} rows\n * @param {object} config\n * @returns {table~row[]}\n */\nexport default (rows, config) => {\n return rows.map((cells) => {\n return cells.map((value, index1) => {\n const column = config.columns[index1];\n\n return ' '.repeat(column.paddingLeft) + value + ' '.repeat(column.paddingRight);\n });\n });\n};\n"],"file":"padTableData.js"}
@@ -1,23 +0,0 @@
1
- {
2
- "$id": "config.json",
3
- "$schema": "http://json-schema.org/draft-07/schema#",
4
- "type": "object",
5
- "properties": {
6
- "border": {
7
- "$ref": "shared.json#/definitions/borders"
8
- },
9
- "columns": {
10
- "$ref": "shared.json#/definitions/columns"
11
- },
12
- "columnDefault": {
13
- "$ref": "shared.json#/definitions/column"
14
- },
15
- "drawHorizontalLine": {
16
- "typeof": "function"
17
- },
18
- "singleLine": {
19
- "typeof": "boolean"
20
- }
21
- },
22
- "additionalProperties": false
23
- }
@@ -1,98 +0,0 @@
1
- {
2
- "$id": "shared.json",
3
- "$schema": "http://json-schema.org/draft-07/schema#",
4
- "definitions": {
5
- "columns": {
6
- "type": "object",
7
- "patternProperties": {
8
- "^[0-9]+$": {
9
- "$ref": "#/definitions/column"
10
- }
11
- },
12
- "additionalProperties": false
13
- },
14
- "column": {
15
- "type": "object",
16
- "properties": {
17
- "alignment": {
18
- "type": "string",
19
- "enum": [
20
- "left",
21
- "right",
22
- "center"
23
- ]
24
- },
25
- "width": {
26
- "type": "number"
27
- },
28
- "wrapWord": {
29
- "type": "boolean"
30
- },
31
- "truncate": {
32
- "type": "number"
33
- },
34
- "paddingLeft": {
35
- "type": "number"
36
- },
37
- "paddingRight": {
38
- "type": "number"
39
- }
40
- },
41
- "additionalProperties": false
42
- },
43
- "borders": {
44
- "type": "object",
45
- "properties": {
46
- "topBody": {
47
- "$ref": "#/definitions/border"
48
- },
49
- "topJoin": {
50
- "$ref": "#/definitions/border"
51
- },
52
- "topLeft": {
53
- "$ref": "#/definitions/border"
54
- },
55
- "topRight": {
56
- "$ref": "#/definitions/border"
57
- },
58
- "bottomBody": {
59
- "$ref": "#/definitions/border"
60
- },
61
- "bottomJoin": {
62
- "$ref": "#/definitions/border"
63
- },
64
- "bottomLeft": {
65
- "$ref": "#/definitions/border"
66
- },
67
- "bottomRight": {
68
- "$ref": "#/definitions/border"
69
- },
70
- "bodyLeft": {
71
- "$ref": "#/definitions/border"
72
- },
73
- "bodyRight": {
74
- "$ref": "#/definitions/border"
75
- },
76
- "bodyJoin": {
77
- "$ref": "#/definitions/border"
78
- },
79
- "joinBody": {
80
- "$ref": "#/definitions/border"
81
- },
82
- "joinLeft": {
83
- "$ref": "#/definitions/border"
84
- },
85
- "joinRight": {
86
- "$ref": "#/definitions/border"
87
- },
88
- "joinJoin": {
89
- "$ref": "#/definitions/border"
90
- }
91
- },
92
- "additionalProperties": false
93
- },
94
- "border": {
95
- "type": "string"
96
- }
97
- }
98
- }
@@ -1,20 +0,0 @@
1
- {
2
- "$id": "streamConfig.json",
3
- "$schema": "http://json-schema.org/draft-07/schema#",
4
- "type": "object",
5
- "properties": {
6
- "border": {
7
- "$ref": "shared.json#/definitions/borders"
8
- },
9
- "columns": {
10
- "$ref": "shared.json#/definitions/columns"
11
- },
12
- "columnDefault": {
13
- "$ref": "shared.json#/definitions/column"
14
- },
15
- "columnCount": {
16
- "type": "number"
17
- }
18
- },
19
- "additionalProperties": false
20
- }
@@ -1,22 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- /**
9
- * Casts all cell values to a string.
10
- *
11
- * @param {table~row[]} rows
12
- * @returns {table~row[]}
13
- */
14
- const stringifyTableData = rows => {
15
- return rows.map(cells => {
16
- return cells.map(String);
17
- });
18
- };
19
-
20
- var _default = stringifyTableData;
21
- exports.default = _default;
22
- //# sourceMappingURL=stringifyTableData.js.map
@@ -1,11 +0,0 @@
1
- /**
2
- * Casts all cell values to a string.
3
- *
4
- * @param {table~row[]} rows
5
- * @returns {table~row[]}
6
- */
7
- export default (rows) => {
8
- return rows.map((cells) => {
9
- return cells.map(String);
10
- });
11
- };
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/stringifyTableData.js"],"names":["rows","map","cells","String"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;2BACgBA,I,IAAS;AACvB,SAAOA,IAAI,CAACC,GAAL,CAAUC,KAAD,IAAW;AACzB,WAAOA,KAAK,CAACD,GAAN,CAAUE,MAAV,CAAP;AACD,GAFM,CAAP;AAGD,C","sourcesContent":["/**\n * Casts all cell values to a string.\n *\n * @param {table~row[]} rows\n * @returns {table~row[]}\n */\nexport default (rows) => {\n return rows.map((cells) => {\n return cells.map(String);\n });\n};\n"],"file":"stringifyTableData.js"}
package/dist/table.js DELETED
@@ -1,110 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _alignTableData = _interopRequireDefault(require("./alignTableData"));
9
-
10
- var _calculateCellWidthIndex = _interopRequireDefault(require("./calculateCellWidthIndex"));
11
-
12
- var _calculateRowHeightIndex = _interopRequireDefault(require("./calculateRowHeightIndex"));
13
-
14
- var _drawTable = _interopRequireDefault(require("./drawTable"));
15
-
16
- var _makeConfig = _interopRequireDefault(require("./makeConfig"));
17
-
18
- var _mapDataUsingRowHeightIndex = _interopRequireDefault(require("./mapDataUsingRowHeightIndex"));
19
-
20
- var _padTableData = _interopRequireDefault(require("./padTableData"));
21
-
22
- var _stringifyTableData = _interopRequireDefault(require("./stringifyTableData"));
23
-
24
- var _truncateTableData = _interopRequireDefault(require("./truncateTableData"));
25
-
26
- var _validateTableData = _interopRequireDefault(require("./validateTableData"));
27
-
28
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
29
-
30
- /**
31
- * @typedef {string} table~cell
32
- */
33
-
34
- /**
35
- * @typedef {table~cell[]} table~row
36
- */
37
-
38
- /**
39
- * @typedef {object} table~columns
40
- * @property {string} alignment Cell content alignment (enum: left, center, right) (default: left).
41
- * @property {number} width Column width (default: auto).
42
- * @property {number} truncate Number of characters are which the content will be truncated (default: Infinity).
43
- * @property {boolean} wrapWord When true the text is broken at the nearest space or one of the special characters
44
- * @property {number} paddingLeft Cell content padding width left (default: 1).
45
- * @property {number} paddingRight Cell content padding width right (default: 1).
46
- */
47
-
48
- /**
49
- * @typedef {object} table~border
50
- * @property {string} topBody
51
- * @property {string} topJoin
52
- * @property {string} topLeft
53
- * @property {string} topRight
54
- * @property {string} bottomBody
55
- * @property {string} bottomJoin
56
- * @property {string} bottomLeft
57
- * @property {string} bottomRight
58
- * @property {string} bodyLeft
59
- * @property {string} bodyRight
60
- * @property {string} bodyJoin
61
- * @property {string} joinBody
62
- * @property {string} joinLeft
63
- * @property {string} joinRight
64
- * @property {string} joinJoin
65
- */
66
-
67
- /**
68
- * Used to tell whether to draw a horizontal 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} drawHorizontalLine
73
- * @param {number} index
74
- * @param {number} size
75
- * @returns {boolean}
76
- */
77
-
78
- /**
79
- * @typedef {object} table~config
80
- * @property {table~border} border
81
- * @property {table~columns[]} columns Column specific configuration.
82
- * @property {table~columns} columnDefault Default values for all columns. Column specific settings overwrite the default values.
83
- * @property {table~drawHorizontalLine} drawHorizontalLine
84
- * @property {table~singleLine} singleLine Horizontal lines inside the table are not drawn.
85
- */
86
-
87
- /**
88
- * Generates a text table.
89
- *
90
- * @param {table~row[]} data
91
- * @param {table~config} userConfig
92
- * @returns {string}
93
- */
94
- const table = (data, userConfig = {}) => {
95
- let rows;
96
- (0, _validateTableData.default)(data);
97
- rows = (0, _stringifyTableData.default)(data);
98
- const config = (0, _makeConfig.default)(rows, userConfig);
99
- rows = (0, _truncateTableData.default)(data, config);
100
- const rowHeightIndex = (0, _calculateRowHeightIndex.default)(rows, config);
101
- rows = (0, _mapDataUsingRowHeightIndex.default)(rows, rowHeightIndex, config);
102
- rows = (0, _alignTableData.default)(rows, config);
103
- rows = (0, _padTableData.default)(rows, config);
104
- const cellWidthIndex = (0, _calculateCellWidthIndex.default)(rows[0]);
105
- return (0, _drawTable.default)(rows, config.border, cellWidthIndex, rowHeightIndex, config.drawHorizontalLine, config.singleLine);
106
- };
107
-
108
- var _default = table;
109
- exports.default = _default;
110
- //# sourceMappingURL=table.js.map
@@ -1,96 +0,0 @@
1
- import alignTableData from './alignTableData';
2
- import calculateCellWidthIndex from './calculateCellWidthIndex';
3
- import calculateRowHeightIndex from './calculateRowHeightIndex';
4
- import drawTable from './drawTable';
5
- import makeConfig from './makeConfig';
6
- import mapDataUsingRowHeightIndex from './mapDataUsingRowHeightIndex';
7
- import padTableData from './padTableData';
8
- import stringifyTableData from './stringifyTableData';
9
- import truncateTableData from './truncateTableData';
10
- import validateTableData from './validateTableData';
11
-
12
- /**
13
- * @typedef {string} table~cell
14
- */
15
-
16
- /**
17
- * @typedef {table~cell[]} table~row
18
- */
19
-
20
- /**
21
- * @typedef {object} table~columns
22
- * @property {string} alignment Cell content alignment (enum: left, center, right) (default: left).
23
- * @property {number} width Column width (default: auto).
24
- * @property {number} truncate Number of characters are which the content will be truncated (default: Infinity).
25
- * @property {boolean} wrapWord When true the text is broken at the nearest space or one of the special characters
26
- * @property {number} paddingLeft Cell content padding width left (default: 1).
27
- * @property {number} paddingRight Cell content padding width right (default: 1).
28
- */
29
-
30
- /**
31
- * @typedef {object} table~border
32
- * @property {string} topBody
33
- * @property {string} topJoin
34
- * @property {string} topLeft
35
- * @property {string} topRight
36
- * @property {string} bottomBody
37
- * @property {string} bottomJoin
38
- * @property {string} bottomLeft
39
- * @property {string} bottomRight
40
- * @property {string} bodyLeft
41
- * @property {string} bodyRight
42
- * @property {string} bodyJoin
43
- * @property {string} joinBody
44
- * @property {string} joinLeft
45
- * @property {string} joinRight
46
- * @property {string} joinJoin
47
- */
48
-
49
- /**
50
- * Used to tell whether to draw a horizontal 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} drawHorizontalLine
55
- * @param {number} index
56
- * @param {number} size
57
- * @returns {boolean}
58
- */
59
-
60
- /**
61
- * @typedef {object} table~config
62
- * @property {table~border} border
63
- * @property {table~columns[]} columns Column specific configuration.
64
- * @property {table~columns} columnDefault Default values for all columns. Column specific settings overwrite the default values.
65
- * @property {table~drawHorizontalLine} drawHorizontalLine
66
- * @property {table~singleLine} singleLine Horizontal lines inside the table are not drawn.
67
- */
68
-
69
- /**
70
- * Generates a text table.
71
- *
72
- * @param {table~row[]} data
73
- * @param {table~config} userConfig
74
- * @returns {string}
75
- */
76
- export default (data, userConfig = {}) => {
77
- let rows;
78
-
79
- validateTableData(data);
80
-
81
- rows = stringifyTableData(data);
82
-
83
- const config = makeConfig(rows, userConfig);
84
-
85
- rows = truncateTableData(data, config);
86
-
87
- const rowHeightIndex = calculateRowHeightIndex(rows, config);
88
-
89
- rows = mapDataUsingRowHeightIndex(rows, rowHeightIndex, config);
90
- rows = alignTableData(rows, config);
91
- rows = padTableData(rows, config);
92
-
93
- const cellWidthIndex = calculateCellWidthIndex(rows[0]);
94
-
95
- return drawTable(rows, config.border, cellWidthIndex, rowHeightIndex, config.drawHorizontalLine, config.singleLine);
96
- };
package/dist/table.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/table.js"],"names":["data","userConfig","rows","config","rowHeightIndex","cellWidthIndex","border","drawHorizontalLine","singleLine"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;eACgBA,I,EAAMC,UAAU,GAAG,E,KAAO;AACxC,MAAIC,IAAJ;AAEA,kCAAkBF,IAAlB;AAEAE,EAAAA,IAAI,GAAG,iCAAmBF,IAAnB,CAAP;AAEA,QAAMG,MAAM,GAAG,yBAAWD,IAAX,EAAiBD,UAAjB,CAAf;AAEAC,EAAAA,IAAI,GAAG,gCAAkBF,IAAlB,EAAwBG,MAAxB,CAAP;AAEA,QAAMC,cAAc,GAAG,sCAAwBF,IAAxB,EAA8BC,MAA9B,CAAvB;AAEAD,EAAAA,IAAI,GAAG,yCAA2BA,IAA3B,EAAiCE,cAAjC,EAAiDD,MAAjD,CAAP;AACAD,EAAAA,IAAI,GAAG,6BAAeA,IAAf,EAAqBC,MAArB,CAAP;AACAD,EAAAA,IAAI,GAAG,2BAAaA,IAAb,EAAmBC,MAAnB,CAAP;AAEA,QAAME,cAAc,GAAG,sCAAwBH,IAAI,CAAC,CAAD,CAA5B,CAAvB;AAEA,SAAO,wBAAUA,IAAV,EAAgBC,MAAM,CAACG,MAAvB,EAA+BD,cAA/B,EAA+CD,cAA/C,EAA+DD,MAAM,CAACI,kBAAtE,EAA0FJ,MAAM,CAACK,UAAjG,CAAP;AACD,C","sourcesContent":["import alignTableData from './alignTableData';\nimport calculateCellWidthIndex from './calculateCellWidthIndex';\nimport calculateRowHeightIndex from './calculateRowHeightIndex';\nimport drawTable from './drawTable';\nimport makeConfig from './makeConfig';\nimport mapDataUsingRowHeightIndex from './mapDataUsingRowHeightIndex';\nimport padTableData from './padTableData';\nimport stringifyTableData from './stringifyTableData';\nimport truncateTableData from './truncateTableData';\nimport validateTableData from './validateTableData';\n\n/**\n * @typedef {string} table~cell\n */\n\n/**\n * @typedef {table~cell[]} table~row\n */\n\n/**\n * @typedef {object} table~columns\n * @property {string} alignment Cell content alignment (enum: left, center, right) (default: left).\n * @property {number} width Column width (default: auto).\n * @property {number} truncate Number of characters are which the content will be truncated (default: Infinity).\n * @property {boolean} wrapWord When true the text is broken at the nearest space or one of the special characters\n * @property {number} paddingLeft Cell content padding width left (default: 1).\n * @property {number} paddingRight Cell content padding width right (default: 1).\n */\n\n/**\n * @typedef {object} table~border\n * @property {string} topBody\n * @property {string} topJoin\n * @property {string} topLeft\n * @property {string} topRight\n * @property {string} bottomBody\n * @property {string} bottomJoin\n * @property {string} bottomLeft\n * @property {string} bottomRight\n * @property {string} bodyLeft\n * @property {string} bodyRight\n * @property {string} bodyJoin\n * @property {string} joinBody\n * @property {string} joinLeft\n * @property {string} joinRight\n * @property {string} joinJoin\n */\n\n/**\n * Used to tell whether to draw a horizontal line.\n * This callback is called for each non-content line of the table.\n * The default behavior is to always return true.\n *\n * @typedef {Function} drawHorizontalLine\n * @param {number} index\n * @param {number} size\n * @returns {boolean}\n */\n\n/**\n * @typedef {object} table~config\n * @property {table~border} border\n * @property {table~columns[]} columns Column specific configuration.\n * @property {table~columns} columnDefault Default values for all columns. Column specific settings overwrite the default values.\n * @property {table~drawHorizontalLine} drawHorizontalLine\n * @property {table~singleLine} singleLine Horizontal lines inside the table are not drawn.\n */\n\n/**\n * Generates a text table.\n *\n * @param {table~row[]} data\n * @param {table~config} userConfig\n * @returns {string}\n */\nexport default (data, userConfig = {}) => {\n let rows;\n\n validateTableData(data);\n\n rows = stringifyTableData(data);\n\n const config = makeConfig(rows, userConfig);\n\n rows = truncateTableData(data, config);\n\n const rowHeightIndex = calculateRowHeightIndex(rows, config);\n\n rows = mapDataUsingRowHeightIndex(rows, rowHeightIndex, config);\n rows = alignTableData(rows, config);\n rows = padTableData(rows, config);\n\n const cellWidthIndex = calculateCellWidthIndex(rows[0]);\n\n return drawTable(rows, config.border, cellWidthIndex, rowHeightIndex, config.drawHorizontalLine, config.singleLine);\n};\n"],"file":"table.js"}
@@ -1,30 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _lodash = _interopRequireDefault(require("lodash.truncate"));
9
-
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
12
- /**
13
- * @todo Make it work with ASCII content.
14
- * @param {table~row[]} rows
15
- * @param {object} config
16
- * @returns {table~row[]}
17
- */
18
- const truncateTableData = (rows, config) => {
19
- return rows.map(cells => {
20
- return cells.map((content, index) => {
21
- return (0, _lodash.default)(content, {
22
- length: config.columns[index].truncate
23
- });
24
- });
25
- });
26
- };
27
-
28
- var _default = truncateTableData;
29
- exports.default = _default;
30
- //# sourceMappingURL=truncateTableData.js.map
@@ -1,17 +0,0 @@
1
- import truncate from 'lodash.truncate';
2
-
3
- /**
4
- * @todo Make it work with ASCII content.
5
- * @param {table~row[]} rows
6
- * @param {object} config
7
- * @returns {table~row[]}
8
- */
9
- export default (rows, config) => {
10
- return rows.map((cells) => {
11
- return cells.map((content, index) => {
12
- return truncate(content, {
13
- length: config.columns[index].truncate,
14
- });
15
- });
16
- });
17
- };
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/truncateTableData.js"],"names":["rows","config","map","cells","content","index","length","columns","truncate"],"mappings":";;;;;;;AAAA;;;;AAEA;AACA;AACA;AACA;AACA;AACA;2BACgBA,I,EAAMC,M,KAAW;AAC/B,SAAOD,IAAI,CAACE,GAAL,CAAUC,KAAD,IAAW;AACzB,WAAOA,KAAK,CAACD,GAAN,CAAU,CAACE,OAAD,EAAUC,KAAV,KAAoB;AACnC,aAAO,qBAASD,OAAT,EAAkB;AACvBE,QAAAA,MAAM,EAAEL,MAAM,CAACM,OAAP,CAAeF,KAAf,EAAsBG;AADP,OAAlB,CAAP;AAGD,KAJM,CAAP;AAKD,GANM,CAAP;AAOD,C","sourcesContent":["import truncate from 'lodash.truncate';\n\n/**\n * @todo Make it work with ASCII content.\n * @param {table~row[]} rows\n * @param {object} config\n * @returns {table~row[]}\n */\nexport default (rows, config) => {\n return rows.map((cells) => {\n return cells.map((content, index) => {\n return truncate(content, {\n length: config.columns[index].truncate,\n });\n });\n });\n};\n"],"file":"truncateTableData.js"}
@@ -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 _validators = _interopRequireDefault(require("../dist/validators"));
9
-
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
12
- /**
13
- * @param {string} schemaId
14
- * @param {formatData~config} config
15
- * @returns {undefined}
16
- */
17
- const validateConfig = (schemaId, config = {}) => {
18
- const validate = _validators.default[schemaId];
19
-
20
- if (!validate(config)) {
21
- const errors = validate.errors.map(error => {
22
- return {
23
- dataPath: error.dataPath,
24
- message: error.message,
25
- params: error.params,
26
- schemaPath: error.schemaPath
27
- };
28
- });
29
- /* eslint-disable no-console */
30
-
31
- console.log('config', config);
32
- console.log('errors', errors);
33
- /* eslint-enable no-console */
34
-
35
- throw new Error('Invalid config.');
36
- }
37
- };
38
-
39
- var _default = validateConfig;
40
- exports.default = _default;
41
- //# sourceMappingURL=validateConfig.js.map
@@ -1,27 +0,0 @@
1
- import validators from '../dist/validators';
2
-
3
- /**
4
- * @param {string} schemaId
5
- * @param {formatData~config} config
6
- * @returns {undefined}
7
- */
8
- export default (schemaId, config = {}) => {
9
- const validate = validators[schemaId];
10
- if (!validate(config)) {
11
- const errors = validate.errors.map((error) => {
12
- return {
13
- dataPath: error.dataPath,
14
- message: error.message,
15
- params: error.params,
16
- schemaPath: error.schemaPath,
17
- };
18
- });
19
-
20
- /* eslint-disable no-console */
21
- console.log('config', config);
22
- console.log('errors', errors);
23
- /* eslint-enable no-console */
24
-
25
- throw new Error('Invalid config.');
26
- }
27
- };
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/validateConfig.js"],"names":["schemaId","config","validate","validators","errors","map","error","dataPath","message","params","schemaPath","console","log","Error"],"mappings":";;;;;;;AAAA;;;;AAEA;AACA;AACA;AACA;AACA;wBACgBA,Q,EAAUC,MAAM,GAAG,E,KAAO;AACxC,QAAMC,QAAQ,GAAGC,oBAAWH,QAAX,CAAjB;;AACA,MAAI,CAACE,QAAQ,CAACD,MAAD,CAAb,EAAuB;AACrB,UAAMG,MAAM,GAAGF,QAAQ,CAACE,MAAT,CAAgBC,GAAhB,CAAqBC,KAAD,IAAW;AAC5C,aAAO;AACLC,QAAAA,QAAQ,EAAED,KAAK,CAACC,QADX;AAELC,QAAAA,OAAO,EAAEF,KAAK,CAACE,OAFV;AAGLC,QAAAA,MAAM,EAAEH,KAAK,CAACG,MAHT;AAILC,QAAAA,UAAU,EAAEJ,KAAK,CAACI;AAJb,OAAP;AAMD,KAPc,CAAf;AASA;;AACAC,IAAAA,OAAO,CAACC,GAAR,CAAY,QAAZ,EAAsBX,MAAtB;AACAU,IAAAA,OAAO,CAACC,GAAR,CAAY,QAAZ,EAAsBR,MAAtB;AACA;;AAEA,UAAM,IAAIS,KAAJ,CAAU,iBAAV,CAAN;AACD;AACF,C","sourcesContent":["import validators from '../dist/validators';\n\n/**\n * @param {string} schemaId\n * @param {formatData~config} config\n * @returns {undefined}\n */\nexport default (schemaId, config = {}) => {\n const validate = validators[schemaId];\n if (!validate(config)) {\n const errors = validate.errors.map((error) => {\n return {\n dataPath: error.dataPath,\n message: error.message,\n params: error.params,\n schemaPath: error.schemaPath,\n };\n });\n\n /* eslint-disable no-console */\n console.log('config', config);\n console.log('errors', errors);\n /* eslint-enable no-console */\n\n throw new Error('Invalid config.');\n }\n};\n"],"file":"validateConfig.js"}