MCPcopy
hub / github.com/vitejs/vite / asyncReplace

Function asyncReplace

packages/vite/src/node/utils.ts:346–361  ·  view source on GitHub ↗
(
  input: string,
  re: RegExp,
  replacer: (match: RegExpExecArray) => string | Promise<string>,
)

Source from the content-addressed store, hash-verified

344}
345
346export 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
363export function timeFrom(start: number, subtract = 0): string {
364 const time: number | string = performance.now() - start - subtract

Callers 4

rewriteCssUrlsFunction · 0.90
rewriteCssDataUrisFunction · 0.90
rewriteImportCssFunction · 0.90
rewriteCssImageSetFunction · 0.90

Calls 1

replacerFunction · 0.85

Tested by

no test coverage detected