mirror of
https://github.com/anuraghazra/github-readme-stats.git
synced 2025-01-06 13:32:26 +08:00
refactor: migrate to using arrow functions (#2033)
This commit is contained in:
parent
b2e34ac8db
commit
4b656ebabb
@ -9,7 +9,7 @@
|
||||
* @param {number} to The value to calculate the probability for.
|
||||
* @returns {number} Probability.
|
||||
*/
|
||||
function normalcdf(mean, sigma, to) {
|
||||
const normalcdf = (mean, sigma, to) => {
|
||||
var z = (to - mean) / Math.sqrt(2 * sigma * sigma);
|
||||
var t = 1 / (1 + 0.3275911 * Math.abs(z));
|
||||
var a1 = 0.254829592;
|
||||
@ -24,7 +24,7 @@ function normalcdf(mean, sigma, to) {
|
||||
sign = -1;
|
||||
}
|
||||
return (1 / 2) * (1 + sign * erf);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Calculates the users rank.
|
||||
@ -38,7 +38,7 @@ function normalcdf(mean, sigma, to) {
|
||||
* @param {number} stargazers The number of stars.
|
||||
* @returns {{level: string, score: number}}} The users rank.
|
||||
*/
|
||||
function calculateRank({
|
||||
const calculateRank = ({
|
||||
totalRepos,
|
||||
totalCommits,
|
||||
contributions,
|
||||
@ -46,7 +46,7 @@ function calculateRank({
|
||||
prs,
|
||||
issues,
|
||||
stargazers,
|
||||
}) {
|
||||
}) => {
|
||||
const COMMITS_OFFSET = 1.65;
|
||||
const CONTRIBS_OFFSET = 1.65;
|
||||
const ISSUES_OFFSET = 1;
|
||||
@ -98,7 +98,7 @@ function calculateRank({
|
||||
})();
|
||||
|
||||
return { level, score: normalizedScore };
|
||||
}
|
||||
};
|
||||
|
||||
export { calculateRank };
|
||||
export default calculateRank;
|
||||
|
@ -42,13 +42,13 @@ const renderError = (message, secondaryMessage = "") => {
|
||||
* @param {string} str String to encode.
|
||||
* @returns {string} Encoded string.
|
||||
*/
|
||||
function encodeHTML(str) {
|
||||
const encodeHTML = (str) => {
|
||||
return str
|
||||
.replace(/[\u00A0-\u9999<>&](?!#)/gim, (i) => {
|
||||
return "&#" + i.charCodeAt(0) + ";";
|
||||
})
|
||||
.replace(/\u0008/gim, "");
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves num with suffix k(thousands) precise to 1 decimal if greater than 999.
|
||||
@ -56,11 +56,11 @@ function encodeHTML(str) {
|
||||
* @param {number} num The number to format.
|
||||
* @returns {string|number} The formatted number.
|
||||
*/
|
||||
function kFormatter(num) {
|
||||
const kFormatter = (num) => {
|
||||
return Math.abs(num) > 999
|
||||
? Math.sign(num) * parseFloat((Math.abs(num) / 1000).toFixed(1)) + "k"
|
||||
: Math.sign(num) * Math.abs(num);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks if a string is a valid hex color.
|
||||
@ -68,11 +68,11 @@ function kFormatter(num) {
|
||||
* @param {string} hexColor String to check.
|
||||
* @returns {boolean} True if the given string is a valid hex color.
|
||||
*/
|
||||
function isValidHexColor(hexColor) {
|
||||
const isValidHexColor = (hexColor) => {
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns boolean if value is either "true" or "false" else the value as it is.
|
||||
@ -80,7 +80,7 @@ function isValidHexColor(hexColor) {
|
||||
* @param {string} value The value to parse.
|
||||
* @returns {boolean | string} The parsed value.
|
||||
*/
|
||||
function parseBoolean(value) {
|
||||
const parseBoolean = (value) => {
|
||||
if (value === "true") {
|
||||
return true;
|
||||
} else if (value === "false") {
|
||||
@ -88,7 +88,7 @@ function parseBoolean(value) {
|
||||
} else {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Parse string to array of strings.
|
||||
@ -96,10 +96,10 @@ function parseBoolean(value) {
|
||||
* @param {string} str The string to parse.
|
||||
* @returns {string[]} The array of strings.
|
||||
*/
|
||||
function parseArray(str) {
|
||||
const parseArray = (str) => {
|
||||
if (!str) return [];
|
||||
return str.split(",");
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Clamp the given number between the given range.
|
||||
@ -109,11 +109,11 @@ function parseArray(str) {
|
||||
* @param {number} max The maximum value.
|
||||
* returns {number} The clamped number.
|
||||
*/
|
||||
function clampValue(number, min, max) {
|
||||
const clampValue = (number, min, max) => {
|
||||
// @ts-ignore
|
||||
if (Number.isNaN(parseInt(number))) return min;
|
||||
return Math.max(min, Math.min(number, max));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if the given string is a valid gradient.
|
||||
@ -121,9 +121,9 @@ function clampValue(number, min, max) {
|
||||
* @param {string[]} colors Array of colors.
|
||||
* @returns {boolean} True if the given string is a valid gradient.
|
||||
*/
|
||||
function isValidGradient(colors) {
|
||||
const isValidGradient = (colors) => {
|
||||
return isValidHexColor(colors[1]) && isValidHexColor(colors[2]);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves a gradient if color has more than one valid hex codes else a single color.
|
||||
@ -132,7 +132,7 @@ function isValidGradient(colors) {
|
||||
* @param {string} fallbackColor The fallback color.
|
||||
* @returns {string | string[]} The gradient or color.
|
||||
*/
|
||||
function fallbackColor(color, fallbackColor) {
|
||||
const fallbackColor = (color, fallbackColor) => {
|
||||
let gradient = null;
|
||||
|
||||
let colors = color ? color.split(",") : [];
|
||||
@ -144,7 +144,7 @@ function fallbackColor(color, fallbackColor) {
|
||||
(gradient ? gradient : isValidHexColor(color) && `#${color}`) ||
|
||||
fallbackColor
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Send GraphQL request to GitHub API.
|
||||
@ -153,7 +153,7 @@ function fallbackColor(color, fallbackColor) {
|
||||
* @param {import('axios').AxiosRequestConfig['headers']} headers Request headers.
|
||||
* @returns {Promise<any>} Request response.
|
||||
*/
|
||||
function request(data, headers) {
|
||||
const request = (data, headers) => {
|
||||
// @ts-ignore
|
||||
return axios({
|
||||
url: "https://api.github.com/graphql",
|
||||
@ -161,7 +161,7 @@ function request(data, headers) {
|
||||
headers,
|
||||
data,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Auto layout utility, allows us to layout things vertically or horizontally with
|
||||
@ -174,7 +174,7 @@ function request(data, headers) {
|
||||
* @param {"column" | "row"?=} props.direction Direction to layout items.
|
||||
* @returns {string[]} Array of items with proper layout.
|
||||
*/
|
||||
function flexLayout({ items, gap, direction, sizes = [] }) {
|
||||
const flexLayout = ({ items, gap, direction, sizes = [] }) => {
|
||||
let lastSize = 0;
|
||||
// filter() for filtering out empty strings
|
||||
return items.filter(Boolean).map((item, i) => {
|
||||
@ -186,7 +186,7 @@ function flexLayout({ items, gap, direction, sizes = [] }) {
|
||||
lastSize += size + gap;
|
||||
return `<g transform="${transform}">${item}</g>`;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns theme based colors with proper overrides and defaults.
|
||||
@ -201,7 +201,7 @@ function flexLayout({ items, gap, direction, sizes = [] }) {
|
||||
* @param {string} args.fallbackTheme Fallback theme.
|
||||
*
|
||||
*/
|
||||
function getCardColors({
|
||||
const getCardColors = ({
|
||||
title_color,
|
||||
text_color,
|
||||
icon_color,
|
||||
@ -210,7 +210,7 @@ function getCardColors({
|
||||
ring_color,
|
||||
theme,
|
||||
fallbackTheme = "default",
|
||||
}) {
|
||||
}) => {
|
||||
const defaultTheme = themes[fallbackTheme];
|
||||
const selectedTheme = themes[theme] || defaultTheme;
|
||||
const defaultBorderColor =
|
||||
@ -248,7 +248,7 @@ function getCardColors({
|
||||
);
|
||||
|
||||
return { titleColor, iconColor, textColor, bgColor, borderColor, ringColor };
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Split text over multiple lines based on the card width.
|
||||
@ -258,7 +258,7 @@ function getCardColors({
|
||||
* @param {number} maxLines Maximum number of lines.
|
||||
* @returns {string[]} Array of lines.
|
||||
*/
|
||||
function wrapTextMultiline(text, width = 59, maxLines = 3) {
|
||||
const wrapTextMultiline = (text, width = 59, maxLines = 3) => {
|
||||
const fullWidthComma = ",";
|
||||
const encoded = encodeHTML(text);
|
||||
const isChinese = encoded.includes(fullWidthComma);
|
||||
@ -283,7 +283,7 @@ function wrapTextMultiline(text, width = 59, maxLines = 3) {
|
||||
// Remove empty lines if text fits in less than maxLines lines
|
||||
const multiLineText = lines.filter(Boolean);
|
||||
return multiLineText;
|
||||
}
|
||||
};
|
||||
|
||||
const noop = () => {};
|
||||
// return console instance based on the environment
|
||||
@ -349,7 +349,7 @@ class MissingParamError extends Error {
|
||||
* @param {number} fontSize Font size.
|
||||
* @returns {number} Text length.
|
||||
*/
|
||||
function measureText(str, fontSize = 10) {
|
||||
const measureText = (str, fontSize = 10) => {
|
||||
// prettier-ignore
|
||||
const widths = [
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
@ -381,7 +381,7 @@ function measureText(str, fontSize = 10) {
|
||||
)
|
||||
.reduce((cur, acc) => acc + cur) * fontSize
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
/** @param {string} name */
|
||||
const lowercaseTrim = (name) => name.toLowerCase().trim();
|
||||
@ -394,7 +394,7 @@ const lowercaseTrim = (name) => name.toLowerCase().trim();
|
||||
* @param {number} perChunk Number of languages per column.
|
||||
* @returns {Array<T>} Array of languages split in two columns.
|
||||
*/
|
||||
function chunkArray(arr, perChunk) {
|
||||
const chunkArray = (arr, perChunk) => {
|
||||
return arr.reduce((resultArray, item, index) => {
|
||||
const chunkIndex = Math.floor(index / perChunk);
|
||||
|
||||
@ -406,7 +406,7 @@ function chunkArray(arr, perChunk) {
|
||||
|
||||
return resultArray;
|
||||
}, []);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Parse emoji from string.
|
||||
@ -414,12 +414,12 @@ function chunkArray(arr, perChunk) {
|
||||
* @param {string} str String to parse emoji from.
|
||||
* @returns {string} String with emoji parsed.
|
||||
*/
|
||||
function parseEmojis(str) {
|
||||
const parseEmojis = (str) => {
|
||||
if (!str) throw new Error("[parseEmoji]: str argument not provided");
|
||||
return str.replace(/:\w+:/gm, (emoji) => {
|
||||
return toEmoji.get(emoji) || "";
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export {
|
||||
ERROR_CARD_LENGTH,
|
||||
|
@ -60,7 +60,7 @@ const urlExample = "/api/pin?username=USERNAME&repo=REPO_NAME";
|
||||
* @param {string} reponame GitHub repository name.
|
||||
* @returns {Promise<import("./types").RepositoryData>} Repository data.
|
||||
*/
|
||||
async function fetchRepo(username, reponame) {
|
||||
const fetchRepo = async (username, reponame) => {
|
||||
if (!username && !reponame) {
|
||||
throw new MissingParamError(["username", "repo"], urlExample);
|
||||
}
|
||||
@ -100,7 +100,7 @@ async function fetchRepo(username, reponame) {
|
||||
starCount: data.organization.repository.stargazers.totalCount,
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export { fetchRepo };
|
||||
export default fetchRepo;
|
||||
|
@ -188,12 +188,12 @@ const totalStarsFetcher = async (username, repoToHide) => {
|
||||
* @param {boolean} include_all_commits Include all commits.
|
||||
* @returns {Promise<import("./types").StatsData>} Stats data.
|
||||
*/
|
||||
async function fetchStats(
|
||||
const fetchStats = async (
|
||||
username,
|
||||
count_private = false,
|
||||
include_all_commits = false,
|
||||
exclude_repo = [],
|
||||
) {
|
||||
) => {
|
||||
if (!username) throw new MissingParamError(["username"]);
|
||||
|
||||
const stats = {
|
||||
@ -275,7 +275,7 @@ async function fetchStats(
|
||||
});
|
||||
|
||||
return stats;
|
||||
}
|
||||
};
|
||||
|
||||
export { fetchStats };
|
||||
export default fetchStats;
|
||||
|
@ -57,7 +57,7 @@ const fetcher = (variables, token) => {
|
||||
* @param {string[]} exclude_repo List of repositories to exclude.
|
||||
* @returns {Promise<import("./types").TopLangData>} Top languages data.
|
||||
*/
|
||||
async function fetchTopLanguages(username, exclude_repo = []) {
|
||||
const fetchTopLanguages = async (username, exclude_repo = []) => {
|
||||
if (!username) throw new MissingParamError(["username"]);
|
||||
|
||||
const res = await retryer(fetcher, { login: username });
|
||||
@ -136,7 +136,7 @@ async function fetchTopLanguages(username, exclude_repo = []) {
|
||||
}, {});
|
||||
|
||||
return topLangs;
|
||||
}
|
||||
};
|
||||
|
||||
export { fetchTopLanguages };
|
||||
export default fetchTopLanguages;
|
||||
|
@ -367,9 +367,9 @@ const availableLocales = Object.keys(repoCardLocales["repocard.archived"]);
|
||||
* @param {string} locale The locale to check.
|
||||
* @returns {boolean} Boolean specifying whether the locale is available or not.
|
||||
*/
|
||||
function isLocaleAvailable(locale) {
|
||||
const isLocaleAvailable = (locale) => {
|
||||
return availableLocales.includes(locale.toLowerCase());
|
||||
}
|
||||
};
|
||||
|
||||
export {
|
||||
isLocaleAvailable,
|
||||
|
Loading…
Reference in New Issue
Block a user