( input: string, pattern: RegExp, replacement: string, maxIterations = 100 )
| 100 | * like `<scr<script>ipt>`. |
| 101 | */ |
| 102 | export function replaceUntilStable( |
| 103 | input: string, |
| 104 | pattern: RegExp, |
| 105 | replacement: string, |
| 106 | maxIterations = 100 |
| 107 | ): string { |
| 108 | let prev = input |
| 109 | let next = prev.replace(pattern, replacement) |
| 110 | let iterations = 0 |
| 111 | while (next !== prev && iterations++ < maxIterations) { |
| 112 | prev = next |
| 113 | next = prev.replace(pattern, replacement) |
| 114 | } |
| 115 | return next |
| 116 | } |
| 117 | |
| 118 | const HTML_ENTITY_MAP: Record<string, string> = { |
| 119 | ' ': ' ', |
no test coverage detected