Skip to content

Commit b7e5611

Browse files
author
tamilr0727-ux
committed
docs(svg): add JSDoc comments for svg generator exports
1 parent 40df8e9 commit b7e5611

1 file changed

Lines changed: 84 additions & 0 deletions

File tree

lib/svg/generator.ts

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,26 @@ function createScaler(sf: number): Scaler {
4848
return (n: number): number => Math.round(n * sf);
4949
}
5050

51+
/**
52+
* Escapes special XML characters in a string so it can be safely
53+
* embedded inside SVG or XML markup.
54+
*
55+
* Converts:
56+
* - & to &
57+
* - < to &lt;
58+
* - > to &gt;
59+
* - " to &quot;
60+
* - ' to &#39;
61+
*
62+
* @param str - Raw string that may contain XML-sensitive characters.
63+
*
64+
* @returns An XML-safe escaped string.
65+
*
66+
* @example
67+
* const safe = escapeXML('<text>Hello & Welcome</text>');
68+
* // Returns:
69+
* // '&lt;text&gt;Hello &amp; Welcome&lt;/text&gt;'
70+
*/
5171
export function escapeXML(str: string): string {
5272
return str
5373
.replace(/&/g, '&amp;')
@@ -185,6 +205,42 @@ function renderFooter(
185205
}
186206

187207
// ── Main static-theme renderer ────────────────────────────────────────────
208+
209+
/**
210+
* Generates the main CommitPulse SVG badge using contribution
211+
* calendar data and streak statistics.
212+
*
213+
* The SVG includes animated contribution towers, statistics,
214+
* theme styling, and optional auto-theme support.
215+
*
216+
* @param stats - Contribution streak statistics including current streak,
217+
* longest streak, total contributions, and today's date.
218+
* @param params - Badge customization options such as colors, fonts,
219+
* animations, scaling, visibility toggles, and theme settings.
220+
* @param params.autoTheme - Enables automatic switching between
221+
* light and dark themes based on the user's system color scheme.
222+
* @param calendar - Contribution calendar data containing weekly
223+
contribution entries and per-day contribution counts used to
224+
generate the tower layout.
225+
*
226+
* @returns A fully generated SVG badge string.
227+
*
228+
* @example
229+
* const svg = generateSVG(
230+
* {
231+
* currentStreak: 12,
232+
* longestStreak: 30,
233+
* totalContributions: 542,
234+
* todayDate: '2026-05-27',
235+
* },
236+
* {
237+
* user: 'octocat',
238+
* autoTheme: true,
239+
* accent: '00ffaa',
240+
* },
241+
* calendar
242+
* );
243+
*/
188244
export function generateSVG(
189245
stats: StreakStats,
190246
params: BadgeParams,
@@ -505,6 +561,34 @@ function generateAutoThemeMonthlySVG(stats: MonthlyStats, params: BadgeParams):
505561
`;
506562
}
507563

564+
/**
565+
* Generates a fallback SVG badge for users that do not exist
566+
* or when contribution data cannot be loaded.
567+
*
568+
* The SVG renders a ghost-style city layout with an animated
569+
* error-state design while preserving the standard badge layout.
570+
*
571+
* @param username - GitHub username displayed in the error badge.
572+
* @param bg - Background color used for the SVG container.
573+
* @param accent - Accent color used for highlights, outlines,
574+
* and animated elements.
575+
* @param text - Primary text color used throughout the badge.
576+
* @param radius - Border radius applied to the SVG background.
577+
* @param speed - Animation speed for the radar scan effect.
578+
* Defaults to '8s'.
579+
*
580+
* @returns A generated SVG string representing the not-found state.
581+
*
582+
* @example
583+
* const svg = generateNotFoundSVG(
584+
* 'octocat',
585+
* '#0d1117',
586+
* '#00ffaa',
587+
* '#ffffff',
588+
* 8,
589+
* '8s'
590+
* );
591+
*/
508592
export function generateNotFoundSVG(
509593
username: string,
510594
bg: string,

0 commit comments

Comments
 (0)