table 6.1.0 → 6.3.2

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 (85) hide show
  1. package/README.md +1 -1
  2. package/dist/alignString.d.ts +6 -0
  3. package/dist/alignString.js +51 -95
  4. package/dist/alignTableData.d.ts +3 -0
  5. package/dist/alignTableData.js +17 -31
  6. package/dist/calculateCellHeight.d.ts +2 -0
  7. package/dist/calculateCellHeight.js +14 -35
  8. package/dist/calculateCellWidthIndex.d.ts +6 -0
  9. package/dist/calculateCellWidthIndex.js +11 -22
  10. package/dist/calculateMaximumColumnWidthIndex.d.ts +6 -0
  11. package/dist/calculateMaximumColumnWidthIndex.js +18 -30
  12. package/dist/calculateRowHeightIndex.d.ts +6 -0
  13. package/dist/calculateRowHeightIndex.js +23 -39
  14. package/dist/createStream.d.ts +3 -0
  15. package/dist/createStream.js +65 -116
  16. package/dist/drawBorder.d.ts +25 -0
  17. package/dist/drawBorder.js +45 -106
  18. package/dist/drawHorizontalContent.d.ts +11 -0
  19. package/dist/drawHorizontalContent.js +17 -40
  20. package/dist/drawRow.d.ts +7 -0
  21. package/dist/drawRow.js +14 -39
  22. package/dist/drawTable.d.ts +3 -0
  23. package/dist/drawTable.js +33 -56
  24. package/dist/generated/validators.d.ts +13 -0
  25. package/dist/{validators.js → generated/validators.js} +309 -315
  26. package/dist/getBorderCharacters.d.ts +3 -0
  27. package/dist/getBorderCharacters.js +79 -115
  28. package/dist/{index.js.flow → index.d.ts} +2 -6
  29. package/dist/index.js +22 -30
  30. package/dist/makeConfig.d.ts +8 -0
  31. package/dist/makeConfig.js +42 -84
  32. package/dist/makeStreamConfig.d.ts +8 -0
  33. package/dist/makeStreamConfig.js +42 -90
  34. package/dist/mapDataUsingRowHeightIndex.d.ts +3 -0
  35. package/dist/mapDataUsingRowHeightIndex.js +23 -38
  36. package/dist/padTableData.d.ts +3 -0
  37. package/dist/padTableData.js +7 -20
  38. package/dist/stringifyTableData.d.ts +3 -0
  39. package/dist/stringifyTableData.js +5 -19
  40. package/dist/table.d.ts +3 -0
  41. package/dist/table.js +25 -119
  42. package/dist/truncateTableData.d.ts +6 -0
  43. package/dist/truncateTableData.js +13 -23
  44. package/dist/types/api.d.ts +100 -0
  45. package/dist/types/api.js +2 -0
  46. package/dist/types/internal.d.ts +1 -0
  47. package/dist/types/internal.js +2 -0
  48. package/dist/validateConfig.d.ts +3 -0
  49. package/dist/validateConfig.js +22 -38
  50. package/dist/validateTableData.d.ts +2 -0
  51. package/dist/validateTableData.js +23 -49
  52. package/dist/wrapCell.d.ts +9 -0
  53. package/dist/wrapCell.js +23 -38
  54. package/dist/wrapString.d.ts +10 -0
  55. package/dist/wrapString.js +14 -29
  56. package/dist/wrapWord.d.ts +2 -0
  57. package/dist/wrapWord.js +26 -44
  58. package/package.json +32 -24
  59. package/dist/alignString.js.flow +0 -97
  60. package/dist/alignTableData.js.flow +0 -21
  61. package/dist/calculateCellHeight.js.flow +0 -24
  62. package/dist/calculateCellWidthIndex.js.flow +0 -17
  63. package/dist/calculateMaximumColumnWidthIndex.js.flow +0 -27
  64. package/dist/calculateRowHeightIndex.js.flow +0 -36
  65. package/dist/createStream.js.flow +0 -125
  66. package/dist/drawBorder.js.flow +0 -89
  67. package/dist/drawHorizontalContent.js.flow +0 -31
  68. package/dist/drawRow.js.flow +0 -29
  69. package/dist/drawTable.js.flow +0 -64
  70. package/dist/getBorderCharacters.js.flow +0 -120
  71. package/dist/makeConfig.js.flow +0 -85
  72. package/dist/makeStreamConfig.js.flow +0 -92
  73. package/dist/mapDataUsingRowHeightIndex.js.flow +0 -34
  74. package/dist/padTableData.js.flow +0 -14
  75. package/dist/schemas/config.json +0 -26
  76. package/dist/schemas/shared.json +0 -98
  77. package/dist/schemas/streamConfig.json +0 -23
  78. package/dist/stringifyTableData.js.flow +0 -11
  79. package/dist/table.js.flow +0 -108
  80. package/dist/truncateTableData.js.flow +0 -17
  81. package/dist/validateConfig.js.flow +0 -27
  82. package/dist/validateTableData.js.flow +0 -44
  83. package/dist/wrapCell.js.flow +0 -35
  84. package/dist/wrapString.js.flow +0 -29
  85. package/dist/wrapWord.js.flow +0 -39
@@ -1,108 +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 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
-
60
- /**
61
- * Used to tell whether to draw a horizontal line.
62
- * This callback is called for each non-content line of the table.
63
- * The default behavior is to always return true.
64
- *
65
- * @typedef {Function} drawHorizontalLine
66
- * @param {number} index
67
- * @param {number} size
68
- * @returns {boolean}
69
- */
70
-
71
- /**
72
- * @typedef {object} table~config
73
- * @property {table~border} border
74
- * @property {table~columns[]} columns Column specific configuration.
75
- * @property {table~columns} columnDefault Default values for all columns. Column specific settings overwrite the default values.
76
- * @property {table~drawVerticalLine} drawVerticalLine
77
- * @property {table~drawHorizontalLine} drawHorizontalLine
78
- * @property {table~singleLine} singleLine Horizontal lines inside the table are not drawn.
79
- */
80
-
81
- /**
82
- * Generates a text table.
83
- *
84
- * @param {table~row[]} data
85
- * @param {table~config} userConfig
86
- * @returns {string}
87
- */
88
- export default (data, userConfig = {}) => {
89
- let rows;
90
-
91
- validateTableData(data);
92
-
93
- rows = stringifyTableData(data);
94
-
95
- const config = makeConfig(rows, userConfig);
96
-
97
- rows = truncateTableData(data, config);
98
-
99
- const rowHeightIndex = calculateRowHeightIndex(rows, config);
100
-
101
- rows = mapDataUsingRowHeightIndex(rows, rowHeightIndex, config);
102
- rows = alignTableData(rows, config);
103
- rows = padTableData(rows, config);
104
-
105
- const cellWidthIndex = calculateCellWidthIndex(rows[0]);
106
-
107
- return drawTable(rows, cellWidthIndex, rowHeightIndex, config);
108
- };
@@ -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,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,44 +0,0 @@
1
- /**
2
- * @typedef {string} cell
3
- */
4
-
5
- /**
6
- * @typedef {cell[]} validateData~column
7
- */
8
-
9
- /**
10
- * @param {column[]} rows
11
- * @returns {undefined}
12
- */
13
- export default (rows) => {
14
- if (!Array.isArray(rows)) {
15
- throw new TypeError('Table data must be an array.');
16
- }
17
-
18
- if (rows.length === 0) {
19
- throw new Error('Table must define at least one row.');
20
- }
21
-
22
- if (rows[0].length === 0) {
23
- throw new Error('Table must define at least one column.');
24
- }
25
-
26
- const columnNumber = rows[0].length;
27
-
28
- for (const cells of rows) {
29
- if (!Array.isArray(cells)) {
30
- throw new TypeError('Table row data must be an array.');
31
- }
32
-
33
- if (cells.length !== columnNumber) {
34
- throw new Error('Table must have a consistent number of cells.');
35
- }
36
-
37
- for (const cell of cells) {
38
- // eslint-disable-next-line no-control-regex
39
- if (/[\u0001-\u0006\u0008\u0009\u000B-\u001A]/.test(cell)) {
40
- throw new Error('Table data must not contain control characters.');
41
- }
42
- }
43
- }
44
- };
@@ -1,35 +0,0 @@
1
- import wrapString from './wrapString';
2
- import wrapWord from './wrapWord';
3
-
4
- /**
5
- * Wrap a single cell value into a list of lines
6
- *
7
- * Always wraps on newlines, for the remainder uses either word or string wrapping
8
- * depending on user configuration.
9
- *
10
- * @param {string} cellValue
11
- * @param {number} columnWidth
12
- * @param {boolean} useWrapWord
13
- * @returns {Array}
14
- */
15
- export default (cellValue, columnWidth, useWrapWord) => {
16
- // First split on literal newlines
17
- const cellLines = cellValue.split('\n');
18
-
19
- // Then iterate over the list and word-wrap every remaining line if necessary.
20
- for (let lineNr = 0; lineNr < cellLines.length;) {
21
- let lineChunks;
22
-
23
- if (useWrapWord) {
24
- lineChunks = wrapWord(cellLines[lineNr], columnWidth);
25
- } else {
26
- lineChunks = wrapString(cellLines[lineNr], columnWidth);
27
- }
28
-
29
- // Replace our original array element with whatever the wrapping returned
30
- cellLines.splice(lineNr, 1, ...lineChunks);
31
- lineNr += lineChunks.length;
32
- }
33
-
34
- return cellLines;
35
- };
@@ -1,29 +0,0 @@
1
- import slice from 'slice-ansi';
2
- import stringWidth from 'string-width';
3
-
4
- /**
5
- * Creates an array of strings split into groups the length of size.
6
- * This function works with strings that contain ASCII characters.
7
- *
8
- * wrapText is different from would-be "chunk" implementation
9
- * in that whitespace characters that occur on a chunk size limit are trimmed.
10
- *
11
- * @param {string} subject
12
- * @param {number} size
13
- * @returns {Array}
14
- */
15
- export default (subject, size) => {
16
- let subjectSlice;
17
-
18
- subjectSlice = subject;
19
-
20
- const chunks = [];
21
-
22
- do {
23
- chunks.push(slice(subjectSlice, 0, size));
24
-
25
- subjectSlice = slice(subjectSlice, size).trim();
26
- } while (stringWidth(subjectSlice));
27
-
28
- return chunks;
29
- };
@@ -1,39 +0,0 @@
1
- import slice from 'slice-ansi';
2
- import stringWidth from 'string-width';
3
-
4
- /**
5
- * @param {string} input
6
- * @param {number} size
7
- * @returns {Array}
8
- */
9
- export default (input, size) => {
10
- let subject;
11
-
12
- subject = input;
13
-
14
- const chunks = [];
15
-
16
- // https://regex101.com/r/gY5kZ1/1
17
- const re = new RegExp('(^.{1,' + size + '}(\\s+|$))|(^.{1,' + (size - 1) + '}(\\\\|/|_|\\.|,|;|-))');
18
-
19
- do {
20
- let chunk;
21
-
22
- chunk = subject.match(re);
23
-
24
- if (chunk) {
25
- chunk = chunk[0];
26
-
27
- subject = slice(subject, stringWidth(chunk));
28
-
29
- chunk = chunk.trim();
30
- } else {
31
- chunk = slice(subject, 0, size);
32
- subject = slice(subject, size);
33
- }
34
-
35
- chunks.push(chunk);
36
- } while (stringWidth(subject));
37
-
38
- return chunks;
39
- };