refactor(wakatime card): move duplicate value format logic into separate function (#3512)

This commit is contained in:
Alexandr Garbuzov 2023-12-26 14:57:22 +02:00 committed by GitHub
parent c1e8037973
commit 59367dc6b0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -39,6 +39,20 @@ const noCodingActivityNode = ({ color, text }) => {
* @typedef {import('../fetchers/types').WakaTimeLang} WakaTimeLang
*/
/**
* Format language value.
*
* @param {Object} args The function arguments.
* @param {WakaTimeLang} args.lang The language object.
* @param {"time" | "percent"} args.display_format The display format of the language node.
* @returns {string} The formatted language value.
*/
const formatLanguageValue = ({ display_format, lang }) => {
return display_format === "percent"
? `${lang.percent.toFixed(2).toString()} %`
: lang.text;
};
/**
* Create compact WakaTime layout.
*
@ -51,10 +65,7 @@ const noCodingActivityNode = ({ color, text }) => {
*/
const createCompactLangNode = ({ lang, x, y, display_format }) => {
const color = languageColors[lang.name] || "#858585";
const value =
display_format === "percent"
? `${lang.percent.toFixed(2).toString()} %`
: lang.text;
const value = formatLanguageValue({ display_format, lang });
return `
<g transform="translate(${x}, ${y})">
@ -341,10 +352,7 @@ const renderWakatimeCard = (stats = {}, options = { hide: [] }) => {
return createTextNode({
id: language.name,
label: language.name,
value:
display_format === "percent"
? `${language.percent.toFixed(2).toString()} %`
: language.text,
value: formatLanguageValue({ display_format, lang: language }),
index,
percent: language.percent,
// @ts-ignore