Skip to content

Commit ecd2cb3

Browse files
committed
feat(score): add final score metric
1 parent 10ee432 commit ecd2cb3

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/PackageSearchPrompter.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class PackageSearchPrompter {
3737
version,
3838
description,
3939
author: publisher.username,
40+
score: result.score.final,
4041
});
4142

4243
formattedPackageDetails.push(formattedDetails);

src/formatPackageDetails.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,41 @@
11
import chalk from 'chalk';
22

3+
const formatScore = (score) => {
4+
const roundedScore = Math.round(score * 100);
5+
6+
if (roundedScore === 100) {
7+
return '💯';
8+
} else if (roundedScore > 90) {
9+
return `🥇 ${chalk.greenBright.bold(`(${roundedScore}/100)`)}`;
10+
} else if (roundedScore > 80) {
11+
return `🥈 ${chalk.green.bold(`(${roundedScore}/100)`)}`;
12+
} else if (roundedScore > 70) {
13+
return `🥉 ${chalk.magentaBright.bold(`(${roundedScore}/100)`)}`;
14+
} else if (roundedScore > 60) {
15+
return `😅 ${chalk.magenta.bold(`(${roundedScore}/100)`)}`;
16+
} else if (roundedScore > 50) {
17+
return `🤔 ${chalk.blue.bold(`(${roundedScore}/100)`)}`;
18+
} else if (roundedScore > 40) {
19+
return `😯 ${chalk.blueBright.bold(`(${roundedScore}/100)`)}`;
20+
} else if (roundedScore > 30) {
21+
return `🤞 ${chalk.yellow.bold(`(${roundedScore}/100)`)}`;
22+
} else if (roundedScore > 20) {
23+
return `😳 ${chalk.yellowBright.bold(`(${roundedScore}/100)`)}`;
24+
} else if (roundedScore > 10) {
25+
return `🙏 ${chalk.red.bold(`(${roundedScore}/100)`)}`;
26+
} else if (roundedScore > 0) {
27+
return `🥔 ${chalk.redBright.bold(`(${roundedScore}/100)`)}`;
28+
}
29+
30+
return '';
31+
};
32+
333
const formatPackageDetails = ({
434
name,
535
version,
636
description,
737
author,
8-
}) => `📦 ${chalk.green.bold(name)} | 📌 ${chalk.cyan.underline(version)} | 🏷️ ${chalk.yellow.bold(description)} | ⌨️ ${chalk.blueBright.underline(`@${author}`)}`;
38+
score,
39+
}) => `📦 ${chalk.green.bold(name)} | 📌 ${chalk.cyan.underline(version)} | 🏷️ ${chalk.yellow.bold(description)} | ⌨️ ${chalk.blueBright.underline(`@${author}`)} | ${formatScore(score)}`;
940

1041
export default formatPackageDetails;

0 commit comments

Comments
 (0)