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 | exports.isCellInRange = exports.areCellEqual = exports.calculateRangeCoordinate = exports.findOriginalRowIndex = exports.flatten = exports.extractTruncates = exports.sumArray = exports.sequence = exports.distributeUnevenly = exports.countSpaceSequence = exports.groupBySizes = exports.makeBorderConfig = exports.splitAnsi = exports.normalizeString = void 0;
|
7 | const slice_ansi_1 = __importDefault(require("slice-ansi"));
|
8 | const string_width_1 = __importDefault(require("string-width"));
|
9 | const strip_ansi_1 = __importDefault(require("strip-ansi"));
|
10 | const getBorderCharacters_1 = require("./getBorderCharacters");
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | const normalizeString = (input) => {
|
17 | return input.replace(/\r\n/g, '\n');
|
18 | };
|
19 | exports.normalizeString = normalizeString;
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | const splitAnsi = (input) => {
|
26 | const lengths = (0, strip_ansi_1.default)(input).split('\n').map(string_width_1.default);
|
27 | const result = [];
|
28 | let startIndex = 0;
|
29 | lengths.forEach((length) => {
|
30 | result.push(length === 0 ? '' : (0, slice_ansi_1.default)(input, startIndex, startIndex + length));
|
31 |
|
32 | startIndex += length + 1;
|
33 | });
|
34 | return result;
|
35 | };
|
36 | exports.splitAnsi = splitAnsi;
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 | const makeBorderConfig = (border) => {
|
43 | return {
|
44 | ...(0, getBorderCharacters_1.getBorderCharacters)('honeywell'),
|
45 | ...border,
|
46 | };
|
47 | };
|
48 | exports.makeBorderConfig = makeBorderConfig;
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 | const groupBySizes = (array, sizes) => {
|
57 | let startIndex = 0;
|
58 | return sizes.map((size) => {
|
59 | const group = array.slice(startIndex, startIndex + size);
|
60 | startIndex += size;
|
61 | return group;
|
62 | });
|
63 | };
|
64 | exports.groupBySizes = groupBySizes;
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 | const countSpaceSequence = (input) => {
|
73 | var _a, _b;
|
74 | return (_b = (_a = input.match(/\s+/g)) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
|
75 | };
|
76 | exports.countSpaceSequence = countSpaceSequence;
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 | const distributeUnevenly = (sum, length) => {
|
87 | const result = Array.from({ length }).fill(Math.floor(sum / length));
|
88 | return result.map((element, index) => {
|
89 | return element + (index < sum % length ? 1 : 0);
|
90 | });
|
91 | };
|
92 | exports.distributeUnevenly = distributeUnevenly;
|
93 | const sequence = (start, end) => {
|
94 | return Array.from({ length: end - start + 1 }, (_, index) => {
|
95 | return index + start;
|
96 | });
|
97 | };
|
98 | exports.sequence = sequence;
|
99 | const sumArray = (array) => {
|
100 | return array.reduce((accumulator, element) => {
|
101 | return accumulator + element;
|
102 | }, 0);
|
103 | };
|
104 | exports.sumArray = sumArray;
|
105 | const extractTruncates = (config) => {
|
106 | return config.columns.map(({ truncate }) => {
|
107 | return truncate;
|
108 | });
|
109 | };
|
110 | exports.extractTruncates = extractTruncates;
|
111 | const flatten = (array) => {
|
112 | return [].concat(...array);
|
113 | };
|
114 | exports.flatten = flatten;
|
115 | const findOriginalRowIndex = (mappedRowHeights, mappedRowIndex) => {
|
116 | const rowIndexMapping = (0, exports.flatten)(mappedRowHeights.map((height, index) => {
|
117 | return Array.from({ length: height }, () => {
|
118 | return index;
|
119 | });
|
120 | }));
|
121 | return rowIndexMapping[mappedRowIndex];
|
122 | };
|
123 | exports.findOriginalRowIndex = findOriginalRowIndex;
|
124 | const calculateRangeCoordinate = (spanningCellConfig) => {
|
125 | const { row, col, colSpan = 1, rowSpan = 1 } = spanningCellConfig;
|
126 | return { bottomRight: { col: col + colSpan - 1,
|
127 | row: row + rowSpan - 1 },
|
128 | topLeft: { col,
|
129 | row } };
|
130 | };
|
131 | exports.calculateRangeCoordinate = calculateRangeCoordinate;
|
132 | const areCellEqual = (cell1, cell2) => {
|
133 | return cell1.row === cell2.row && cell1.col === cell2.col;
|
134 | };
|
135 | exports.areCellEqual = areCellEqual;
|
136 | const isCellInRange = (cell, { topLeft, bottomRight }) => {
|
137 | return (topLeft.row <= cell.row &&
|
138 | cell.row <= bottomRight.row &&
|
139 | topLeft.col <= cell.col &&
|
140 | cell.col <= bottomRight.col);
|
141 | };
|
142 | exports.isCellInRange = isCellInRange;
|
143 |
|
\ | No newline at end of file |