Skip to content

Commit

Permalink
refactor: revise code for improved readability and maintainability (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
qwerty652 authored Nov 4, 2023
1 parent 6cf953d commit ec3413a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ function isValidHexColor(hexColor: any): boolean {
return new RegExp(
/^([A-Fa-f0-9]{8}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{3}|[A-Fa-f0-9]{4})$/
).test(hexColor);
};
}

function isValidGradient(hexColors: string[]): boolean {
const colors = [hexColors];
Expand All @@ -12,7 +12,7 @@ function isValidGradient(hexColors: string[]): boolean {
}
}
return true;
};
}

function parseBoolean(value: boolean | string): boolean | undefined {
if (typeof value === "boolean") {
Expand All @@ -27,7 +27,7 @@ function parseBoolean(value: boolean | string): boolean | undefined {
}
}
return undefined;
};
}

export {
isValidHexColor,
Expand Down
2 changes: 1 addition & 1 deletion src/fetcher/apiFetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export interface RepositoriesContributedTo {
}

export default async function apiFetch(username: string): Promise<User> {
let data = await axios({
const data = await axios({
method: "post",
url: "https://api.github.com/graphql",
headers: {
Expand Down
4 changes: 2 additions & 2 deletions src/fetcher/repositoryFetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default async function repositoryFetch(
{ length: totalpage },
async (_, i) => await getPerPageReposData(username, i + 1)
)
).then((data: any) => {
).then((data: object[]) => {
data.forEach((repo: any) => {
stars += repo.stars;
forks += repo.forks;
Expand All @@ -39,7 +39,7 @@ async function getPerPageReposData(
username: string,
pageno: number
): Promise<object> {
let data = await axios({
const data = await axios({
method: "get",
url: `https://api.github.com/users/${username}/repos?page=${pageno}&per_page=100`,
headers: {
Expand Down
8 changes: 4 additions & 4 deletions src/getData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ export type GetData = {
};

async function getData(username: string): Promise<GetData> {
let user = await apiFetch(username);
let totalRepoPages = Math.ceil(user.repositories.totalCount / 100);
let userRepositories = await repositoryFetch(username, totalRepoPages);
const user = await apiFetch(username);
const totalRepoPages = Math.ceil(user.repositories.totalCount / 100);
const userRepositories = await repositoryFetch(username, totalRepoPages);

if (!user.name) user.name = user.login;

let output = {
const output = {
username: user.login,
name: user.name,
pic: await base64ImageFetcher.encode(`${user.avatarUrl}&s=200`, {
Expand Down

0 comments on commit ec3413a

Please sign in to comment.