Replace text table (#4373)

This commit is contained in:
Peter Hedenskog 2024-12-29 15:50:19 +01:00 committed by GitHub
parent ebae0bfa99
commit c2f44d23b9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 27 additions and 6 deletions

View File

@ -1,4 +1,3 @@
import table from 'text-table';
import clic from 'cli-color';
import { plural, short, cap } from '../../support/helpers/index.js';
@ -10,6 +9,30 @@ const tableOptions = {
};
const drab = blackBright;
function table(rows, options = {}) {
const { stringLength = str => str.length } = options;
const colWidths = [];
for (const row of rows) {
for (const [i, cell] of row.entries()) {
const len = stringLength(String(cell));
colWidths[i] = Math.max(colWidths[i] || 0, len);
}
}
return rows
.map(row =>
row
.map((cell, i) => {
const cellStr = String(cell);
const padding = colWidths[i] - stringLength(cellStr);
return cellStr + ' '.repeat(padding);
})
.join(' ')
)
.join('\n');
}
function chunk(array, size) {
const out = [];
for (let i = 0; i < array.length; i += size) {
@ -46,7 +69,6 @@ function getBoxes(metrics, html) {
return chunk(summaryBoxesSetup(metrics, html).filter(Boolean), 3).flat();
}
// foo bar -> fb
function abbr(string_) {
if (/total|overall/i.test(string_)) return string_.trim();
return string_.replaceAll(/\w+\s?/g, a => a[0]);
@ -61,7 +83,7 @@ export function renderSummary(metrics, context, options) {
let rows = getBoxes(metrics, options.html).map(b => {
const marker = getMarker(b.label),
c = getColor(b.label);
// color.xterm(ansi)(label),
return [clic[c](marker), clic[c](b.name), bold(b.median)];
});
rows.unshift(

4
npm-shrinkwrap.json generated
View File

@ -50,7 +50,6 @@
"recursive-readdir": "2.2.3",
"simplecrawler": "1.1.9",
"tape": "5.8.1",
"text-table": "0.2.0",
"yargs": "17.7.2"
},
"bin": {
@ -10858,7 +10857,8 @@
"node_modules/text-table": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz",
"integrity": "sha1-f17oI66AUgfACvLfSoTsP8+lcLQ="
"integrity": "sha1-f17oI66AUgfACvLfSoTsP8+lcLQ=",
"dev": true
},
"node_modules/third-party-web": {
"version": "0.26.2",

View File

@ -121,7 +121,6 @@
"simplecrawler": "1.1.9",
"@sitespeed.io/plugin": "0.0.6",
"tape": "5.8.1",
"text-table": "0.2.0",
"yargs": "17.7.2"
},
"overrides": {