Skip to content

Commit

Permalink
perf: use text-table for less package size (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Oct 31, 2018
1 parent 883a0dc commit ea22b7b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"log-update": "^2.3.0",
"pretty-time": "^1.1.0",
"std-env": "^2.0.2",
"table": "^5.1.0"
"text-table": "^5.1.0"
},
"devDependencies": {
"@commitlint/cli": "^7.2.1",
Expand Down
14 changes: 10 additions & 4 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import path from 'path';

import chalk from 'chalk';
import figures from 'figures';
import { table } from 'table';
import textTable from 'text-table';
import prettyTime from 'pretty-time';

import getDescription from './description';
Expand Down Expand Up @@ -101,13 +101,19 @@ export const formatRequest = (request) => {
return `${loaders}${NEXT}${request.file}`;
};

function createTable(data) {
return textTable(data, {
align: data[0].map(() => 'l'),
}).replace(/\n/g, '\n\n');
}

export const formatStats = (allStats) => {
const lines = [];

Object.keys(allStats).forEach((category) => {
const stats = allStats[category];

lines.push(`Stats by ${chalk.bold(startCase(category))}`);
lines.push(`> Stats by ${chalk.bold(startCase(category))}`);

let totalRequests = 0;
const totalTime = [0, 0];
Expand Down Expand Up @@ -139,10 +145,10 @@ export const formatStats = (allStats) => {

data.push(['Total', totalRequests, prettyTime(totalTime), '', '']);

lines.push(table(data));
lines.push(createTable(data));
});

return lines.join('\n\n');
return `${lines.join('\n\n')}\n`;
};

export function ellipsis(str, n) {
Expand Down

0 comments on commit ea22b7b

Please sign in to comment.