( input: string, re: RegExp, replacer: (match: RegExpExecArray) => string | Promise<string>, )
| 344 | } |
| 345 | |
| 346 | export async function asyncReplace( |
| 347 | input: string, |
| 348 | re: RegExp, |
| 349 | replacer: (match: RegExpExecArray) => string | Promise<string>, |
| 350 | ): Promise<string> { |
| 351 | let match: RegExpExecArray | null |
| 352 | let remaining = input |
| 353 | let rewritten = '' |
| 354 | while ((match = re.exec(remaining))) { |
| 355 | rewritten += remaining.slice(0, match.index) |
| 356 | rewritten += await replacer(match) |
| 357 | remaining = remaining.slice(match.index + match[0].length) |
| 358 | } |
| 359 | rewritten += remaining |
| 360 | return rewritten |
| 361 | } |
| 362 | |
| 363 | export function timeFrom(start: number, subtract = 0): string { |
| 364 | const time: number | string = performance.now() - start - subtract |
no test coverage detected