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
  7dd8ee93_7980_3539_ed2a_eeed062615e8["doUrlReplace()"]
  5e3855e0_f04e_28ee_98ea_8502e6531bc8["urls.ts"]
  7dd8ee93_7980_3539_ed2a_eeed062615e8 -->|defined in| 5e3855e0_f04e_28ee_98ea_8502e6531bc8
  e05e1697_3d67_86a0_04e6_5227a1370bea["rewriteCssUrls()"]
  e05e1697_3d67_86a0_04e6_5227a1370bea -->|calls| 7dd8ee93_7980_3539_ed2a_eeed062615e8
  1a0c0ebf_cd90_07bb_b4e5_e972ca328a5b["rewriteCssImageSet()"]
  1a0c0ebf_cd90_07bb_b4e5_e972ca328a5b -->|calls| 7dd8ee93_7980_3539_ed2a_eeed062615e8
  a1913d05_1c71_5b7d_a56a_6addaacebefe["skipUrlReplacer()"]
  7dd8ee93_7980_3539_ed2a_eeed062615e8 -->|calls| a1913d05_1c71_5b7d_a56a_6addaacebefe
  style 7dd8ee93_7980_3539_ed2a_eeed062615e8 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, defined in packages/@tailwindcss-node/src/urls.ts.
Where is doUrlReplace() defined?
doUrlReplace() is defined in packages/@tailwindcss-node/src/urls.ts at line 119.
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