Skip to content

Commit

Permalink
refactor(heading): validate level (#28)
Browse files Browse the repository at this point in the history
Co-authored-by: Pooya Parsa <[email protected]>
  • Loading branch information
StrivingRabbit and pi0 authored Nov 26, 2024
1 parent 6f95ba4 commit 6f38211
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,16 @@
*
* @group render_utils
*/
export function heading(text: string, level: number): string {
return `\n${"#".repeat(level || 1)} ${text}\n`;
export function heading(
text: string,
level: 1 | 2 | 3 | 4 | 5 | 6 | (number & {}),
): string {
if (!level || level < 1) {
level = 1;
} else if (level > 6) {
level = 6;
}
return `\n${"#".repeat(level)} ${text}\n`;
}

/**
Expand Down

0 comments on commit 6f38211

Please sign in to comment.