Skip to content

Commit

Permalink
cleanup show command (#917)
Browse files Browse the repository at this point in the history
fixes #847
  • Loading branch information
joaomoreno authored Dec 13, 2023
1 parent 3aae834 commit 7be15a9
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions src/show.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,28 @@ export function show(extensionId: string, json: boolean = false): Promise<any> {
});
}

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',
Expand Down Expand Up @@ -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}`,
'',
Expand All @@ -91,7 +113,9 @@ function showOverview({
'',
'Statistics:',
...tableView(
<ViewTable>statistics.map(({ statisticName, value }) => [statisticName, Number(value).toFixed(2)])
<ViewTable>statistics
.filter(({ statisticName }) => !/^trending/.test(statisticName!))
.map(({ statisticName, value }) => [statisticName, unit(round(value!), statisticName!)])
).map(indentRow),
]
.map(line => wordWrap(line))
Expand Down

0 comments on commit 7be15a9

Please sign in to comment.