mirror of
https://github.com/kamranahmedse/developer-roadmap.git
synced 2025-08-17 22:51:16 +02:00
Fix star count is displaying NaN
This commit is contained in:
@@ -2,6 +2,7 @@ const formatter = Intl.NumberFormat('en-US', {
|
|||||||
notation: 'compact',
|
notation: 'compact',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const defaultStarCount = 224000;
|
||||||
let starCount: number | undefined = undefined;
|
let starCount: number | undefined = undefined;
|
||||||
|
|
||||||
export async function countStars(
|
export async function countStars(
|
||||||
@@ -15,10 +16,10 @@ export async function countStars(
|
|||||||
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();
|
||||||
|
|
||||||
starCount = json.stargazers_count * 1;
|
starCount = json.stargazers_count * 1 || defaultStarCount;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log('Failed to fetch stars', e);
|
console.log('Failed to fetch stars', e);
|
||||||
starCount = 224000;
|
starCount = defaultStarCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
return starCount;
|
return starCount;
|
||||||
@@ -27,11 +28,7 @@ export async function countStars(
|
|||||||
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) {
|
const stars = import.meta.env.DEV ? defaultStarCount : await countStars(repo);
|
||||||
return '224k';
|
|
||||||
}
|
|
||||||
|
|
||||||
const stars = await countStars(repo);
|
|
||||||
|
|
||||||
return formatter.format(stars);
|
return formatter.format(stars);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user