Home / Function/ expand() — tailwindcss Function Reference

expand() — tailwindcss Function Reference

Architecture documentation for the expand() function in brace-expansion.ts from the tailwindcss codebase.

Entity Profile

Dependency Diagram

graph TD
  4e82d568_7e90_60c3_1671_8ea6ca89c260["expand()"]
  5df5aa0d_5ac4_161a_e624_dc3b15de4a28["brace-expansion.ts"]
  4e82d568_7e90_60c3_1671_8ea6ca89c260 -->|defined in| 5df5aa0d_5ac4_161a_e624_dc3b15de4a28
  3970218d_3d6c_e455_87cc_45b4a094f0e9["parseCss()"]
  3970218d_3d6c_e455_87cc_45b4a094f0e9 -->|calls| 4e82d568_7e90_60c3_1671_8ea6ca89c260
  d701d21e_a20e_b167_d3e4_fb033d63b4c8["isSequence()"]
  4e82d568_7e90_60c3_1671_8ea6ca89c260 -->|calls| d701d21e_a20e_b167_d3e4_fb033d63b4c8
  4737ac97_5889_1afc_badb_944e15af3828["expandSequence()"]
  4e82d568_7e90_60c3_1671_8ea6ca89c260 -->|calls| 4737ac97_5889_1afc_badb_944e15af3828
  f712ed47_45d4_4e5a_dd73_fdefa1da71da["segment()"]
  4e82d568_7e90_60c3_1671_8ea6ca89c260 -->|calls| f712ed47_45d4_4e5a_dd73_fdefa1da71da
  style 4e82d568_7e90_60c3_1671_8ea6ca89c260 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/tailwindcss/src/utils/brace-expansion.ts lines 5–53

export function expand(pattern: string): string[] {
  let index = pattern.indexOf('{')
  if (index === -1) return [pattern]

  let result: string[] = []
  let pre = pattern.slice(0, index)
  let rest = pattern.slice(index)

  // Find the matching closing brace
  let depth = 0
  let endIndex = rest.lastIndexOf('}')
  for (let i = 0; i < rest.length; i++) {
    let char = rest[i]
    if (char === '{') {
      depth++
    } else if (char === '}') {
      depth--
      if (depth === 0) {
        endIndex = i
        break
      }
    }
  }

  if (endIndex === -1) {
    throw new Error(`The pattern \`${pattern}\` is not balanced.`)
  }

  let inside = rest.slice(1, endIndex)
  let post = rest.slice(endIndex + 1)
  let parts: string[]

  if (isSequence(inside)) {
    parts = expandSequence(inside)
  } else {
    parts = segment(inside, ',')
  }

  parts = parts.flatMap((part) => expand(part))

  let expandedTail = expand(post)

  for (let tail of expandedTail) {
    for (let part of parts) {
      result.push(pre + part + tail)
    }
  }
  return result
}

Domain

Subdomains

Called By

Frequently Asked Questions

What does expand() do?
expand() is a function in the tailwindcss codebase, defined in packages/tailwindcss/src/utils/brace-expansion.ts.
Where is expand() defined?
expand() is defined in packages/tailwindcss/src/utils/brace-expansion.ts at line 5.
What does expand() call?
expand() calls 3 function(s): expandSequence, isSequence, segment.
What calls expand()?
expand() is called by 1 function(s): parseCss.

Analyze Your Own Codebase

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

Try Supermodel Free