Roadmap to becoming a developer in 2022
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
832 B

2 years ago
const formatter = Intl.NumberFormat('en-US', {
notation: 'compact',
});
const defaultStarCount = 224000;
let starCount: number | undefined = undefined;
2 years ago
export async function countStars(
repo = 'kamranahmedse/developer-roadmap'
): Promise<number> {
if (starCount) {
return starCount;
}
try {
const repoData = await fetch(`https://api.github.com/repos/${repo}`);
const json = await repoData.json();
starCount = json.stargazers_count * 1 || defaultStarCount;
} catch (e) {
console.log('Failed to fetch stars', e);
starCount = defaultStarCount;
}
2 years ago
return starCount;
2 years ago
}
export async function getFormattedStars(
repo = 'kamranahmedse/developer-roadmap'
): Promise<string> {
const stars = import.meta.env.DEV ? defaultStarCount : await countStars(repo);
2 years ago
return formatter.format(stars);
}