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