Home / Function/ expand() — tailwindcss Function Reference

expand() — tailwindcss Function Reference

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

Function typescript Oxide Scanner calls 3 called by 1

Entity Profile

Dependency Diagram

graph TD
  91a1286b_b296_e99a_4150_7ded5cd2aa4e["expand()"]
  dc817c0a_ee3b_7666_cb9d_ef0ab5b72986["brace-expansion.ts"]
  91a1286b_b296_e99a_4150_7ded5cd2aa4e -->|defined in| dc817c0a_ee3b_7666_cb9d_ef0ab5b72986
  f7f9b3da_5977_1aa6_3bcb_bfc607af4e8f["parseCss()"]
  f7f9b3da_5977_1aa6_3bcb_bfc607af4e8f -->|calls| 91a1286b_b296_e99a_4150_7ded5cd2aa4e
  7f779319_2084_3459_2543_7ef8d81e0f08["isSequence()"]
  91a1286b_b296_e99a_4150_7ded5cd2aa4e -->|calls| 7f779319_2084_3459_2543_7ef8d81e0f08
  0239eea1_54ce_d149_ab68_b39617f815f1["expandSequence()"]
  91a1286b_b296_e99a_4150_7ded5cd2aa4e -->|calls| 0239eea1_54ce_d149_ab68_b39617f815f1
  c58cbb33_f3cc_0b4f_844a_15bf66a1dc61["segment()"]
  91a1286b_b296_e99a_4150_7ded5cd2aa4e -->|calls| c58cbb33_f3cc_0b4f_844a_15bf66a1dc61
  style 91a1286b_b296_e99a_4150_7ded5cd2aa4e 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