table 6.5.1 → 6.7.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.
- package/README.md +407 -434
- package/dist/alignString.d.ts +2 -3
- package/dist/alignString.js +23 -11
- package/dist/alignTableData.d.ts +1 -2
- package/dist/alignTableData.js +7 -14
- package/dist/calculateCellHeight.d.ts +4 -2
- package/dist/calculateCellHeight.js +8 -9
- package/dist/calculateCellWidths.d.ts +5 -0
- package/dist/{calculateCellWidthIndex.js → calculateCellWidths.js} +6 -6
- package/dist/{calculateMaximumColumnWidthIndex.d.ts → calculateColumnWidths.d.ts} +0 -0
- package/dist/calculateColumnWidths.js +16 -0
- package/dist/calculateRowHeights.d.ts +5 -0
- package/dist/calculateRowHeights.js +18 -0
- package/dist/createStream.d.ts +1 -2
- package/dist/createStream.js +29 -30
- package/dist/drawBorder.d.ts +6 -5
- package/dist/drawBorder.js +60 -14
- package/dist/drawContent.d.ts +9 -0
- package/dist/drawContent.js +26 -0
- package/dist/drawHeader.d.ts +2 -0
- package/dist/drawHeader.js +29 -0
- package/dist/drawRow.d.ts +1 -2
- package/dist/drawRow.js +16 -12
- package/dist/drawTable.d.ts +1 -2
- package/dist/drawTable.js +26 -36
- package/dist/generated/validators.d.ts +2 -2
- package/dist/generated/validators.js +657 -307
- package/dist/getBorderCharacters.d.ts +1 -2
- package/dist/getBorderCharacters.js +7 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +6 -9
- package/dist/makeStreamConfig.d.ts +1 -2
- package/dist/makeStreamConfig.js +14 -26
- package/dist/{makeConfig.d.ts → makeTableConfig.d.ts} +1 -2
- package/dist/{makeConfig.js → makeTableConfig.js} +29 -21
- package/dist/mapDataUsingRowHeights.d.ts +2 -0
- package/dist/mapDataUsingRowHeights.js +44 -0
- package/dist/padTableData.d.ts +2 -2
- package/dist/padTableData.js +10 -4
- package/dist/stringifyTableData.d.ts +1 -2
- package/dist/stringifyTableData.js +7 -2
- package/dist/table.d.ts +1 -2
- package/dist/table.js +23 -24
- package/dist/truncateTableData.d.ts +2 -2
- package/dist/truncateTableData.js +10 -6
- package/dist/types/api.d.ts +18 -4
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +92 -0
- package/dist/validateConfig.d.ts +1 -2
- package/dist/validateConfig.js +3 -1
- package/dist/validateTableData.d.ts +1 -2
- package/dist/validateTableData.js +5 -2
- package/dist/wrapCell.d.ts +1 -2
- package/dist/wrapCell.js +9 -24
- package/dist/wrapString.d.ts +1 -2
- package/dist/wrapString.js +3 -1
- package/dist/wrapWord.d.ts +1 -2
- package/dist/wrapWord.js +3 -1
- package/package.json +6 -7
- package/dist/calculateCellWidthIndex.d.ts +0 -6
- package/dist/calculateMaximumColumnWidthIndex.js +0 -24
- package/dist/calculateRowHeightIndex.d.ts +0 -6
- package/dist/calculateRowHeightIndex.js +0 -21
- package/dist/drawHorizontalContent.d.ts +0 -11
- package/dist/drawHorizontalContent.js +0 -18
- package/dist/mapDataUsingRowHeightIndex.d.ts +0 -3
- package/dist/mapDataUsingRowHeightIndex.js +0 -26
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.validateTableData = void 0;
|
|
4
|
+
const utils_1 = require("./utils");
|
|
5
|
+
const validateTableData = (rows) => {
|
|
4
6
|
if (!Array.isArray(rows)) {
|
|
5
7
|
throw new TypeError('Table data must be an array.');
|
|
6
8
|
}
|
|
@@ -20,9 +22,10 @@ exports.default = (rows) => {
|
|
|
20
22
|
}
|
|
21
23
|
for (const cell of row) {
|
|
22
24
|
// eslint-disable-next-line no-control-regex
|
|
23
|
-
if (/[\u0001-\u0006\u0008\u0009\u000B-\u001A]/.test(cell)) {
|
|
25
|
+
if (/[\u0001-\u0006\u0008\u0009\u000B-\u001A]/.test(utils_1.normalizeString(String(cell)))) {
|
|
24
26
|
throw new Error('Table data must not contain control characters.');
|
|
25
27
|
}
|
|
26
28
|
}
|
|
27
29
|
}
|
|
28
30
|
};
|
|
31
|
+
exports.validateTableData = validateTableData;
|
package/dist/wrapCell.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
declare const _default: (cellValue: string, columnWidth: number, useWrapWord: boolean) => string[];
|
|
2
1
|
/**
|
|
3
2
|
* Wrap a single cell value into a list of lines
|
|
4
3
|
*
|
|
@@ -6,4 +5,4 @@ declare const _default: (cellValue: string, columnWidth: number, useWrapWord: bo
|
|
|
6
5
|
* depending on user configuration.
|
|
7
6
|
*
|
|
8
7
|
*/
|
|
9
|
-
export
|
|
8
|
+
export declare const wrapCell: (cellValue: string, cellWidth: number, useWrapWord: boolean) => string[];
|
package/dist/wrapCell.js
CHANGED
|
@@ -1,25 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const wrapString_1 =
|
|
9
|
-
const wrapWord_1 =
|
|
10
|
-
const splitAnsi = (input) => {
|
|
11
|
-
const lengths = strip_ansi_1.default(input).split('\n').map(({ length }) => {
|
|
12
|
-
return length;
|
|
13
|
-
});
|
|
14
|
-
const result = [];
|
|
15
|
-
let startIndex = 0;
|
|
16
|
-
lengths.forEach((length) => {
|
|
17
|
-
result.push(length === 0 ? '' : slice_ansi_1.default(input, startIndex, startIndex + length));
|
|
18
|
-
// Plus 1 for the newline character itself
|
|
19
|
-
startIndex += length + 1;
|
|
20
|
-
});
|
|
21
|
-
return result;
|
|
22
|
-
};
|
|
3
|
+
exports.wrapCell = void 0;
|
|
4
|
+
const utils_1 = require("./utils");
|
|
5
|
+
const wrapString_1 = require("./wrapString");
|
|
6
|
+
const wrapWord_1 = require("./wrapWord");
|
|
23
7
|
/**
|
|
24
8
|
* Wrap a single cell value into a list of lines
|
|
25
9
|
*
|
|
@@ -27,17 +11,17 @@ const splitAnsi = (input) => {
|
|
|
27
11
|
* depending on user configuration.
|
|
28
12
|
*
|
|
29
13
|
*/
|
|
30
|
-
|
|
14
|
+
const wrapCell = (cellValue, cellWidth, useWrapWord) => {
|
|
31
15
|
// First split on literal newlines
|
|
32
|
-
const cellLines = splitAnsi(cellValue);
|
|
16
|
+
const cellLines = utils_1.splitAnsi(cellValue);
|
|
33
17
|
// Then iterate over the list and word-wrap every remaining line if necessary.
|
|
34
18
|
for (let lineNr = 0; lineNr < cellLines.length;) {
|
|
35
19
|
let lineChunks;
|
|
36
20
|
if (useWrapWord) {
|
|
37
|
-
lineChunks = wrapWord_1.
|
|
21
|
+
lineChunks = wrapWord_1.wrapWord(cellLines[lineNr], cellWidth);
|
|
38
22
|
}
|
|
39
23
|
else {
|
|
40
|
-
lineChunks = wrapString_1.
|
|
24
|
+
lineChunks = wrapString_1.wrapString(cellLines[lineNr], cellWidth);
|
|
41
25
|
}
|
|
42
26
|
// Replace our original array element with whatever the wrapping returned
|
|
43
27
|
cellLines.splice(lineNr, 1, ...lineChunks);
|
|
@@ -45,3 +29,4 @@ exports.default = (cellValue, columnWidth, useWrapWord) => {
|
|
|
45
29
|
}
|
|
46
30
|
return cellLines;
|
|
47
31
|
};
|
|
32
|
+
exports.wrapCell = wrapCell;
|
package/dist/wrapString.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
declare const _default: (subject: string, size: number) => string[];
|
|
2
1
|
/**
|
|
3
2
|
* Creates an array of strings split into groups the length of size.
|
|
4
3
|
* This function works with strings that contain ASCII characters.
|
|
@@ -7,4 +6,4 @@ declare const _default: (subject: string, size: number) => string[];
|
|
|
7
6
|
* in that whitespace characters that occur on a chunk size limit are trimmed.
|
|
8
7
|
*
|
|
9
8
|
*/
|
|
10
|
-
export
|
|
9
|
+
export declare const wrapString: (subject: string, size: number) => string[];
|
package/dist/wrapString.js
CHANGED
|
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.wrapString = void 0;
|
|
6
7
|
const slice_ansi_1 = __importDefault(require("slice-ansi"));
|
|
7
8
|
const string_width_1 = __importDefault(require("string-width"));
|
|
8
9
|
/**
|
|
@@ -13,7 +14,7 @@ const string_width_1 = __importDefault(require("string-width"));
|
|
|
13
14
|
* in that whitespace characters that occur on a chunk size limit are trimmed.
|
|
14
15
|
*
|
|
15
16
|
*/
|
|
16
|
-
|
|
17
|
+
const wrapString = (subject, size) => {
|
|
17
18
|
let subjectSlice = subject;
|
|
18
19
|
const chunks = [];
|
|
19
20
|
do {
|
|
@@ -22,3 +23,4 @@ exports.default = (subject, size) => {
|
|
|
22
23
|
} while (string_width_1.default(subjectSlice));
|
|
23
24
|
return chunks;
|
|
24
25
|
};
|
|
26
|
+
exports.wrapString = wrapString;
|
package/dist/wrapWord.d.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
declare const
|
|
2
|
-
export default _default;
|
|
1
|
+
export declare const wrapWord: (input: string, size: number) => string[];
|
package/dist/wrapWord.js
CHANGED
|
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.wrapWord = void 0;
|
|
6
7
|
const slice_ansi_1 = __importDefault(require("slice-ansi"));
|
|
7
8
|
const strip_ansi_1 = __importDefault(require("strip-ansi"));
|
|
8
9
|
const calculateStringLengths = (input, size) => {
|
|
@@ -28,7 +29,7 @@ const calculateStringLengths = (input, size) => {
|
|
|
28
29
|
} while (subject.length);
|
|
29
30
|
return chunks;
|
|
30
31
|
};
|
|
31
|
-
|
|
32
|
+
const wrapWord = (input, size) => {
|
|
32
33
|
const result = [];
|
|
33
34
|
let startIndex = 0;
|
|
34
35
|
calculateStringLengths(input, size).forEach(([length, offset]) => {
|
|
@@ -37,3 +38,4 @@ exports.default = (input, size) => {
|
|
|
37
38
|
});
|
|
38
39
|
return result;
|
|
39
40
|
};
|
|
41
|
+
exports.wrapWord = wrapWord;
|
package/package.json
CHANGED
|
@@ -7,17 +7,15 @@
|
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"ajv": "^8.0.1",
|
|
9
9
|
"lodash.clonedeep": "^4.5.0",
|
|
10
|
-
"lodash.flatten": "^4.4.0",
|
|
11
10
|
"lodash.truncate": "^4.4.2",
|
|
12
11
|
"slice-ansi": "^4.0.0",
|
|
13
|
-
"string-width": "^4.2.
|
|
14
|
-
"strip-ansi": "^6.0.
|
|
12
|
+
"string-width": "^4.2.3",
|
|
13
|
+
"strip-ansi": "^6.0.1"
|
|
15
14
|
},
|
|
16
15
|
"description": "Formats data into a string table.",
|
|
17
16
|
"devDependencies": {
|
|
18
17
|
"@types/chai": "^4.2.16",
|
|
19
18
|
"@types/lodash.clonedeep": "^4.5.6",
|
|
20
|
-
"@types/lodash.flatten": "^4.4.6",
|
|
21
19
|
"@types/lodash.mapvalues": "^4.6.6",
|
|
22
20
|
"@types/lodash.truncate": "^4.4.6",
|
|
23
21
|
"@types/mocha": "^8.2.2",
|
|
@@ -75,7 +73,8 @@
|
|
|
75
73
|
"test/**/*.ts"
|
|
76
74
|
],
|
|
77
75
|
"reporter": [
|
|
78
|
-
"text-lcov"
|
|
76
|
+
"text-lcov",
|
|
77
|
+
"text"
|
|
79
78
|
]
|
|
80
79
|
},
|
|
81
80
|
"repository": {
|
|
@@ -89,7 +88,7 @@
|
|
|
89
88
|
"create-readme": "gitdown ./.README/README.md --output-file ./README.md",
|
|
90
89
|
"create-validators": "rm -fr ./src/generated && mkdirp ./src/generated && ajv compile --all-errors --inline-refs=false -s src/schemas/config -s src/schemas/streamConfig -r src/schemas/shared -c ajv-keywords/dist/keywords/typeof -o | js-beautify > ./src/generated/validators.js",
|
|
91
90
|
"lint": "eslint --ignore-path .gitignore ./src ./test",
|
|
92
|
-
"test": "npm run create-validators && mocha --require ts-node/register ./test/**/*.ts"
|
|
91
|
+
"test": "npm run create-validators && mocha --require ts-node/register \"./test/**/*.ts\""
|
|
93
92
|
},
|
|
94
|
-
"version": "6.
|
|
93
|
+
"version": "6.7.2"
|
|
95
94
|
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const calculateCellWidthIndex_1 = __importDefault(require("./calculateCellWidthIndex"));
|
|
7
|
-
/**
|
|
8
|
-
* Produces an array of values that describe the largest value length (width) in every column.
|
|
9
|
-
*/
|
|
10
|
-
exports.default = (rows) => {
|
|
11
|
-
if (!rows[0]) {
|
|
12
|
-
throw new Error('Dataset must have at least one row.');
|
|
13
|
-
}
|
|
14
|
-
const columns = new Array(rows[0].length).fill(0);
|
|
15
|
-
rows.forEach((row) => {
|
|
16
|
-
const columnWidthIndex = calculateCellWidthIndex_1.default(row);
|
|
17
|
-
columnWidthIndex.forEach((valueWidth, index0) => {
|
|
18
|
-
if (columns[index0] < valueWidth) {
|
|
19
|
-
columns[index0] = valueWidth;
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
return columns;
|
|
24
|
-
};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const calculateCellHeight_1 = __importDefault(require("./calculateCellHeight"));
|
|
7
|
-
/**
|
|
8
|
-
* Calculates the vertical row span index.
|
|
9
|
-
*/
|
|
10
|
-
exports.default = (rows, config) => {
|
|
11
|
-
const tableWidth = rows[0].length;
|
|
12
|
-
const rowSpanIndex = [];
|
|
13
|
-
rows.forEach((cells) => {
|
|
14
|
-
const cellHeightIndex = new Array(tableWidth).fill(1);
|
|
15
|
-
cells.forEach((value, index1) => {
|
|
16
|
-
cellHeightIndex[index1] = calculateCellHeight_1.default(value, config.columns[index1].width, config.columns[index1].wrapWord);
|
|
17
|
-
});
|
|
18
|
-
rowSpanIndex.push(Math.max(...cellHeightIndex));
|
|
19
|
-
});
|
|
20
|
-
return rowSpanIndex;
|
|
21
|
-
};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { DrawVerticalLine } from './types/api';
|
|
2
|
-
declare type Separator = {
|
|
3
|
-
readonly left: string;
|
|
4
|
-
readonly right: string;
|
|
5
|
-
readonly join: string;
|
|
6
|
-
};
|
|
7
|
-
export default function drawHorizontalContent(contents: string[], config: {
|
|
8
|
-
separator: Separator;
|
|
9
|
-
drawVerticalLine: DrawVerticalLine;
|
|
10
|
-
}): string;
|
|
11
|
-
export {};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
function drawHorizontalContent(contents, config) {
|
|
4
|
-
const { separator, drawVerticalLine } = config;
|
|
5
|
-
const contentSize = contents.length;
|
|
6
|
-
const result = [];
|
|
7
|
-
result.push(drawVerticalLine(0, contentSize) ? separator.left : '');
|
|
8
|
-
contents.forEach((content, index) => {
|
|
9
|
-
result.push(content);
|
|
10
|
-
// Only append the join separator if it is not the last content
|
|
11
|
-
if (index + 1 < contentSize) {
|
|
12
|
-
result.push(drawVerticalLine(index + 1, contentSize) ? separator.join : '');
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
result.push(drawVerticalLine(contentSize, contentSize) ? separator.right : '');
|
|
16
|
-
return result.join('') + '\n';
|
|
17
|
-
}
|
|
18
|
-
exports.default = drawHorizontalContent;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const lodash_flatten_1 = __importDefault(require("lodash.flatten"));
|
|
7
|
-
const wrapCell_1 = __importDefault(require("./wrapCell"));
|
|
8
|
-
exports.default = (unmappedRows, rowHeightIndex, config) => {
|
|
9
|
-
const tableWidth = unmappedRows[0].length;
|
|
10
|
-
const mappedRows = unmappedRows.map((row, index0) => {
|
|
11
|
-
const rowHeight = Array.from({ length: rowHeightIndex[index0] }, () => {
|
|
12
|
-
return new Array(tableWidth).fill('');
|
|
13
|
-
});
|
|
14
|
-
// rowHeight
|
|
15
|
-
// [{row index within rowSaw; index2}]
|
|
16
|
-
// [{cell index within a virtual row; index1}]
|
|
17
|
-
row.forEach((cell, index1) => {
|
|
18
|
-
const cellLines = wrapCell_1.default(cell, config.columns[index1].width, config.columns[index1].wrapWord);
|
|
19
|
-
cellLines.forEach((cellLine, index2) => {
|
|
20
|
-
rowHeight[index2][index1] = cellLine;
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
return rowHeight;
|
|
24
|
-
});
|
|
25
|
-
return lodash_flatten_1.default(mappedRows);
|
|
26
|
-
};
|