code/components/GetRepositories.ts

14 lines
476 B
TypeScript
Raw Normal View History

2021-10-17 18:41:15 +00:00
import { GithubRepository } from '../types/github';
2021-07-12 08:23:02 +00:00
async function getRepositories(): Promise<GithubRepository[]> {
2021-07-12 08:23:02 +00:00
try {
const response = await (await fetch('https://api.github.com/users/aldy505/repos')).json() as GithubRepository[];
2021-07-12 08:23:02 +00:00
const randNumber = Math.random() * (response.length - 5);
return Promise.resolve(response.sort().slice(randNumber, randNumber + 5));
} catch (error) {
return Promise.reject(error);
}
}
export default getRepositories;