table 6.0.3 → 6.0.7

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 (40) hide show
  1. package/README.md +3 -3
  2. package/dist/alignString.js.map +1 -1
  3. package/dist/alignTableData.js.map +1 -1
  4. package/dist/calculateCellHeight.js.map +1 -1
  5. package/dist/calculateCellWidthIndex.js.map +1 -1
  6. package/dist/calculateMaximumColumnWidthIndex.js.map +1 -1
  7. package/dist/calculateRowHeightIndex.js.map +1 -1
  8. package/dist/createStream.js +4 -9
  9. package/dist/createStream.js.flow +3 -4
  10. package/dist/createStream.js.map +1 -1
  11. package/dist/drawBorder.js.map +1 -1
  12. package/dist/drawRow.js.map +1 -1
  13. package/dist/drawTable.js.map +1 -1
  14. package/dist/getBorderCharacters.js.map +1 -1
  15. package/dist/index.js +3 -3
  16. package/dist/makeConfig.js +1 -1
  17. package/dist/makeConfig.js.flow +1 -1
  18. package/dist/makeConfig.js.map +1 -1
  19. package/dist/makeStreamConfig.js +1 -1
  20. package/dist/makeStreamConfig.js.flow +1 -1
  21. package/dist/makeStreamConfig.js.map +1 -1
  22. package/dist/mapDataUsingRowHeightIndex.js.map +1 -1
  23. package/dist/padTableData.js.map +1 -1
  24. package/dist/schemas/config.json +7 -98
  25. package/dist/schemas/shared.json +98 -0
  26. package/dist/schemas/streamConfig.json +4 -98
  27. package/dist/stringifyTableData.js.map +1 -1
  28. package/dist/table.js.map +1 -1
  29. package/dist/truncateTableData.js.map +1 -1
  30. package/dist/validateConfig.js +40 -751
  31. package/dist/validateConfig.js.flow +4 -10
  32. package/dist/validateConfig.js.map +1 -1
  33. package/dist/validateTableData.js +11 -39
  34. package/dist/validateTableData.js.map +1 -1
  35. package/dist/validators.js +1492 -0
  36. package/dist/wrapCell.js.map +1 -1
  37. package/dist/wrapString.js.map +1 -1
  38. package/dist/wrapWord.js.map +1 -1
  39. package/package.json +20 -19
  40. package/dist/validateStreamConfig.js +0 -741
@@ -0,0 +1,98 @@
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
+ }
@@ -4,111 +4,17 @@
4
4
  "type": "object",
5
5
  "properties": {
6
6
  "border": {
7
- "$ref": "#/definitions/borders"
7
+ "$ref": "shared.json#/definitions/borders"
8
8
  },
9
9
  "columns": {
10
- "$ref": "#/definitions/columns"
10
+ "$ref": "shared.json#/definitions/columns"
11
11
  },
12
12
  "columnDefault": {
13
- "$ref": "#/definitions/column"
13
+ "$ref": "shared.json#/definitions/column"
14
14
  },
15
15
  "columnCount": {
16
16
  "type": "number"
17
17
  }
18
18
  },
19
- "additionalProperties": false,
20
- "definitions": {
21
- "columns": {
22
- "type": "object",
23
- "patternProperties": {
24
- "^[0-9]+$": {
25
- "$ref": "#/definitions/column"
26
- }
27
- },
28
- "additionalProperties": false
29
- },
30
- "column": {
31
- "type": "object",
32
- "properties": {
33
- "alignment": {
34
- "type": "string",
35
- "enum": [
36
- "left",
37
- "right",
38
- "center"
39
- ]
40
- },
41
- "width": {
42
- "type": "number"
43
- },
44
- "wrapWord": {
45
- "type": "boolean"
46
- },
47
- "truncate": {
48
- "type": "number"
49
- },
50
- "paddingLeft": {
51
- "type": "number"
52
- },
53
- "paddingRight": {
54
- "type": "number"
55
- }
56
- },
57
- "additionalProperties": false
58
- },
59
- "borders": {
60
- "type": "object",
61
- "properties": {
62
- "topBody": {
63
- "$ref": "#/definitions/border"
64
- },
65
- "topJoin": {
66
- "$ref": "#/definitions/border"
67
- },
68
- "topLeft": {
69
- "$ref": "#/definitions/border"
70
- },
71
- "topRight": {
72
- "$ref": "#/definitions/border"
73
- },
74
- "bottomBody": {
75
- "$ref": "#/definitions/border"
76
- },
77
- "bottomJoin": {
78
- "$ref": "#/definitions/border"
79
- },
80
- "bottomLeft": {
81
- "$ref": "#/definitions/border"
82
- },
83
- "bottomRight": {
84
- "$ref": "#/definitions/border"
85
- },
86
- "bodyLeft": {
87
- "$ref": "#/definitions/border"
88
- },
89
- "bodyRight": {
90
- "$ref": "#/definitions/border"
91
- },
92
- "bodyJoin": {
93
- "$ref": "#/definitions/border"
94
- },
95
- "joinBody": {
96
- "$ref": "#/definitions/border"
97
- },
98
- "joinLeft": {
99
- "$ref": "#/definitions/border"
100
- },
101
- "joinRight": {
102
- "$ref": "#/definitions/border"
103
- },
104
- "joinJoin": {
105
- "$ref": "#/definitions/border"
106
- }
107
- },
108
- "additionalProperties": false
109
- },
110
- "border": {
111
- "type": "string"
112
- }
113
- }
19
+ "additionalProperties": false
114
20
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/stringifyTableData.js"],"names":["rows","map","cells","String"],"mappings":";;;;;;;AAAA;;;;;;2BAMgBA,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"}
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.map CHANGED
@@ -1 +1 @@
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;;;;AAIA;;;;AAIA;;;;;;;;;;AAUA;;;;;;;;;;;;;;;;;;;AAmBA;;;;;;;;;;;AAWA;;;;;;;;;AASA;;;;;;;eAOgBA,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
+ {"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 +1 @@
1
- {"version":3,"sources":["../src/truncateTableData.js"],"names":["rows","config","map","cells","content","index","length","columns","truncate"],"mappings":";;;;;;;;;;;AAEA;;;;;;2BAMgBA,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,wBAAWD,OAAX,EAAoB;AACzBE,QAAAA,MAAM,EAAEL,MAAM,CAACM,OAAP,CAAeF,KAAf,EAAsBG;AADL,OAApB,CAAP;AAGD,KAJM,CAAP;AAKD,GANM,CAAP;AAOD,C","sourcesContent":["import _ from 'lodash';\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
+ {"version":3,"sources":["../src/truncateTableData.js"],"names":["rows","config","map","cells","content","index","length","columns","truncate"],"mappings":";;;;;;;;;;;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,wBAAWD,OAAX,EAAoB;AACzBE,QAAAA,MAAM,EAAEL,MAAM,CAACM,OAAP,CAAeF,KAAf,EAAsBG;AADL,OAApB,CAAP;AAGD,KAJM,CAAP;AAKD,GANM,CAAP;AAOD,C","sourcesContent":["import _ from 'lodash';\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"}