(count: number | undefined)
| 18 | * 0/unknown → ☆☆☆☆, <100 → ★☆☆☆, <500 → ★★☆☆, <1000 → ★★★☆, 1000+ → ★★★★ |
| 19 | */ |
| 20 | export function formatPopularity(count: number | undefined): string { |
| 21 | const filled = "★"; |
| 22 | const empty = "☆"; |
| 23 | const max = 4; |
| 24 | let stars: number; |
| 25 | if (count === undefined || count === 0) stars = 0; |
| 26 | else if (count < 100) stars = 1; |
| 27 | else if (count < 500) stars = 2; |
| 28 | else if (count < 1000) stars = 3; |
| 29 | else stars = 4; |
| 30 | |
| 31 | const filledPart = filled.repeat(stars); |
| 32 | const emptyPart = empty.repeat(max - stars); |
| 33 | if (stars === 0) return pc.dim(emptyPart); |
| 34 | return pc.yellow(filledPart) + pc.dim(emptyPart); |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Returns the install count as a human-readable range string. |
no outgoing calls
no test coverage detected