Answer the stability nits: the runs a trailing-anchored regex re-walks
CI / gate (push) Successful in 8s

This commit is contained in:
2026-09-01 20:11:41 +02:00
parent e68dbc41a3
commit 5a41547222
4 changed files with 45 additions and 34 deletions
+14 -2
View File
@@ -223,6 +223,18 @@ export function setextHeadingLevel(line: string): number | undefined {
return underline.startsWith('=') ? 1 : 2
}
export function trimSpace(text: string): string {
return text.replace(/^[ \t]+|[ \t]+$/g, '')
function spaceOrTab(character: string): boolean {
return character === ' ' || character === '\t'
}
export function trimSpace(text: string): string {
let start = 0
while (start < text.length && spaceOrTab(text.charAt(start))) start += 1
return trimTrailingSpace(text.slice(start))
}
export function trimTrailingSpace(text: string): string {
let end = text.length
while (end > 0 && spaceOrTab(text.charAt(end - 1))) end -= 1
return text.slice(0, end)
}