* Strip markdown code fences that LLMs commonly wrap code in. * Handles ```js, ```javascript, ```typescript, ```ts, or bare ```.
(code: string)
| 5 | * Handles ```js, ```javascript, ```typescript, ```ts, or bare ```. |
| 6 | */ |
| 7 | function stripCodeFences(code: string): string { |
| 8 | const fenced = |
| 9 | /^```(?:js|javascript|typescript|ts|tsx|jsx)?\s*\n([\s\S]*?)```\s*$/; |
| 10 | const match = code.match(fenced); |
| 11 | return match ? match[1] : code; |
| 12 | } |
| 13 | |
| 14 | export function normalizeCode(code: string): string { |
| 15 | const trimmed = stripCodeFences(code.trim()); |