mirror of
https://github.com/DavidHDev/vue-bits.git
synced 2026-03-07 14:39:30 -07:00
Landing Page
This commit is contained in:
20
src/utils/utils.ts
Normal file
20
src/utils/utils.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Fetches the star count for a GitHub repository
|
||||
* @param repo - Repository in format "owner/repo"
|
||||
* @returns Promise<number> - The star count
|
||||
*/
|
||||
export const getStarsCount = async (repo: string = 'DavidHDev/vue-bits'): Promise<number> => {
|
||||
try {
|
||||
const response = await fetch(`https://api.github.com/repos/${repo}`)
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`GitHub API error: ${response.status}`)
|
||||
}
|
||||
|
||||
const data = await response.json()
|
||||
return data.stargazers_count || 0
|
||||
} catch (error) {
|
||||
console.error('Error fetching GitHub stars:', error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user