MCPcopy
hub / github.com/upstash/context7 / formatPopularity

Function formatPopularity

packages/cli/src/utils/prompts.ts:20–35  ·  view source on GitHub ↗
(count: number | undefined)

Source from the content-addressed store, hash-verified

18 * 0/unknown → ☆☆☆☆, <100 → ★☆☆☆, <500 → ★★☆☆, <1000 → ★★★☆, 1000+ → ★★★★
19 */
20export 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.

Callers 3

installCommandFunction · 0.85
searchCommandFunction · 0.85
suggestCommandFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected