Skip to content

Commit af334bc

Browse files
Guard score inputs to avoid NaN rankings.
1 parent cfabca0 commit af334bc

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

src/services/analytics.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,16 +174,16 @@ export function getTopRepositories(repos, limit = 10) {
174174

175175
return [...repos]
176176
.map(repo => {
177-
const daysSinceLastPush =
178-
(Date.now() - new Date(repo.pushed_at).getTime()) / MS_PER_DAY;
177+
const pushedAtMs = Date.parse(repo.pushed_at);
178+
const daysSinceLastPush = Number.isFinite(pushedAtMs) ? (Date.now() - pushedAtMs) / MS_PER_DAY : Infinity;
179179

180180
const activityBonus = 0.5 * Math.max(0, 365 - daysSinceLastPush);
181181

182-
const score =
183-
repo.stargazers_count +
184-
repo.forks_count * 2 +
185-
repo.watchers_count * 1.5 +
186-
activityBonus;
182+
const score =
183+
(repo.stargazers_count ?? 0) +
184+
(repo.forks_count ?? 0) * 2 +
185+
(repo.watchers_count ?? 0) * 1.5 +
186+
activityBonus;
187187

188188
return {
189189
...repo,

0 commit comments

Comments
 (0)