MCPcopy
hub / github.com/tailwindlabs/tailwindcss / wordWrap

Function wordWrap

packages/@tailwindcss-cli/src/utils/renderer.ts:43–67  ·  view source on GitHub ↗
(text: string, width: number)

Source from the content-addressed store, hash-verified

41 * Wrap `text` into multiple lines based on the `width`.
42 */
43export function wordWrap(text: string, width: number) {
44 let words = text.split(' ')
45 let lines = []
46
47 let line = ''
48 let lineLength = 0
49 for (let word of words) {
50 let wordLength = stripVTControlCharacters(word).length
51
52 if (lineLength + wordLength + 1 > width) {
53 lines.push(line)
54 line = ''
55 lineLength = 0
56 }
57
58 line += (lineLength ? ' ' : '') + word
59 lineLength += wordLength + (lineLength ? 1 : 0)
60 }
61
62 if (lineLength) {
63 lines.push(line)
64 }
65
66 return lines
67}
68
69/**
70 * Format a duration in nanoseconds to a more human readable format.

Callers 2

renderer.test.tsFile · 0.90
helpFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected