Skip to content

Commit cd84794

Browse files
authored
fix: remove any types to fix type errors (#946)
1 parent 16daa88 commit cd84794

6 files changed

Lines changed: 37 additions & 28 deletions

File tree

api/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import escapeHTML from "escape-html";
22
import { Resvg } from "@resvg/resvg-js";
33
import parseBoolean from "@barudakrosul/parse-boolean";
4-
import getData from "../src/getData";
4+
import { getData,GetData } from "../src/getData";
55
import card from "../src/card";
66
import { themes, Themes } from "../themes/index";
77
import { isValidHexColor, isValidGradient } from "../src/common/utils";
@@ -16,7 +16,7 @@ import { isValidHexColor, isValidGradient } from "../src/common/utils";
1616
* @property {string} borderColor - Color for borders.
1717
* @property {string} strokeColor - Color for strokes.
1818
* @property {string} usernameColor - Color for the username.
19-
* @property {any} bgColor - Background color or gradient.
19+
* @property {string|string[]} bgColor - Background color or gradient.
2020
* @property {string} Title - Add custom title (optional).
2121
* @property {string} Locale - Locale setting.
2222
* @property {number|string} borderWidth - Width of borders.
@@ -38,7 +38,7 @@ type UiConfig = {
3838
borderColor: string;
3939
strokeColor: string;
4040
usernameColor: string;
41-
bgColor: any;
41+
bgColor: string|string[];
4242
Title: string | undefined;
4343
Locale: string;
4444
borderWidth: number | string;
@@ -74,9 +74,9 @@ function generateXML(data: any): string {
7474
*
7575
* @param {any} req - The request object from the client.
7676
* @param {any} res - The response object to send data back to the client.
77-
* @returns {Promise<any>} - A promise that resolves when the photo profile is generated and sent.
77+
* @returns {Promise<void>} - A promise that resolves when the photo profile is generated and sent.
7878
*/
79-
async function readmeStats(req: any, res: any): Promise<any> {
79+
async function readmeStats(req: any, res: any): Promise<void> {
8080
try {
8181
const username = escapeHTML(req.query.username);
8282
const photoQuality = Math.max(0, Math.min(parseInt(escapeHTML(req.query.photo_quality || "15")), 100));
@@ -130,7 +130,7 @@ async function readmeStats(req: any, res: any): Promise<any> {
130130
}
131131
}
132132

133-
const fetchStats = await getData(username);
133+
const fetchStats: GetData = await getData(username);
134134
res.setHeader("Cache-Control", "s-maxage=7200, stale-while-revalidate");
135135

136136
if (uiConfig.Format === "json") {

scripts/generate-translation-doc.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,18 @@ function generateTranslationsMarkdown(locale: string): string {
1616
return `${locale}`;
1717
}
1818

19-
export function generateReadmeLocales() {
19+
export function generateReadmeLocales(): string {
2020
const availableLocales = Object.keys(locales).sort();
2121

2222
let localesListTable = "";
2323
for (let i = 0; i < availableLocales.length; i += 1) {
2424
const localesSlice = availableLocales.slice(i, i + 1);
2525
const row = localesSlice.map(locale => generateTranslationsMarkdown(locale)).join("");
2626

27-
const progress = (Object.keys(locales[row]).length / 16) * 100;
27+
const progress = (Object.keys(locales[row as keyof typeof locales]).length / 16) * 100;
2828
const progressColor = getProgressColor(progress);
2929

30-
localesListTable += ` <tr>
31-
<td><p align="center"><code>${row}</code></p></td>
32-
<td><p align="left">${languageNames[row]}</p></td>
33-
<td><p align="center"><img src="https://shapecolor.vercel.app/?width=14&height=14&radius=7&color=${progressColor}"/> ${progress.toFixed(0)}%</p></td>
34-
</tr>\n`;
30+
localesListTable += ` <tr>\n <td><p align="center"><code>${row}</code></p></td>\n <td><p align="left">${languageNames[row as keyof typeof languageNames]}</p></td>\n <td><p align="center"><img src="https://shapecolor.vercel.app/?width=14&height=14&radius=7&color=${progressColor}"/> ${progress.toFixed(0)}%</p></td>\n </tr>\n`;
3531
}
3632

3733
const readmeContent = `<!-- DO NOT EDIT THIS FILE DIRECTLY -->
@@ -59,5 +55,4 @@ Want to add new translations? Consider reading the [contribution guidelines](htt
5955
}
6056

6157
const generatedReadme = generateReadmeLocales();
62-
6358
fs.writeFileSync(TARGET_FILE, generatedReadme);

src/card.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ export default async function card(data: GetData, uiConfig: UiConfig): Promise<s
241241

242242
const visibleItems = itemsConfig.filter(item => item.visible);
243243
const cardItemsSVG = visibleItems.map((item, idx) => {
244-
const label = (selectedLocale as any)[item.labelKey];
244+
const label = (selectedLocale as Record<string, string>)[item.labelKey];
245245
const value = data[item.valueKey as keyof GetData];
246246
return `
247247
<g transform="translate(${positions.itemStatsX}, ${15 + idx * 25})">

src/common/utils.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,29 @@
11
/**
22
* Checks whether the provided value is a valid hexadecimal color.
33
*
4-
* @param {any} hexColor - The input value to check for valid hexadecimal color.
4+
* @param {string|string[]} hexColor - The input value to check for valid hexadecimal color.
55
* @returns {boolean} - True if the input is a valid hexadecimal color, false otherwise.
66
*/
7-
function isValidHexColor(hexColor: string): boolean {
7+
function isValidHexColor(hexColor: string | string[]): boolean {
8+
if (Array.isArray(hexColor)) return false;
89
const re = new RegExp("^([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6}|[0-9A-Fa-f]{8})$", "g");
910
return re.test(hexColor);
1011
}
1112

1213
/**
1314
* Checks whether the provided array of hexadecimal colors is a valid gradient.
1415
*
15-
* @param {string[]} hexColors - The array of hexadecimal colors to check for a valid gradient.
16+
* @param {string|string[]} hexColors - The array of hexadecimal colors to check for a valid gradient.
1617
* @returns {boolean} - True if the array represents a valid gradient, false otherwise.
1718
*/
18-
function isValidGradient(hexColors: string): boolean {
19-
const colors = hexColors.split(",");
19+
function isValidGradient(hexColors: string | string[]): boolean {
20+
let colors;
21+
if (Array.isArray(hexColors)) {
22+
colors = hexColors;
23+
} else {
24+
colors = hexColors.split(",");
25+
}
26+
2027
for (let i = 1; i < colors.length; i++) {
2128
if (!isValidHexColor(colors[i])) {
2229
return false;

src/fetcher/repositoryStats.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
import axios from "axios";
22
import getToken from "../getToken";
33

4+
/**
5+
* Represents the structure of a GitHub repository object returned from API.
6+
*/
7+
interface Repository {
8+
stargazers_count: number;
9+
forks_count: number;
10+
open_issues: number;
11+
}
12+
413
/**
514
* Type representing the data associated with a user's repository stats.
615
*
@@ -35,8 +44,8 @@ async function repositoryStats(
3544
{ length: totalpage },
3645
async (_, i) => await getPerPageRepositoryData(username, i + 1)
3746
)
38-
).then((data: object[]) => {
39-
data.forEach((repo: any) => {
47+
).then((data: RepositoryData[]) => {
48+
data.forEach((repo: RepositoryData) => {
4049
stars += repo.stars;
4150
forks += repo.forks;
4251
openedIssues += repo.openedIssues;
@@ -76,7 +85,8 @@ async function getPerPageRepositoryData(
7685
let forks = 0;
7786
let openedIssues = 0;
7887

79-
data.data.forEach((repo: any) => {
88+
// Iterate over each repository in the response and accumulate stats
89+
data.data.forEach((repo: Repository) => {
8090
stars += repo.stargazers_count;
8191
forks += repo.forks_count;
8292
openedIssues += repo.open_issues;

src/getData.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,14 @@ async function getData(username: string): Promise<GetData> {
7575
total_closed_issues: millify(user.closedIssues.totalCount),
7676
total_prs: millify(user.pullRequests.totalCount),
7777
total_prs_merged: millify(user.mergedPullRequests.totalCount),
78-
total_commits: millify(
79-
user.restrictedContributionsCount + user.totalCommitContributions
80-
),
78+
total_commits: millify(user.totalCommitContributions + user.restrictedContributionsCount),
8179
total_review: millify(user.totalPullRequestReviewContributions),
8280
total_discussion_answered: millify(user.discussionAnswered.totalCount),
8381
total_discussion_started: millify(user.discussionStarted.totalCount),
8482
total_contributed_to: millify(user.repositoriesContributedTo.totalCount),
85-
};
83+
} as GetData;
8684

8785
return output;
8886
}
89-
9087
export { GetData, getData };
9188
export default getData;

0 commit comments

Comments
 (0)