Skip to content

Commit b60aa8f

Browse files
committed
wrap label into function
1 parent 4c3629b commit b60aa8f

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

src/cards/stats-card.js

+22-14
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,20 @@ const getStyles = ({
187187
`;
188188
};
189189

190+
/**
191+
* Return the label for commits according to the selected options
192+
*
193+
* @param {boolean} include_all_commits Option to include all years
194+
* @param {number|undefined} commits_year Option to include only selected year
195+
* @returns {string} The label corresponding to the options.
196+
*/
197+
const getTotalCommitsYearLabel = (include_all_commits, commits_year) =>
198+
include_all_commits
199+
? ""
200+
: commits_year
201+
? ` (${commits_year})`
202+
: ` (last year)`;
203+
190204
/**
191205
* @typedef {import('../fetchers/types').StatsData} StatsData
192206
* @typedef {import('./types').StatCardOptions} StatCardOptions
@@ -274,13 +288,10 @@ const renderStatsCard = (stats, options = {}) => {
274288
};
275289
STATS.commits = {
276290
icon: icons.commits,
277-
label: `${i18n.t("statcard.commits")}${
278-
include_all_commits
279-
? ""
280-
: commits_year
281-
? ` (${commits_year})`
282-
: ` (last year)`
283-
}`,
291+
label: `${i18n.t("statcard.commits")}${getTotalCommitsYearLabel(
292+
include_all_commits,
293+
commits_year,
294+
)}`,
284295
value: totalCommits,
285296
id: "commits",
286297
};
@@ -521,13 +532,10 @@ const renderStatsCard = (stats, options = {}) => {
521532
.filter((key) => !hide.includes(key))
522533
.map((key) => {
523534
if (key === "commits") {
524-
return `${i18n.t("statcard.commits")} ${
525-
include_all_commits
526-
? ""
527-
: commits_year
528-
? ` (${commits_year})`
529-
: ` (last year)`
530-
} : ${totalStars}`;
535+
return `${i18n.t("statcard.commits")} ${getTotalCommitsYearLabel(
536+
include_all_commits,
537+
commits_year,
538+
)} : ${totalStars}`;
531539
}
532540
return `${STATS[key].label}: ${STATS[key].value}`;
533541
})

0 commit comments

Comments
 (0)