( input: string, re: RegExp, replacer: (match: RegExpExecArray) => string | Promise<string>, )
| 190 | } |
| 191 | |
| 192 | async function asyncReplace( |
| 193 | input: string, |
| 194 | re: RegExp, |
| 195 | replacer: (match: RegExpExecArray) => string | Promise<string>, |
| 196 | ): Promise<string> { |
| 197 | let match: RegExpExecArray | null |
| 198 | let remaining = input |
| 199 | let rewritten = '' |
| 200 | while ((match = re.exec(remaining))) { |
| 201 | rewritten += remaining.slice(0, match.index) |
| 202 | rewritten += await replacer(match) |
| 203 | remaining = remaining.slice(match.index + match[0].length) |
| 204 | } |
| 205 | rewritten += remaining |
| 206 | return rewritten |
| 207 | } |
no test coverage detected