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
  c31510dc_31ef_7448_58a7_0d6f18e31e8d["wordWrap()"]
  2329d36e_5aa2_4fa5_cf9f_a9c6cc4e1277["renderer.ts"]
  c31510dc_31ef_7448_58a7_0d6f18e31e8d -->|defined in| 2329d36e_5aa2_4fa5_cf9f_a9c6cc4e1277
  b1bbf167_50da_cc65_0ade_524a7e4023cb["help()"]
  b1bbf167_50da_cc65_0ade_524a7e4023cb -->|calls| c31510dc_31ef_7448_58a7_0d6f18e31e8d
  b2526beb_7899_1404_bd41_2e8cb84eb3b4["log()"]
  b2526beb_7899_1404_bd41_2e8cb84eb3b4 -->|calls| c31510dc_31ef_7448_58a7_0d6f18e31e8d
  style c31510dc_31ef_7448_58a7_0d6f18e31e8d 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
}

Subdomains

Called By

Frequently Asked Questions

What does wordWrap() do?
wordWrap() is a function in the tailwindcss codebase, defined in packages/@tailwindcss-upgrade/src/utils/renderer.ts.
Where is wordWrap() defined?
wordWrap() is defined in packages/@tailwindcss-upgrade/src/utils/renderer.ts at line 43.
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