MCPcopy Create free account
hub / github.com/denoland/std / replaceAllAsync

Function replaceAllAsync

regexp/unstable_replace_all_async.ts:34–48  ·  view source on GitHub ↗
(
  text: string,
  searchValue: RegExp | string,
  replacer: (substring: string, ...args: any[]) => Promise<string> | string,
)

Source from the content-addressed store, hash-verified

32 * ```
33 */
34export 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}

Calls 2

pushMethod · 0.45
nextMethod · 0.45

Tested by

no test coverage detected