Home / Function/ wordWrap() — tailwindcss Function Reference

wordWrap() — tailwindcss Function Reference

Architecture documentation for the wordWrap() function in renderer.ts from the tailwindcss codebase.

Entity Profile

Dependency Diagram

graph TD
  6a3f8228_9c9b_2250_dbb5_c6512f68df39["wordWrap()"]
  fa9abad4_74c6_c2f4_3ecf_50b0b73a6013["help()"]
  fa9abad4_74c6_c2f4_3ecf_50b0b73a6013 -->|calls| 6a3f8228_9c9b_2250_dbb5_c6512f68df39
  c3280d10_269f_8701_bd4c_48a551b9b4ae["log()"]
  c3280d10_269f_8701_bd4c_48a551b9b4ae -->|calls| 6a3f8228_9c9b_2250_dbb5_c6512f68df39
  style 6a3f8228_9c9b_2250_dbb5_c6512f68df39 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/@tailwindcss-upgrade/src/utils/renderer.ts lines 43–73

export function wordWrap(text: string, width: number): string[] {
  // Handle text with newlines by maintaining the newlines, then splitting
  // each line separately.
  if (text.includes('\n')) {
    return text.split('\n').flatMap((line) => (line ? wordWrap(line, width) : ['']))
  }

  let words = text.split(' ')
  let lines = []

  let line = ''
  let lineLength = 0
  for (let word of words) {
    let wordLength = stripVTControlCharacters(word).length

    if (lineLength + wordLength + 1 > width) {
      lines.push(line)
      line = ''
      lineLength = 0
    }

    line += (lineLength ? ' ' : '') + word
    lineLength += wordLength + (lineLength ? 1 : 0)
  }

  if (lineLength) {
    lines.push(line)
  }

  return lines
}

Domain

Subdomains

Called By

Frequently Asked Questions

What does wordWrap() do?
wordWrap() is a function in the tailwindcss codebase.
What calls wordWrap()?
wordWrap() is called by 2 function(s): help, log.

Analyze Your Own Codebase

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

Try Supermodel Free