From 7be15a92cacbb03b1669240cf78a7cd6e3dc4f5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Moreno?= Date: Wed, 13 Dec 2023 14:58:31 +0100 Subject: [PATCH] cleanup show command (#917) fixes #847 --- src/show.ts | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/show.ts b/src/show.ts index d9f5c193..1a8ab7e7 100644 --- a/src/show.ts +++ b/src/show.ts @@ -37,6 +37,28 @@ export function show(extensionId: string, json: boolean = false): Promise { }); } +function round(num: number): number { + return Math.round(num * 100) / 100; +} + +function unit(value: number, statisticName: string): string { + switch (statisticName) { + case 'install': + return `${value} installs`; + case 'updateCount': + return `${value} updates`; + case 'averagerating': + case 'weightedRating': + return `${value} stars`; + case 'ratingcount': + return `${value} ratings`; + case 'downloadCount': + return `${value} downloads`; + default: + return `${value}`; + } +} + function showOverview({ displayName = 'unknown', extensionName = 'unknown', @@ -66,8 +88,8 @@ function showOverview({ [ `${displayName}`, `${publisherDisplayName} | ${icons.download} ` + - `${Number(installs).toLocaleString()} installs |` + - ` ${ratingStars(averagerating)} (${ratingcount})`, + `${Number(installs).toLocaleString()} installs |` + + ` ${ratingStars(averagerating)} (${ratingcount})`, '', `${shortDescription}`, '', @@ -91,7 +113,9 @@ function showOverview({ '', 'Statistics:', ...tableView( - statistics.map(({ statisticName, value }) => [statisticName, Number(value).toFixed(2)]) + statistics + .filter(({ statisticName }) => !/^trending/.test(statisticName!)) + .map(({ statisticName, value }) => [statisticName, unit(round(value!), statisticName!)]) ).map(indentRow), ] .map(line => wordWrap(line))