323
*/
324
export function replaceAsync(str: string, search: RegExp, replacer: (match: string, ...args: unknown[]) => Promise<string>): Promise<string> {
325
>
const parts: (string | Promise<string>)[] = [];
strings.ts
326
>
327
>
let last = 0;
328
>
for (const match of str.matchAll(search)) {
329
>
parts.push(str.slice(last, match.index));
330
>
if (match.index === undefined) {
331
throw new Error('match.index should be defined');
332
}
334
>
last = match.index + match[0].length;
335
>
parts.push(replacer(match[0], ...match.slice(1), match.index, str, match.groups));
336
>
}
337
>
338
>
parts.push(str.slice(last));
339
>
340
>
return Promise.all(parts).then(p => p.join(''));
341
>
}
342
343
export function compare(a: string, b: string): number {