Skip to content

Commit 4b656eb

Browse files
authored
refactor: migrate to using arrow functions (#2033)
1 parent b2e34ac commit 4b656eb

File tree

6 files changed

+45
-45
lines changed

6 files changed

+45
-45
lines changed

src/calculateRank.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* @param {number} to The value to calculate the probability for.
1010
* @returns {number} Probability.
1111
*/
12-
function normalcdf(mean, sigma, to) {
12+
const normalcdf = (mean, sigma, to) => {
1313
var z = (to - mean) / Math.sqrt(2 * sigma * sigma);
1414
var t = 1 / (1 + 0.3275911 * Math.abs(z));
1515
var a1 = 0.254829592;
@@ -24,7 +24,7 @@ function normalcdf(mean, sigma, to) {
2424
sign = -1;
2525
}
2626
return (1 / 2) * (1 + sign * erf);
27-
}
27+
};
2828

2929
/**
3030
* Calculates the users rank.
@@ -38,15 +38,15 @@ function normalcdf(mean, sigma, to) {
3838
* @param {number} stargazers The number of stars.
3939
* @returns {{level: string, score: number}}} The users rank.
4040
*/
41-
function calculateRank({
41+
const calculateRank = ({
4242
totalRepos,
4343
totalCommits,
4444
contributions,
4545
followers,
4646
prs,
4747
issues,
4848
stargazers,
49-
}) {
49+
}) => {
5050
const COMMITS_OFFSET = 1.65;
5151
const CONTRIBS_OFFSET = 1.65;
5252
const ISSUES_OFFSET = 1;
@@ -98,7 +98,7 @@ function calculateRank({
9898
})();
9999

100100
return { level, score: normalizedScore };
101-
}
101+
};
102102

103103
export { calculateRank };
104104
export default calculateRank;

src/common/utils.js

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -42,64 +42,64 @@ const renderError = (message, secondaryMessage = "") => {
4242
* @param {string} str String to encode.
4343
* @returns {string} Encoded string.
4444
*/
45-
function encodeHTML(str) {
45+
const encodeHTML = (str) => {
4646
return str
4747
.replace(/[\u00A0-\u9999<>&](?!#)/gim, (i) => {
4848
return "&#" + i.charCodeAt(0) + ";";
4949
})
5050
.replace(/\u0008/gim, "");
51-
}
51+
};
5252

5353
/**
5454
* Retrieves num with suffix k(thousands) precise to 1 decimal if greater than 999.
5555
*
5656
* @param {number} num The number to format.
5757
* @returns {string|number} The formatted number.
5858
*/
59-
function kFormatter(num) {
59+
const kFormatter = (num) => {
6060
return Math.abs(num) > 999
6161
? Math.sign(num) * parseFloat((Math.abs(num) / 1000).toFixed(1)) + "k"
6262
: Math.sign(num) * Math.abs(num);
63-
}
63+
};
6464

6565
/**
6666
* Checks if a string is a valid hex color.
6767
*
6868
* @param {string} hexColor String to check.
6969
* @returns {boolean} True if the given string is a valid hex color.
7070
*/
71-
function isValidHexColor(hexColor) {
71+
const isValidHexColor = (hexColor) => {
7272
return new RegExp(
7373
/^([A-Fa-f0-9]{8}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{3}|[A-Fa-f0-9]{4})$/,
7474
).test(hexColor);
75-
}
75+
};
7676

7777
/**
7878
* Returns boolean if value is either "true" or "false" else the value as it is.
7979
*
8080
* @param {string} value The value to parse.
8181
* @returns {boolean | string} The parsed value.
8282
*/
83-
function parseBoolean(value) {
83+
const parseBoolean = (value) => {
8484
if (value === "true") {
8585
return true;
8686
} else if (value === "false") {
8787
return false;
8888
} else {
8989
return value;
9090
}
91-
}
91+
};
9292

9393
/**
9494
* Parse string to array of strings.
9595
*
9696
* @param {string} str The string to parse.
9797
* @returns {string[]} The array of strings.
9898
*/
99-
function parseArray(str) {
99+
const parseArray = (str) => {
100100
if (!str) return [];
101101
return str.split(",");
102-
}
102+
};
103103

104104
/**
105105
* Clamp the given number between the given range.
@@ -109,21 +109,21 @@ function parseArray(str) {
109109
* @param {number} max The maximum value.
110110
* returns {number} The clamped number.
111111
*/
112-
function clampValue(number, min, max) {
112+
const clampValue = (number, min, max) => {
113113
// @ts-ignore
114114
if (Number.isNaN(parseInt(number))) return min;
115115
return Math.max(min, Math.min(number, max));
116-
}
116+
};
117117

118118
/**
119119
* Check if the given string is a valid gradient.
120120
*
121121
* @param {string[]} colors Array of colors.
122122
* @returns {boolean} True if the given string is a valid gradient.
123123
*/
124-
function isValidGradient(colors) {
124+
const isValidGradient = (colors) => {
125125
return isValidHexColor(colors[1]) && isValidHexColor(colors[2]);
126-
}
126+
};
127127

128128
/**
129129
* Retrieves a gradient if color has more than one valid hex codes else a single color.
@@ -132,7 +132,7 @@ function isValidGradient(colors) {
132132
* @param {string} fallbackColor The fallback color.
133133
* @returns {string | string[]} The gradient or color.
134134
*/
135-
function fallbackColor(color, fallbackColor) {
135+
const fallbackColor = (color, fallbackColor) => {
136136
let gradient = null;
137137

138138
let colors = color ? color.split(",") : [];
@@ -144,7 +144,7 @@ function fallbackColor(color, fallbackColor) {
144144
(gradient ? gradient : isValidHexColor(color) && `#${color}`) ||
145145
fallbackColor
146146
);
147-
}
147+
};
148148

149149
/**
150150
* Send GraphQL request to GitHub API.
@@ -153,15 +153,15 @@ function fallbackColor(color, fallbackColor) {
153153
* @param {import('axios').AxiosRequestConfig['headers']} headers Request headers.
154154
* @returns {Promise<any>} Request response.
155155
*/
156-
function request(data, headers) {
156+
const request = (data, headers) => {
157157
// @ts-ignore
158158
return axios({
159159
url: "https://api.github.com/graphql",
160160
method: "post",
161161
headers,
162162
data,
163163
});
164-
}
164+
};
165165

166166
/**
167167
* Auto layout utility, allows us to layout things vertically or horizontally with
@@ -174,7 +174,7 @@ function request(data, headers) {
174174
* @param {"column" | "row"?=} props.direction Direction to layout items.
175175
* @returns {string[]} Array of items with proper layout.
176176
*/
177-
function flexLayout({ items, gap, direction, sizes = [] }) {
177+
const flexLayout = ({ items, gap, direction, sizes = [] }) => {
178178
let lastSize = 0;
179179
// filter() for filtering out empty strings
180180
return items.filter(Boolean).map((item, i) => {
@@ -186,7 +186,7 @@ function flexLayout({ items, gap, direction, sizes = [] }) {
186186
lastSize += size + gap;
187187
return `<g transform="${transform}">${item}</g>`;
188188
});
189-
}
189+
};
190190

191191
/**
192192
* Returns theme based colors with proper overrides and defaults.
@@ -201,7 +201,7 @@ function flexLayout({ items, gap, direction, sizes = [] }) {
201201
* @param {string} args.fallbackTheme Fallback theme.
202202
*
203203
*/
204-
function getCardColors({
204+
const getCardColors = ({
205205
title_color,
206206
text_color,
207207
icon_color,
@@ -210,7 +210,7 @@ function getCardColors({
210210
ring_color,
211211
theme,
212212
fallbackTheme = "default",
213-
}) {
213+
}) => {
214214
const defaultTheme = themes[fallbackTheme];
215215
const selectedTheme = themes[theme] || defaultTheme;
216216
const defaultBorderColor =
@@ -248,7 +248,7 @@ function getCardColors({
248248
);
249249

250250
return { titleColor, iconColor, textColor, bgColor, borderColor, ringColor };
251-
}
251+
};
252252

253253
/**
254254
* Split text over multiple lines based on the card width.
@@ -258,7 +258,7 @@ function getCardColors({
258258
* @param {number} maxLines Maximum number of lines.
259259
* @returns {string[]} Array of lines.
260260
*/
261-
function wrapTextMultiline(text, width = 59, maxLines = 3) {
261+
const wrapTextMultiline = (text, width = 59, maxLines = 3) => {
262262
const fullWidthComma = ",";
263263
const encoded = encodeHTML(text);
264264
const isChinese = encoded.includes(fullWidthComma);
@@ -283,7 +283,7 @@ function wrapTextMultiline(text, width = 59, maxLines = 3) {
283283
// Remove empty lines if text fits in less than maxLines lines
284284
const multiLineText = lines.filter(Boolean);
285285
return multiLineText;
286-
}
286+
};
287287

288288
const noop = () => {};
289289
// return console instance based on the environment
@@ -349,7 +349,7 @@ class MissingParamError extends Error {
349349
* @param {number} fontSize Font size.
350350
* @returns {number} Text length.
351351
*/
352-
function measureText(str, fontSize = 10) {
352+
const measureText = (str, fontSize = 10) => {
353353
// prettier-ignore
354354
const widths = [
355355
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -381,7 +381,7 @@ function measureText(str, fontSize = 10) {
381381
)
382382
.reduce((cur, acc) => acc + cur) * fontSize
383383
);
384-
}
384+
};
385385

386386
/** @param {string} name */
387387
const lowercaseTrim = (name) => name.toLowerCase().trim();
@@ -394,7 +394,7 @@ const lowercaseTrim = (name) => name.toLowerCase().trim();
394394
* @param {number} perChunk Number of languages per column.
395395
* @returns {Array<T>} Array of languages split in two columns.
396396
*/
397-
function chunkArray(arr, perChunk) {
397+
const chunkArray = (arr, perChunk) => {
398398
return arr.reduce((resultArray, item, index) => {
399399
const chunkIndex = Math.floor(index / perChunk);
400400

@@ -406,20 +406,20 @@ function chunkArray(arr, perChunk) {
406406

407407
return resultArray;
408408
}, []);
409-
}
409+
};
410410

411411
/**
412412
* Parse emoji from string.
413413
*
414414
* @param {string} str String to parse emoji from.
415415
* @returns {string} String with emoji parsed.
416416
*/
417-
function parseEmojis(str) {
417+
const parseEmojis = (str) => {
418418
if (!str) throw new Error("[parseEmoji]: str argument not provided");
419419
return str.replace(/:\w+:/gm, (emoji) => {
420420
return toEmoji.get(emoji) || "";
421421
});
422-
}
422+
};
423423

424424
export {
425425
ERROR_CARD_LENGTH,

src/fetchers/repo-fetcher.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const urlExample = "/api/pin?username=USERNAME&amp;repo=REPO_NAME";
6060
* @param {string} reponame GitHub repository name.
6161
* @returns {Promise<import("./types").RepositoryData>} Repository data.
6262
*/
63-
async function fetchRepo(username, reponame) {
63+
const fetchRepo = async (username, reponame) => {
6464
if (!username && !reponame) {
6565
throw new MissingParamError(["username", "repo"], urlExample);
6666
}
@@ -100,7 +100,7 @@ async function fetchRepo(username, reponame) {
100100
starCount: data.organization.repository.stargazers.totalCount,
101101
};
102102
}
103-
}
103+
};
104104

105105
export { fetchRepo };
106106
export default fetchRepo;

src/fetchers/stats-fetcher.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,12 @@ const totalStarsFetcher = async (username, repoToHide) => {
188188
* @param {boolean} include_all_commits Include all commits.
189189
* @returns {Promise<import("./types").StatsData>} Stats data.
190190
*/
191-
async function fetchStats(
191+
const fetchStats = async (
192192
username,
193193
count_private = false,
194194
include_all_commits = false,
195195
exclude_repo = [],
196-
) {
196+
) => {
197197
if (!username) throw new MissingParamError(["username"]);
198198

199199
const stats = {
@@ -275,7 +275,7 @@ async function fetchStats(
275275
});
276276

277277
return stats;
278-
}
278+
};
279279

280280
export { fetchStats };
281281
export default fetchStats;

src/fetchers/top-languages-fetcher.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const fetcher = (variables, token) => {
5757
* @param {string[]} exclude_repo List of repositories to exclude.
5858
* @returns {Promise<import("./types").TopLangData>} Top languages data.
5959
*/
60-
async function fetchTopLanguages(username, exclude_repo = []) {
60+
const fetchTopLanguages = async (username, exclude_repo = []) => {
6161
if (!username) throw new MissingParamError(["username"]);
6262

6363
const res = await retryer(fetcher, { login: username });
@@ -136,7 +136,7 @@ async function fetchTopLanguages(username, exclude_repo = []) {
136136
}, {});
137137

138138
return topLangs;
139-
}
139+
};
140140

141141
export { fetchTopLanguages };
142142
export default fetchTopLanguages;

src/translations.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,9 +367,9 @@ const availableLocales = Object.keys(repoCardLocales["repocard.archived"]);
367367
* @param {string} locale The locale to check.
368368
* @returns {boolean} Boolean specifying whether the locale is available or not.
369369
*/
370-
function isLocaleAvailable(locale) {
370+
const isLocaleAvailable = (locale) => {
371371
return availableLocales.includes(locale.toLowerCase());
372-
}
372+
};
373373

374374
export {
375375
isLocaleAvailable,

0 commit comments

Comments
 (0)