Home / Function/ doUrlReplace() — tailwindcss Function Reference

doUrlReplace() — tailwindcss Function Reference

Architecture documentation for the doUrlReplace() function in urls.ts from the tailwindcss codebase.

Entity Profile

Dependency Diagram

graph TD
  9709745c_f692_4b57_161b_4e10d26fd42b["doUrlReplace()"]
  76fabe9d_dc97_71ec_324d_538db5f890dc["rewriteCssUrls()"]
  76fabe9d_dc97_71ec_324d_538db5f890dc -->|calls| 9709745c_f692_4b57_161b_4e10d26fd42b
  3d9b4ec5_fe39_c58e_e6f0_b825053581d2["rewriteCssImageSet()"]
  3d9b4ec5_fe39_c58e_e6f0_b825053581d2 -->|calls| 9709745c_f692_4b57_161b_4e10d26fd42b
  d4593802_02fd_3f65_9480_0870f8bce3af["skipUrlReplacer()"]
  9709745c_f692_4b57_161b_4e10d26fd42b -->|calls| d4593802_02fd_3f65_9480_0870f8bce3af
  style 9709745c_f692_4b57_161b_4e10d26fd42b fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/@tailwindcss-node/src/urls.ts lines 119–151

async function doUrlReplace(
  rawUrl: string,
  matched: string,
  replacer: CssUrlReplacer,
  funcName: string = 'url',
) {
  let wrap = ''
  const first = rawUrl[0]
  if (first === `"` || first === `'`) {
    wrap = first
    rawUrl = rawUrl.slice(1, -1)
  }

  if (skipUrlReplacer(rawUrl)) {
    return matched
  }

  let newUrl = await replacer(rawUrl)
  // The new url might need wrapping even if the original did not have it, e.g. if a space was added during replacement
  if (wrap === '' && newUrl !== encodeURI(newUrl)) {
    wrap = '"'
  }
  // If wrapping in single quotes and newUrl also contains single quotes, switch to double quotes.
  // Give preference to double quotes since SVG inlining converts double quotes to single quotes.
  if (wrap === "'" && newUrl.includes("'")) {
    wrap = '"'
  }
  // Escape double quotes if they exist (they also tend to be rarer than single quotes)
  if (wrap === '"' && newUrl.includes('"')) {
    newUrl = newUrl.replace(nonEscapedDoubleQuoteRE, '\\"')
  }
  return `${funcName}(${wrap}${newUrl}${wrap})`
}

Domain

Subdomains

Frequently Asked Questions

What does doUrlReplace() do?
doUrlReplace() is a function in the tailwindcss codebase.
What does doUrlReplace() call?
doUrlReplace() calls 1 function(s): skipUrlReplacer.
What calls doUrlReplace()?
doUrlReplace() is called by 2 function(s): rewriteCssImageSet, rewriteCssUrls.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free