table 6.0.2 → 6.0.6
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.
- package/README.md +3 -2
- package/dist/alignString.js +7 -3
- package/dist/alignString.js.flow +4 -3
- package/dist/alignString.js.map +1 -1
- package/dist/alignTableData.js.map +1 -1
- package/dist/calculateCellHeight.js +3 -1
- package/dist/calculateCellHeight.js.flow +2 -1
- package/dist/calculateCellHeight.js.map +1 -1
- package/dist/calculateCellWidthIndex.js.map +1 -1
- package/dist/calculateMaximumColumnWidthIndex.js.map +1 -1
- package/dist/calculateRowHeightIndex.js +9 -3
- package/dist/calculateRowHeightIndex.js.flow +4 -3
- package/dist/calculateRowHeightIndex.js.map +1 -1
- package/dist/createStream.js +4 -2
- package/dist/createStream.js.flow +3 -2
- package/dist/createStream.js.map +1 -1
- package/dist/drawBorder.js.map +1 -1
- package/dist/drawRow.js.map +1 -1
- package/dist/drawTable.js.map +1 -1
- package/dist/getBorderCharacters.js.map +1 -1
- package/dist/index.js +3 -3
- package/dist/makeConfig.js +11 -15
- package/dist/makeConfig.js.flow +6 -5
- package/dist/makeConfig.js.map +1 -1
- package/dist/makeStreamConfig.js +11 -15
- package/dist/makeStreamConfig.js.flow +6 -7
- package/dist/makeStreamConfig.js.map +1 -1
- package/dist/mapDataUsingRowHeightIndex.js +7 -6
- package/dist/mapDataUsingRowHeightIndex.js.flow +3 -3
- package/dist/mapDataUsingRowHeightIndex.js.map +1 -1
- package/dist/padTableData.js.map +1 -1
- package/dist/schemas/config.json +4 -98
- package/dist/schemas/shared.json +98 -0
- package/dist/schemas/streamConfig.json +4 -98
- package/dist/stringifyTableData.js.map +1 -1
- package/dist/table.js.map +1 -1
- package/dist/truncateTableData.js +7 -6
- package/dist/truncateTableData.js.flow +4 -4
- package/dist/truncateTableData.js.map +1 -1
- package/dist/validateConfig.js +40 -751
- package/dist/validateConfig.js.flow +4 -10
- package/dist/validateConfig.js.map +1 -1
- package/dist/validateTableData.js +11 -39
- package/dist/validateTableData.js.map +1 -1
- package/dist/validators.js +1472 -0
- package/dist/wrapCell.js.map +1 -1
- package/dist/wrapString.js.map +1 -1
- package/dist/wrapWord.js.map +1 -1
- package/package.json +22 -19
- package/dist/validateStreamConfig.js +0 -741
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _ from 'lodash';
|
|
1
2
|
import getBorderCharacters from './getBorderCharacters';
|
|
2
3
|
import validateConfig from './validateConfig';
|
|
3
4
|
|
|
@@ -21,10 +22,8 @@ const makeBorder = (border = {}) => {
|
|
|
21
22
|
* @returns {object}
|
|
22
23
|
*/
|
|
23
24
|
const makeColumns = (columnCount, columns = {}, columnDefault = {}) => {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
while (index--) {
|
|
27
|
-
if (!columns[index]) {
|
|
25
|
+
_.times(columnCount, (index) => {
|
|
26
|
+
if (_.isUndefined(columns[index])) {
|
|
28
27
|
columns[index] = {};
|
|
29
28
|
}
|
|
30
29
|
|
|
@@ -32,10 +31,10 @@ const makeColumns = (columnCount, columns = {}, columnDefault = {}) => {
|
|
|
32
31
|
alignment: 'left',
|
|
33
32
|
paddingLeft: 1,
|
|
34
33
|
paddingRight: 1,
|
|
35
|
-
truncate:
|
|
34
|
+
truncate: Number.POSITIVE_INFINITY,
|
|
36
35
|
wrapWord: false,
|
|
37
36
|
}, columnDefault, columns[index]);
|
|
38
|
-
}
|
|
37
|
+
});
|
|
39
38
|
|
|
40
39
|
return columns;
|
|
41
40
|
};
|
|
@@ -67,7 +66,7 @@ const makeColumns = (columnCount, columns = {}, columnDefault = {}) => {
|
|
|
67
66
|
export default (userConfig = {}) => {
|
|
68
67
|
validateConfig('streamConfig.json', userConfig);
|
|
69
68
|
|
|
70
|
-
const config =
|
|
69
|
+
const config = _.cloneDeep(userConfig);
|
|
71
70
|
|
|
72
71
|
if (!config.columnDefault || !config.columnDefault.width) {
|
|
73
72
|
throw new Error('Must provide config.columnDefault.width when creating a stream.');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/makeStreamConfig.js"],"names":["makeBorder","border","Object","assign","makeColumns","columnCount","columns","columnDefault","index","alignment","paddingLeft","paddingRight","truncate","
|
|
1
|
+
{"version":3,"sources":["../src/makeStreamConfig.js"],"names":["makeBorder","border","Object","assign","makeColumns","columnCount","columns","columnDefault","index","alignment","paddingLeft","paddingRight","truncate","Number","POSITIVE_INFINITY","wrapWord","userConfig","config","width","Error"],"mappings":";;;;;;;;;;;;;AACA;;AACA;;;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,UAAU,GAAG,CAACC,MAAM,GAAG,EAAV,KAAiB;AAClC,SAAOC,MAAM,CAACC,MAAP,CAAc,EAAd,EAAkB,kCAAoB,WAApB,CAAlB,EAAoDF,MAApD,CAAP;AACD,CAFD;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,MAAMG,WAAW,GAAG,CAACC,WAAD,EAAcC,OAAO,GAAG,EAAxB,EAA4BC,aAAa,GAAG,EAA5C,KAAmD;AACrE,uBAAQF,WAAR,EAAsBG,KAAD,IAAW;AAC9B,QAAI,2BAAcF,OAAO,CAACE,KAAD,CAArB,CAAJ,EAAmC;AACjCF,MAAAA,OAAO,CAACE,KAAD,CAAP,GAAiB,EAAjB;AACD;;AAEDF,IAAAA,OAAO,CAACE,KAAD,CAAP,GAAiBN,MAAM,CAACC,MAAP,CAAc;AAC7BM,MAAAA,SAAS,EAAE,MADkB;AAE7BC,MAAAA,WAAW,EAAE,CAFgB;AAG7BC,MAAAA,YAAY,EAAE,CAHe;AAI7BC,MAAAA,QAAQ,EAAEC,MAAM,CAACC,iBAJY;AAK7BC,MAAAA,QAAQ,EAAE;AALmB,KAAd,EAMdR,aANc,EAMCD,OAAO,CAACE,KAAD,CANR,CAAjB;AAOD,GAZD;AAcA,SAAOF,OAAP;AACD,CAhBD;AAkBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;;0BACgBU,UAAU,GAAG,E,KAAO;AAClC,+BAAe,mBAAf,EAAoCA,UAApC;AAEA,QAAMC,MAAM,GAAG,yBAAYD,UAAZ,CAAf;;AAEA,MAAI,CAACC,MAAM,CAACV,aAAR,IAAyB,CAACU,MAAM,CAACV,aAAP,CAAqBW,KAAnD,EAA0D;AACxD,UAAM,IAAIC,KAAJ,CAAU,iEAAV,CAAN;AACD;;AAED,MAAI,CAACF,MAAM,CAACZ,WAAZ,EAAyB;AACvB,UAAM,IAAIc,KAAJ,CAAU,kCAAV,CAAN;AACD;;AAEDF,EAAAA,MAAM,CAAChB,MAAP,GAAgBD,UAAU,CAACiB,MAAM,CAAChB,MAAR,CAA1B;AACAgB,EAAAA,MAAM,CAACX,OAAP,GAAiBF,WAAW,CAACa,MAAM,CAACZ,WAAR,EAAqBY,MAAM,CAACX,OAA5B,EAAqCW,MAAM,CAACV,aAA5C,CAA5B;AAEA,SAAOU,MAAP;AACD,C","sourcesContent":["import _ from 'lodash';\nimport getBorderCharacters from './getBorderCharacters';\nimport validateConfig from './validateConfig';\n\n/**\n * Merges user provided border characters with the default border (\"honeywell\") characters.\n *\n * @param {object} border\n * @returns {object}\n */\nconst makeBorder = (border = {}) => {\n return Object.assign({}, getBorderCharacters('honeywell'), border);\n};\n\n/**\n * Creates a configuration for every column using default\n * values for the missing configuration properties.\n *\n * @param {number} columnCount\n * @param {object} columns\n * @param {object} columnDefault\n * @returns {object}\n */\nconst makeColumns = (columnCount, columns = {}, columnDefault = {}) => {\n _.times(columnCount, (index) => {\n if (_.isUndefined(columns[index])) {\n columns[index] = {};\n }\n\n columns[index] = Object.assign({\n alignment: 'left',\n paddingLeft: 1,\n paddingRight: 1,\n truncate: Number.POSITIVE_INFINITY,\n wrapWord: false,\n }, columnDefault, columns[index]);\n });\n\n return columns;\n};\n\n/**\n * @typedef {object} columnConfig\n * @property {string} alignment\n * @property {number} width\n * @property {number} truncate\n * @property {number} paddingLeft\n * @property {number} paddingRight\n */\n\n/**\n * @typedef {object} streamConfig\n * @property {columnConfig} columnDefault\n * @property {object} border\n * @property {columnConfig[]}\n * @property {number} columnCount Number of columns in the table (required).\n */\n\n/**\n * Makes a new configuration object out of the userConfig object\n * using default values for the missing configuration properties.\n *\n * @param {streamConfig} userConfig\n * @returns {object}\n */\nexport default (userConfig = {}) => {\n validateConfig('streamConfig.json', userConfig);\n\n const config = _.cloneDeep(userConfig);\n\n if (!config.columnDefault || !config.columnDefault.width) {\n throw new Error('Must provide config.columnDefault.width when creating a stream.');\n }\n\n if (!config.columnCount) {\n throw new Error('Must provide config.columnCount.');\n }\n\n config.border = makeBorder(config.border);\n config.columns = makeColumns(config.columnCount, config.columns, config.columnDefault);\n\n return config;\n};\n"],"file":"makeStreamConfig.js"}
|
|
@@ -5,6 +5,10 @@ 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"));
|
|
11
|
+
|
|
8
12
|
var _wrapCell = _interopRequireDefault(require("./wrapCell"));
|
|
9
13
|
|
|
10
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -18,9 +22,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
18
22
|
const mapDataUsingRowHeightIndex = (unmappedRows, rowHeightIndex, config) => {
|
|
19
23
|
const tableWidth = unmappedRows[0].length;
|
|
20
24
|
const mappedRows = unmappedRows.map((cells, index0) => {
|
|
21
|
-
const rowHeight =
|
|
22
|
-
length: rowHeightIndex[index0]
|
|
23
|
-
}, () => {
|
|
25
|
+
const rowHeight = (0, _times2.default)(rowHeightIndex[index0], () => {
|
|
24
26
|
return new Array(tableWidth).fill('');
|
|
25
27
|
}); // rowHeight
|
|
26
28
|
// [{row index within rowSaw; index2}]
|
|
@@ -33,9 +35,8 @@ const mapDataUsingRowHeightIndex = (unmappedRows, rowHeightIndex, config) => {
|
|
|
33
35
|
});
|
|
34
36
|
});
|
|
35
37
|
return rowHeight;
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
return [].concat(...mappedRows);
|
|
38
|
+
});
|
|
39
|
+
return (0, _flatten2.default)(mappedRows);
|
|
39
40
|
};
|
|
40
41
|
|
|
41
42
|
var _default = mapDataUsingRowHeightIndex;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _ from 'lodash';
|
|
1
2
|
import wrapCell from './wrapCell';
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -10,7 +11,7 @@ export default (unmappedRows, rowHeightIndex, config) => {
|
|
|
10
11
|
const tableWidth = unmappedRows[0].length;
|
|
11
12
|
|
|
12
13
|
const mappedRows = unmappedRows.map((cells, index0) => {
|
|
13
|
-
const rowHeight =
|
|
14
|
+
const rowHeight = _.times(rowHeightIndex[index0], () => {
|
|
14
15
|
return new Array(tableWidth).fill('');
|
|
15
16
|
});
|
|
16
17
|
|
|
@@ -29,6 +30,5 @@ export default (unmappedRows, rowHeightIndex, config) => {
|
|
|
29
30
|
return rowHeight;
|
|
30
31
|
});
|
|
31
32
|
|
|
32
|
-
|
|
33
|
-
return [].concat(...mappedRows);
|
|
33
|
+
return _.flatten(mappedRows);
|
|
34
34
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/mapDataUsingRowHeightIndex.js"],"names":["unmappedRows","rowHeightIndex","config","tableWidth","length","mappedRows","map","cells","index0","rowHeight","Array","
|
|
1
|
+
{"version":3,"sources":["../src/mapDataUsingRowHeightIndex.js"],"names":["unmappedRows","rowHeightIndex","config","tableWidth","length","mappedRows","map","cells","index0","rowHeight","Array","fill","forEach","value","index1","cellLines","columns","width","wrapWord","cellLine","index2"],"mappings":";;;;;;;;;;;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,GAAG,qBAAQR,cAAc,CAACO,MAAD,CAAtB,EAAgC,MAAM;AACtD,aAAO,IAAIE,KAAJ,CAAUP,UAAV,EAAsBQ,IAAtB,CAA2B,EAA3B,CAAP;AACD,KAFiB,CAAlB,CADqD,CAKrD;AACA;AACA;;AAEAJ,IAAAA,KAAK,CAACK,OAAN,CAAc,CAACC,KAAD,EAAQC,MAAR,KAAmB;AAC/B,YAAMC,SAAS,GAAG,uBAASF,KAAT,EAAgBX,MAAM,CAACc,OAAP,CAAeF,MAAf,EAAuBG,KAAvC,EAA8Cf,MAAM,CAACc,OAAP,CAAeF,MAAf,EAAuBI,QAArE,CAAlB;AAEAH,MAAAA,SAAS,CAACH,OAAV,CAAkB,CAACO,QAAD,EAAWC,MAAX,KAAsB;AACtCX,QAAAA,SAAS,CAACW,MAAD,CAAT,CAAkBN,MAAlB,IAA4BK,QAA5B;AACD,OAFD;AAGD,KAND;AAQA,WAAOV,SAAP;AACD,GAlBkB,CAAnB;AAoBA,SAAO,uBAAUJ,UAAV,CAAP;AACD,C","sourcesContent":["import _ from 'lodash';\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 = _.times(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"}
|
package/dist/padTableData.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/padTableData.js"],"names":["rows","config","map","cells","value","index1","column","columns","repeat","paddingLeft","paddingRight"],"mappings":";;;;;;;AAAA
|
|
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"}
|
package/dist/schemas/config.json
CHANGED
|
@@ -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
|
"drawHorizontalLine": {
|
|
16
16
|
"typeof": "function"
|
|
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
|
}
|
|
@@ -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
|
|
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
|
|
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"}
|
|
@@ -5,21 +5,22 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
8
|
+
var _truncate2 = _interopRequireDefault(require("lodash/truncate"));
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
|
|
11
12
|
/**
|
|
12
13
|
* @todo Make it work with ASCII content.
|
|
13
14
|
* @param {table~row[]} rows
|
|
14
15
|
* @param {object} config
|
|
15
16
|
* @returns {table~row[]}
|
|
16
17
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
18
|
const truncateTableData = (rows, config) => {
|
|
20
19
|
return rows.map(cells => {
|
|
21
20
|
return cells.map((content, index) => {
|
|
22
|
-
return
|
|
21
|
+
return (0, _truncate2.default)(content, {
|
|
22
|
+
length: config.columns[index].truncate
|
|
23
|
+
});
|
|
23
24
|
});
|
|
24
25
|
});
|
|
25
26
|
};
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
return string.length > length ? string.slice(0, Math.max(0, length - 3)) + '...' : string;
|
|
3
|
-
};
|
|
1
|
+
import _ from 'lodash';
|
|
4
2
|
|
|
5
3
|
/**
|
|
6
4
|
* @todo Make it work with ASCII content.
|
|
@@ -11,7 +9,9 @@ const truncate = (string, length) => {
|
|
|
11
9
|
export default (rows, config) => {
|
|
12
10
|
return rows.map((cells) => {
|
|
13
11
|
return cells.map((content, index) => {
|
|
14
|
-
return truncate(content,
|
|
12
|
+
return _.truncate(content, {
|
|
13
|
+
length: config.columns[index].truncate,
|
|
14
|
+
});
|
|
15
15
|
});
|
|
16
16
|
});
|
|
17
17
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/truncateTableData.js"],"names":["
|
|
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"}
|