Skip to content

Commit 3d87b89

Browse files
committed
refactor: add docstrings
1 parent 0812ed6 commit 3d87b89

15 files changed

+290
-229
lines changed

src/calculateRank.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
*
55
* @see https://stackoverflow.com/a/5263759/10629172
66
*
7-
* @param {string} mean
8-
* @param {number} sigma
9-
* @param {number} to
7+
* @param {string} mean The mean of the normal distribution.
8+
* @param {number} sigma The standard deviation of the normal distribution.
9+
* @param {number} to The value to calculate the probability for.
1010
* @returns {number} Probability.
1111
*/
1212
function normalcdf(mean, sigma, to) {
@@ -29,13 +29,13 @@ function normalcdf(mean, sigma, to) {
2929
/**
3030
* Calculates the users rank.
3131
*
32-
* @param {number} totalRepos
33-
* @param {number} totalCommits
34-
* @param {number} contributions
35-
* @param {number} followers
36-
* @param {number} prs
37-
* @param {number} issues
38-
* @param {number} stargazers
32+
* @param {number} totalRepos Total number of repos.
33+
* @param {number} totalCommits Total number of commits.
34+
* @param {number} contributions The number of contributions.
35+
* @param {number} followers The number of followers.
36+
* @param {number} prs The number of pull requests.
37+
* @param {number} issues The number of issues.
38+
* @param {number} stargazers The number of stars.
3939
* @returns {{level: string, score: number}}} The users rank.
4040
*/
4141
function calculateRank({

src/cards/repo-card.js

+16-16
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ import {
1414
import { repoCardLocales } from "../translations.js";
1515

1616
/**
17-
* Retrieves a badge to display the type of repo like template, archived, etc
17+
* Retrieves the repository description and wraps it to fit the card width.
1818
*
19-
* @param {string} label
20-
* @param {string} textColor
21-
* @returns {string} svg badge
19+
* @param {string} label The repository description.
20+
* @param {string} textColor The color of the text.
21+
* @returns {string} Wrapped repo description SVG object.
2222
*/
2323
const getBadgeSVG = (label, textColor) => `
2424
<g data-testid="badge" class="badge" transform="translate(320, -18)">
@@ -36,11 +36,11 @@ const getBadgeSVG = (label, textColor) => `
3636
`;
3737

3838
/**
39-
* Creates a node to display the primary programming language of the repository
39+
* Creates a node to display the primary programming language of the repository.
4040
*
41-
* @param {string} langName
42-
* @param {string} langColor
43-
* @returns {string} language node
41+
* @param {string} langName Language name.
42+
* @param {string} langColor Language color.
43+
* @returns {string} Language display SVG object.
4444
*/
4545
const createLanguageNode = (langName, langColor) => {
4646
return `
@@ -56,10 +56,10 @@ const ICON_SIZE = 16;
5656
/**
5757
* Creates an icon with label to display repository stats like forks, stars, etc.
5858
*
59-
* @param {string} icon
60-
* @param {number|string} label
61-
* @param {string} testid
62-
* @returns {string} icon with label
59+
* @param {string} icon The icon to display.
60+
* @param {number|string} label The label to display.
61+
* @param {string} testid The testid to assign to the label.
62+
* @returns {string} Icon with label SVG object.
6363
*/
6464
const iconWithLabel = (icon, label, testid) => {
6565
if (label <= 0) return "";
@@ -80,11 +80,11 @@ const iconWithLabel = (icon, label, testid) => {
8080
};
8181

8282
/**
83-
* Renders repository card details
83+
* Renders repository card details.
8484
*
85-
* @param {import('../fetchers/types').RepositoryData} repo
86-
* @param {Partial<import("./types").RepoCardOptions>} options
87-
* @returns {string} repository card
85+
* @param {import('../fetchers/types').RepositoryData} repo Repository data.
86+
* @param {Partial<import("./types").RepoCardOptions>} options Card options.
87+
* @returns {string} Repository card SVG object.
8888
*/
8989
const renderRepoCard = (repo, options = {}) => {
9090
const {

src/cards/stats-card.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,11 @@ const createTextNode = ({
6363
};
6464

6565
/**
66-
* @param {Partial<import('../fetchers/types').StatsData>} stats
67-
* @param {Partial<import("./types").StatCardOptions>} options
68-
* @returns {string}
66+
* Renders the stats card.
67+
*
68+
* @param {Partial<import('../fetchers/types').StatsData>} stats The stats data.
69+
* @param {Partial<import("./types").StatCardOptions>} options The card options.
70+
* @returns {string} The stats card SVG object.
6971
*/
7072
const renderStatsCard = (stats = {}, options = { hide: [] }) => {
7173
const {

src/cards/top-languages-card.js

+45-41
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ const CARD_PADDING = 25;
2323
*/
2424

2525
/**
26-
* Retrieves the programming language whose name is the longest
26+
* Retrieves the programming language whose name is the longest.
2727
*
28-
* @param {Lang[]} arr
29-
* @returns {Object} longest lang obj
28+
* @param {Lang[]} arr Array of programming languages.
29+
* @returns {Object} Longest programming language object.
3030
*/
3131
const getLongestLang = (arr) =>
3232
arr.reduce(
@@ -37,15 +37,14 @@ const getLongestLang = (arr) =>
3737

3838
/**
3939
* Creates a node to display usage of a programming language in percentage
40-
* using text and a horizontal progress bar
40+
* using text and a horizontal progress bar.
4141
*
42-
* @param {{
43-
* width: number,
44-
* color: string,
45-
* name: string,
46-
* progress: string
47-
* }} props
48-
* @returns {string} progress text node
42+
* @param {object[]} props Function properties.
43+
* @param {number} props.width The card width
44+
* @param {string} props.name Name of the programming language.
45+
* @param {string} props.color Color of the programming language.
46+
* @param {string} props.progress Usage of the programming language in percentage.
47+
* @returns {string} Programming language SVG node.
4948
*/
5049
const createProgressTextNode = ({ width, color, name, progress }) => {
5150
const paddingRight = 95;
@@ -67,10 +66,12 @@ const createProgressTextNode = ({ width, color, name, progress }) => {
6766
};
6867

6968
/**
70-
* Creates a text only node to display usage of a programming language in percentage
69+
* Creates a text only node to display usage of a programming language in percentage.
7170
*
72-
* @param {{ lang: Lang, totalSize: number }} props
73-
* @returns {string} text node
71+
* @param {object[]} props Function properties.
72+
* @param {Lang} props.lang Programming language object.
73+
* @param {number} props.totalSize Total size of all languages.
74+
* @returns {string} Compact layout programming language SVG node.
7475
*/
7576
const createCompactLangNode = ({ lang, totalSize }) => {
7677
const percentage = ((lang.size / totalSize) * 100).toFixed(2);
@@ -87,10 +88,12 @@ const createCompactLangNode = ({ lang, totalSize }) => {
8788
};
8889

8990
/**
90-
* Creates compact layout of text only language nodes
91+
* Creates compact layout of text only language nodes.
9192
*
92-
* @param {{ langs: Lang[], totalSize: number }} props
93-
* @returns {string} text nodes layout
93+
* @param {object[]} props Function properties.
94+
* @param {Lang[]} props.langs Array of programming languages.
95+
* @param {number} props.totalSize Total size of all languages.
96+
* @returns {string} Programming languages SVG node.
9497
*/
9598
const createLanguageTextNode = ({ langs, totalSize }) => {
9699
const longestLang = getLongestLang(langs);
@@ -122,12 +125,12 @@ const createLanguageTextNode = ({ langs, totalSize }) => {
122125
};
123126

124127
/**
125-
* Renders layout to display user's most frequently used programming languages
128+
* Renders layout to display user's most frequently used programming languages.
126129
*
127-
* @param {Lang[]} langs
128-
* @param {number} width
129-
* @param {number} totalLanguageSize
130-
* @returns {string} normal layout
130+
* @param {Lang[]} langs Array of programming languages.
131+
* @param {number} width Card width.
132+
* @param {number} totalLanguageSize Total size of all languages.
133+
* @returns {string} Normal layout card SVG object.
131134
*/
132135
const renderNormalLayout = (langs, width, totalLanguageSize) => {
133136
return flexLayout({
@@ -145,12 +148,12 @@ const renderNormalLayout = (langs, width, totalLanguageSize) => {
145148
};
146149

147150
/**
148-
* Renders compact layout to display user's most frequently used programming languages
151+
* Renders compact layout to display user's most frequently used programming languages.
149152
*
150-
* @param {Lang[]} langs
151-
* @param {number} width
152-
* @param {number} totalLanguageSize
153-
* @returns {string} compact layout
153+
* @param {Lang[]} langs Array of programming languages.
154+
* @param {number} width Card width.
155+
* @param {number} totalLanguageSize Total size of all languages.
156+
* @returns {string} Compact layout card SVG object.
154157
*/
155158
const renderCompactLayout = (langs, width, totalLanguageSize) => {
156159
const paddingRight = 50;
@@ -198,30 +201,31 @@ const renderCompactLayout = (langs, width, totalLanguageSize) => {
198201
};
199202

200203
/**
201-
* Calculates height for the compact layout
204+
* Calculates height for the compact layout.
202205
*
203-
* @param {number} totalLangs
204-
* @returns {number} height
206+
* @param {number} totalLangs Total number of languages.
207+
* @returns {number} Card height.
205208
*/
206209
const calculateCompactLayoutHeight = (totalLangs) => {
207210
return 90 + Math.round(totalLangs / 2) * 25;
208211
};
209212

210213
/**
211-
* Calculates height for the normal layout
214+
* Calculates height for the normal layout.
212215
*
213-
* @param {number} totalLangs
214-
* @returns {number} height
216+
* @param {number} totalLangs Total number of languages.
217+
* @returns {number} Card height.
215218
*/
216219
const calculateNormalLayoutHeight = (totalLangs) => {
217220
return 45 + (totalLangs + 1) * 40;
218221
};
219222

220223
/**
221-
*
222-
* @param {Record<string, Lang>} topLangs
223-
* @param {string[]} hide
224-
* @param {string} langs_count
224+
* Hides languages and trims the list to show only the top N languages.
225+
*
226+
* @param {Record<string, Lang>} topLangs Top languages.
227+
* @param {string[]} hide Languages to hide.
228+
* @param {string} langs_count Number of languages to show.
225229
*/
226230
const useLanguages = (topLangs, hide, langs_count) => {
227231
let langs = Object.values(topLangs);
@@ -250,11 +254,11 @@ const useLanguages = (topLangs, hide, langs_count) => {
250254
};
251255

252256
/**
253-
* Renders card to display user's most frequently used programming languages
257+
* Renders card to display user's most frequently used programming languages.
254258
*
255-
* @param {import('../fetchers/types').TopLangData} topLangs
256-
* @param {Partial<import("./types").TopLangOptions>} options
257-
* @returns {string}
259+
* @param {import('../fetchers/types').TopLangData} topLangs User's most frequently used programming languages.
260+
* @param {Partial<import("./types").TopLangOptions>} options Card options.
261+
* @returns {string} Language card SVG object.
258262
*/
259263
const renderTopLanguages = (topLangs, options = {}) => {
260264
const {

src/cards/wakatime-card.js

+37-31
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ const require = createRequire(import.meta.url);
2323
const languageColors = require("../common/languageColors.json"); // now works
2424

2525
/**
26-
* @param {{color: string, text: string}} param0
26+
* Creates the no coding activity SVG node.
27+
*
28+
* @param {{color: string, text: string}} The function prop
2729
*/
2830
const noCodingActivityNode = ({ color, text }) => {
2931
return `
@@ -32,13 +34,13 @@ const noCodingActivityNode = ({ color, text }) => {
3234
};
3335

3436
/**
35-
*
36-
* @param {{
37-
* lang: import("../fetchers/types").WakaTimeLang,
38-
* totalSize: number,
39-
* x: number,
40-
* y: number
41-
* }} props
37+
* Create compact WakaTime layout.
38+
*
39+
* @param {Object[]} args The function arguments.
40+
* @param {import("../fetchers/types").WakaTimeLang[]} languages The languages array.
41+
* @param {number} totalSize The total size of the languages.
42+
* @param {number} x The x position of the language node.
43+
* @param {number} y The y position of the language node.
4244
*/
4345
const createCompactLangNode = ({ lang, totalSize, x, y }) => {
4446
const color = languageColors[lang.name] || "#858585";
@@ -54,12 +56,13 @@ const createCompactLangNode = ({ lang, totalSize, x, y }) => {
5456
};
5557

5658
/**
57-
* @param {{
58-
* langs: import("../fetchers/types").WakaTimeLang[],
59-
* totalSize: number,
60-
* x: number,
61-
* y: number
62-
* }} props
59+
* Create WakaTime language text node item.
60+
*
61+
* @param {Object[]} args The function arguments.
62+
* @param {import("../fetchers/types").WakaTimeLang} lang The language object.
63+
* @param {number} totalSize The total size of the languages.
64+
* @param {number} x The x position of the language node.
65+
* @param {number} y The y position of the language node.
6366
*/
6467
const createLanguageTextNode = ({ langs, totalSize, x, y }) => {
6568
return langs.map((lang, index) => {
@@ -81,17 +84,16 @@ const createLanguageTextNode = ({ langs, totalSize, x, y }) => {
8184
};
8285

8386
/**
84-
*
85-
* @param {{
86-
* id: string;
87-
* label: string;
88-
* value: string;
89-
* index: number;
90-
* percent: number;
91-
* hideProgress: boolean;
92-
* progressBarColor: string;
93-
* progressBarBackgroundColor: string
94-
* }} props
87+
* Create WakaTime text item.
88+
*
89+
* @param {Object[]} args The function arguments.
90+
* @param {string} id The id of the text node item.
91+
* @param {string} label The label of the text node item.
92+
* @param {string} value The value of the text node item.
93+
* @param {number} index The index of the text node item.
94+
* @param {percent} percent Percentage of the text node item.
95+
* @param {boolean} hideProgress Whether to hide the progress bar.
96+
* @param {string} progressBarBackgroundColor The color of the progress bar background.
9597
*/
9698
const createTextNode = ({
9799
id,
@@ -132,11 +134,13 @@ const createTextNode = ({
132134
};
133135

134136
/**
135-
* @param {import("../fetchers/types").WakaTimeLang[]} languages
137+
* Recalculating percentages so that, compact layout's progress bar does not break when
138+
* hiding languages.
139+
*
140+
* @param {import("../fetchers/types").WakaTimeLang[]} languages The languages array.
141+
* @return {import("../fetchers/types").WakaTimeLang[]} The recalculated languages array.
136142
*/
137143
const recalculatePercentages = (languages) => {
138-
// recalculating percentages so that,
139-
// compact layout's progress bar does not break when hiding languages
140144
const totalSum = languages.reduce(
141145
(totalSum, language) => totalSum + language.percent,
142146
0,
@@ -148,9 +152,11 @@ const recalculatePercentages = (languages) => {
148152
};
149153

150154
/**
151-
* @param {Partial<import('../fetchers/types').WakaTimeData>} stats
152-
* @param {Partial<import('./types').WakaTimeOptions>} options
153-
* @returns {string}
155+
* Renders WakaTime card.
156+
*
157+
* @param {Partial<import('../fetchers/types').WakaTimeData>} stats WakaTime stats.
158+
* @param {Partial<import('./types').WakaTimeOptions>} options Card options.
159+
* @returns {string} WakaTime card SVG.
154160
*/
155161
const renderWakatimeCard = (stats = {}, options = { hide: [] }) => {
156162
let { languages } = stats;

0 commit comments

Comments
 (0)