Files
developer-roadmap/src/lib/github.ts
T
2023-01-02 23:18:20 +04:00

21 lines
505 B
TypeScript

const formatter = Intl.NumberFormat('en-US', {
notation: 'compact',
});
export async function countStars(
repo = 'kamranahmedse/developer-roadmap'
): Promise<number> {
const repoData = await fetch(`https://api.github.com/repos/${repo}`);
const json = await repoData.json();
return json.stargazers_count * 1;
}
export async function getFormattedStars(
repo = 'kamranahmedse/developer-roadmap'
): Promise<string> {
const stars = await countStars(repo);
return formatter.format(stars);
}