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,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
- };
@@ -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
- };
@@ -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,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
- };
@@ -1,85 +0,0 @@
1
- import cloneDeep from 'lodash.clonedeep';
2
- import calculateMaximumColumnWidthIndex from './calculateMaximumColumnWidthIndex';
3
- import getBorderCharacters from './getBorderCharacters';
4
- import validateConfig from './validateConfig';
5
-
6
- /**
7
- * Merges user provided border characters with the default border ("honeywell") characters.
8
- *
9
- * @param {object} border
10
- * @returns {object}
11
- */
12
- const makeBorder = (border = {}) => {
13
- return Object.assign({}, getBorderCharacters('honeywell'), border);
14
- };
15
-
16
- /**
17
- * Creates a configuration for every column using default
18
- * values for the missing configuration properties.
19
- *
20
- * @param {Array[]} rows
21
- * @param {object} columns
22
- * @param {object} columnDefault
23
- * @returns {object}
24
- */
25
- const makeColumns = (rows, columns = {}, columnDefault = {}) => {
26
- const maximumColumnWidthIndex = calculateMaximumColumnWidthIndex(rows);
27
-
28
- for (let index = 0; index < rows[0].length; index++) {
29
- if (typeof columns[index] === 'undefined') {
30
- columns[index] = {};
31
- }
32
-
33
- columns[index] = Object.assign({
34
- alignment: 'left',
35
- paddingLeft: 1,
36
- paddingRight: 1,
37
- truncate: Number.POSITIVE_INFINITY,
38
- width: maximumColumnWidthIndex[index],
39
- wrapWord: false,
40
- }, columnDefault, columns[index]);
41
- }
42
-
43
- return columns;
44
- };
45
-
46
- /**
47
- * Makes a new configuration object out of the userConfig object
48
- * using default values for the missing configuration properties.
49
- *
50
- * @param {Array[]} rows
51
- * @param {object} userConfig
52
- * @returns {object}
53
- */
54
- export default (rows, userConfig = {}) => {
55
- validateConfig('config.json', userConfig);
56
-
57
- const config = cloneDeep(userConfig);
58
-
59
- config.border = makeBorder(config.border);
60
- config.columns = makeColumns(rows, config.columns, config.columnDefault);
61
-
62
- if (!config.drawHorizontalLine) {
63
- /**
64
- * @returns {boolean}
65
- */
66
- config.drawHorizontalLine = () => {
67
- return true;
68
- };
69
- }
70
-
71
- if (!config.drawVerticalLine) {
72
- /**
73
- * @returns {boolean}
74
- */
75
- config.drawVerticalLine = () => {
76
- return true;
77
- };
78
- }
79
-
80
- if (config.singleLine === undefined) {
81
- config.singleLine = false;
82
- }
83
-
84
- return config;
85
- };
@@ -1,92 +0,0 @@
1
- import cloneDeep from 'lodash.clonedeep';
2
- import getBorderCharacters from './getBorderCharacters';
3
- import validateConfig from './validateConfig';
4
-
5
- /**
6
- * Merges user provided border characters with the default border ("honeywell") characters.
7
- *
8
- * @param {object} border
9
- * @returns {object}
10
- */
11
- const makeBorder = (border = {}) => {
12
- return Object.assign({}, getBorderCharacters('honeywell'), border);
13
- };
14
-
15
- /**
16
- * Creates a configuration for every column using default
17
- * values for the missing configuration properties.
18
- *
19
- * @param {number} columnCount
20
- * @param {object} columns
21
- * @param {object} columnDefault
22
- * @returns {object}
23
- */
24
- const makeColumns = (columnCount, columns = {}, columnDefault = {}) => {
25
- for (let index = 0; index < columnCount; index++) {
26
- if (typeof columns[index] === 'undefined') {
27
- columns[index] = {};
28
- }
29
-
30
- columns[index] = Object.assign({
31
- alignment: 'left',
32
- paddingLeft: 1,
33
- paddingRight: 1,
34
- truncate: Number.POSITIVE_INFINITY,
35
- wrapWord: false,
36
- }, columnDefault, columns[index]);
37
- }
38
-
39
- return columns;
40
- };
41
-
42
- /**
43
- * @typedef {object} columnConfig
44
- * @property {string} alignment
45
- * @property {number} width
46
- * @property {number} truncate
47
- * @property {number} paddingLeft
48
- * @property {number} paddingRight
49
- */
50
-
51
- /**
52
- * @typedef {object} streamConfig
53
- * @property {columnConfig} columnDefault
54
- * @property {object} border
55
- * @property {columnConfig[]}
56
- * @property {number} columnCount Number of columns in the table (required).
57
- */
58
-
59
- /**
60
- * Makes a new configuration object out of the userConfig object
61
- * using default values for the missing configuration properties.
62
- *
63
- * @param {streamConfig} userConfig
64
- * @returns {object}
65
- */
66
- export default (userConfig = {}) => {
67
- validateConfig('streamConfig.json', userConfig);
68
-
69
- const config = cloneDeep(userConfig);
70
-
71
- if (!config.columnDefault || !config.columnDefault.width) {
72
- throw new Error('Must provide config.columnDefault.width when creating a stream.');
73
- }
74
-
75
- if (!config.columnCount) {
76
- throw new Error('Must provide config.columnCount.');
77
- }
78
-
79
- config.border = makeBorder(config.border);
80
- config.columns = makeColumns(config.columnCount, config.columns, config.columnDefault);
81
-
82
- if (!config.drawVerticalLine) {
83
- /**
84
- * @returns {boolean}
85
- */
86
- config.drawVerticalLine = () => {
87
- return true;
88
- };
89
- }
90
-
91
- return config;
92
- };
@@ -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,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,26 +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
- "drawVerticalLine": {
16
- "typeof": "function"
17
- },
18
- "drawHorizontalLine": {
19
- "typeof": "function"
20
- },
21
- "singleLine": {
22
- "typeof": "boolean"
23
- }
24
- },
25
- "additionalProperties": false
26
- }
@@ -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,23 +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
- "drawVerticalLine": {
19
- "typeof": "function"
20
- }
21
- },
22
- "additionalProperties": false
23
- }
@@ -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
- };