table 6.9.4 → 6.9.5
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.
|
@@ -5,14 +5,28 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.truncateTableData = exports.truncateString = void 0;
|
|
7
7
|
const lodash_truncate_1 = __importDefault(require("lodash.truncate"));
|
|
8
|
+
const slice_ansi_1 = __importDefault(require("slice-ansi"));
|
|
9
|
+
const strip_ansi_1 = __importDefault(require("strip-ansi"));
|
|
10
|
+
const utils_1 = require("./utils");
|
|
11
|
+
const omission = '…';
|
|
8
12
|
const truncateString = (input, length) => {
|
|
9
|
-
|
|
10
|
-
|
|
13
|
+
// Not even the escape codes and the text together exceed the length.
|
|
14
|
+
if (input.length <= length) {
|
|
15
|
+
return input;
|
|
16
|
+
}
|
|
17
|
+
// Truncate the visible text, so that ANSI escape codes do not count towards the length.
|
|
18
|
+
const visible = (0, strip_ansi_1.default)(input);
|
|
19
|
+
const truncated = (0, lodash_truncate_1.default)(visible, { length,
|
|
20
|
+
omission });
|
|
21
|
+
if (truncated === visible) {
|
|
22
|
+
return input;
|
|
23
|
+
}
|
|
24
|
+
// Cut the input after the same characters, which keeps its ANSI escape codes and closes any that
|
|
25
|
+
// are still open, so that styles do not leak past the cell.
|
|
26
|
+
const kept = truncated.slice(0, -omission.length);
|
|
27
|
+
return (0, slice_ansi_1.default)(input, 0, (0, utils_1.calculateSliceLength)(kept, Number.POSITIVE_INFINITY)) + omission;
|
|
11
28
|
};
|
|
12
29
|
exports.truncateString = truncateString;
|
|
13
|
-
/**
|
|
14
|
-
* @todo Make it work with ASCII content.
|
|
15
|
-
*/
|
|
16
30
|
const truncateTableData = (rows, truncates) => {
|
|
17
31
|
return rows.map((cells) => {
|
|
18
32
|
return cells.map((cell, cellIndex) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"truncateTableData.js","sourceRoot":"","sources":["../../src/truncateTableData.ts"],"names":[],"mappings":";;;;;;AAAA,sEAAuC;
|
|
1
|
+
{"version":3,"file":"truncateTableData.js","sourceRoot":"","sources":["../../src/truncateTableData.ts"],"names":[],"mappings":";;;;;;AAAA,sEAAuC;AACvC,4DAA+B;AAC/B,4DAAmC;AAInC,mCAEiB;AAEjB,MAAM,QAAQ,GAAG,GAAG,CAAC;AAEd,MAAM,cAAc,GAAG,CAAC,KAAa,EAAE,MAAc,EAAU,EAAE;IACtE,qEAAqE;IACrE,IAAI,KAAK,CAAC,MAAM,IAAI,MAAM,EAAE;QAC1B,OAAO,KAAK,CAAC;KACd;IAED,wFAAwF;IACxF,MAAM,OAAO,GAAG,IAAA,oBAAS,EAAC,KAAK,CAAC,CAAC;IACjC,MAAM,SAAS,GAAG,IAAA,yBAAQ,EAAC,OAAO,EAAE,EAAC,MAAM;QACzC,QAAQ,EAAC,CAAC,CAAC;IAEb,IAAI,SAAS,KAAK,OAAO,EAAE;QACzB,OAAO,KAAK,CAAC;KACd;IAED,iGAAiG;IACjG,4DAA4D;IAC5D,MAAM,IAAI,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAElD,OAAO,IAAA,oBAAK,EAAC,KAAK,EAAE,CAAC,EAAE,IAAA,4BAAoB,EAAC,IAAI,EAAE,MAAM,CAAC,iBAAiB,CAAC,CAAC,GAAG,QAAQ,CAAC;AAC1F,CAAC,CAAC;AApBW,QAAA,cAAc,kBAoBzB;AAEK,MAAM,iBAAiB,GAAG,CAAC,IAAW,EAAE,SAAmB,EAAS,EAAE;IAC3E,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;QACxB,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,SAAS,EAAE,EAAE;YACnC,OAAO,IAAA,sBAAc,EAAC,IAAI,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC;QACpD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AANW,QAAA,iBAAiB,qBAM5B"}
|
package/package.json
CHANGED