Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions api/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import escapeHTML from "escape-html";
import { Resvg } from "@resvg/resvg-js";
import parseBoolean from "@barudakrosul/parse-boolean";
import getData from "../src/getData";
import { getData,GetData } from "../src/getData";
import card from "../src/card";
import { themes, Themes } from "../themes/index";
import { isValidHexColor, isValidGradient } from "../src/common/utils";
Expand All @@ -16,7 +16,7 @@ import { isValidHexColor, isValidGradient } from "../src/common/utils";
* @property {string} borderColor - Color for borders.
* @property {string} strokeColor - Color for strokes.
* @property {string} usernameColor - Color for the username.
* @property {any} bgColor - Background color or gradient.
* @property {string|string[]} bgColor - Background color or gradient.
* @property {string} Title - Add custom title (optional).
* @property {string} Locale - Locale setting.
* @property {number|string} borderWidth - Width of borders.
Expand All @@ -38,7 +38,7 @@ type UiConfig = {
borderColor: string;
strokeColor: string;
usernameColor: string;
bgColor: any;
bgColor: string|string[];
Title: string | undefined;
Locale: string;
borderWidth: number | string;
Expand Down Expand Up @@ -74,9 +74,9 @@ function generateXML(data: any): string {
*
* @param {any} req - The request object from the client.
* @param {any} res - The response object to send data back to the client.
* @returns {Promise<any>} - A promise that resolves when the photo profile is generated and sent.
* @returns {Promise<void>} - A promise that resolves when the photo profile is generated and sent.
*/
async function readmeStats(req: any, res: any): Promise<any> {
async function readmeStats(req: any, res: any): Promise<void> {
try {
const username = escapeHTML(req.query.username);
const photoQuality = Math.max(0, Math.min(parseInt(escapeHTML(req.query.photo_quality || "15")), 100));
Expand Down Expand Up @@ -130,7 +130,7 @@ async function readmeStats(req: any, res: any): Promise<any> {
}
}

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

if (uiConfig.Format === "json") {
Expand Down
11 changes: 3 additions & 8 deletions scripts/generate-translation-doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,18 @@ function generateTranslationsMarkdown(locale: string): string {
return `${locale}`;
}

export function generateReadmeLocales() {
export function generateReadmeLocales(): string {
const availableLocales = Object.keys(locales).sort();

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

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

localesListTable += ` <tr>
<td><p align="center"><code>${row}</code></p></td>
<td><p align="left">${languageNames[row]}</p></td>
<td><p align="center"><img src="https://shapecolor.vercel.app/?width=14&height=14&radius=7&color=${progressColor}"/> ${progress.toFixed(0)}%</p></td>
</tr>\n`;
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`;
}

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

const generatedReadme = generateReadmeLocales();

fs.writeFileSync(TARGET_FILE, generatedReadme);
2 changes: 1 addition & 1 deletion src/card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ export default async function card(data: GetData, uiConfig: UiConfig): Promise<s

const visibleItems = itemsConfig.filter(item => item.visible);
const cardItemsSVG = visibleItems.map((item, idx) => {
const label = (selectedLocale as any)[item.labelKey];
const label = (selectedLocale as Record<string, string>)[item.labelKey];
const value = data[item.valueKey as keyof GetData];
return `
<g transform="translate(${positions.itemStatsX}, ${15 + idx * 25})">
Expand Down
17 changes: 12 additions & 5 deletions src/common/utils.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
/**
* Checks whether the provided value is a valid hexadecimal color.
*
* @param {any} hexColor - The input value to check for valid hexadecimal color.
* @param {string|string[]} hexColor - The input value to check for valid hexadecimal color.
* @returns {boolean} - True if the input is a valid hexadecimal color, false otherwise.
*/
function isValidHexColor(hexColor: string): boolean {
function isValidHexColor(hexColor: string | string[]): boolean {
if (Array.isArray(hexColor)) return false;
const re = new RegExp("^([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6}|[0-9A-Fa-f]{8})$", "g");
return re.test(hexColor);
}

/**
* Checks whether the provided array of hexadecimal colors is a valid gradient.
*
* @param {string[]} hexColors - The array of hexadecimal colors to check for a valid gradient.
* @param {string|string[]} hexColors - The array of hexadecimal colors to check for a valid gradient.
* @returns {boolean} - True if the array represents a valid gradient, false otherwise.
*/
function isValidGradient(hexColors: string): boolean {
const colors = hexColors.split(",");
function isValidGradient(hexColors: string | string[]): boolean {
let colors;
if (Array.isArray(hexColors)) {
colors = hexColors;
} else {
colors = hexColors.split(",");
}

for (let i = 1; i < colors.length; i++) {
if (!isValidHexColor(colors[i])) {
return false;
Expand Down
16 changes: 13 additions & 3 deletions src/fetcher/repositoryStats.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import axios from "axios";
import getToken from "../getToken";

/**
* Represents the structure of a GitHub repository object returned from API.
*/
interface Repository {
stargazers_count: number;
forks_count: number;
open_issues: number;
}

/**
* Type representing the data associated with a user's repository stats.
*
Expand Down Expand Up @@ -35,8 +44,8 @@ async function repositoryStats(
{ length: totalpage },
async (_, i) => await getPerPageRepositoryData(username, i + 1)
)
).then((data: object[]) => {
data.forEach((repo: any) => {
).then((data: RepositoryData[]) => {
data.forEach((repo: RepositoryData) => {
stars += repo.stars;
forks += repo.forks;
openedIssues += repo.openedIssues;
Expand Down Expand Up @@ -76,7 +85,8 @@ async function getPerPageRepositoryData(
let forks = 0;
let openedIssues = 0;

data.data.forEach((repo: any) => {
// Iterate over each repository in the response and accumulate stats
data.data.forEach((repo: Repository) => {
stars += repo.stargazers_count;
forks += repo.forks_count;
openedIssues += repo.open_issues;
Expand Down
7 changes: 2 additions & 5 deletions src/getData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,14 @@ async function getData(username: string): Promise<GetData> {
total_closed_issues: millify(user.closedIssues.totalCount),
total_prs: millify(user.pullRequests.totalCount),
total_prs_merged: millify(user.mergedPullRequests.totalCount),
total_commits: millify(
user.restrictedContributionsCount + user.totalCommitContributions
),
total_commits: millify(user.totalCommitContributions + user.restrictedContributionsCount),
total_review: millify(user.totalPullRequestReviewContributions),
total_discussion_answered: millify(user.discussionAnswered.totalCount),
total_discussion_started: millify(user.discussionStarted.totalCount),
total_contributed_to: millify(user.repositoriesContributedTo.totalCount),
};
} as GetData;

return output;
}

export { GetData, getData };
export default getData;
Loading