(fallback: string)
| 15 | } |
| 16 | |
| 17 | async function fetchStars(fallback: string): Promise<string> { |
| 18 | try { |
| 19 | const controller = new AbortController(); |
| 20 | const timeout = setTimeout(() => controller.abort(), 3000); |
| 21 | const res = await fetch('https://api.github.com/repos/colbymchenry/codegraph', { |
| 22 | headers: { |
| 23 | Accept: 'application/vnd.github+json', |
| 24 | 'User-Agent': 'codegraph-site', |
| 25 | }, |
| 26 | signal: controller.signal, |
| 27 | }); |
| 28 | clearTimeout(timeout); |
| 29 | if (!res.ok) return fallback; |
| 30 | const data = (await res.json()) as { stargazers_count?: number }; |
| 31 | return typeof data.stargazers_count === 'number' ? format(data.stargazers_count) : fallback; |
| 32 | } catch { |
| 33 | return fallback; |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | let cached: Promise<string> | null = null; |
| 38 |
no test coverage detected