( text: string, searchValue: RegExp | string, replacer: (substring: string, ...args: any[]) => Promise<string> | string, )
| 32 | * ``` |
| 33 | */ |
| 34 | export async function replaceAllAsync( |
| 35 | text: string, |
| 36 | searchValue: RegExp | string, |
| 37 | replacer: (substring: string, ...args: any[]) => Promise<string> | string, |
| 38 | ): Promise<string> { |
| 39 | const promises: (Promise<string> | string)[] = []; |
| 40 | |
| 41 | text.replaceAll(searchValue, (...args) => { |
| 42 | promises.push(replacer(...args)); |
| 43 | return ""; |
| 44 | }); |
| 45 | |
| 46 | const results = (await Promise.all(promises))[Symbol.iterator](); |
| 47 | return text.replaceAll(searchValue, () => results.next().value!); |
| 48 | } |
no test coverage detected