MCPcopy Index your code
hub / github.com/codeaashu/claude-code / wrapText

Function wrapText

src/components/MarkdownTable.tsx:44–62  ·  view source on GitHub ↗

* Wrap text to fit within a given width, returning array of lines. * ANSI-aware: preserves styling across line breaks. * * @param hard - If true, break words that exceed width (needed when columns * are narrower than the longest word). Default false.

(text: string, width: number, options?: {
  hard?: boolean;
})

Source from the content-addressed store, hash-verified

42 * are narrower than the longest word). Default false.
43 */
44function wrapText(text: string, width: number, options?: {
45 hard?: boolean;
46}): string[] {
47 if (width <= 0) return [text];
48 // Strip trailing whitespace/newlines before wrapping.
49 // formatToken() adds EOL to paragraphs and other token types,
50 // which would otherwise create extra blank lines in table cells.
51 const trimmedText = text.trimEnd();
52 const wrapped = wrapAnsi(trimmedText, width, {
53 hard: options?.hard ?? false,
54 trim: false,
55 wordWrap: true
56 });
57 // Filter out empty lines that result from trailing newlines or
58 // multiple consecutive newlines in the source content.
59 const lines = wrapped.split('\n').filter(line => line.length > 0);
60 // Ensure we always return at least one line (empty string for empty cells)
61 return lines.length > 0 ? lines : [''];
62}
63
64/**
65 * Renders a markdown table using Ink's Box layout.

Callers 6

AgentLineFunction · 0.70
calculateMaxRowLinesFunction · 0.70
renderRowLinesFunction · 0.70
renderVerticalFormatFunction · 0.70
generateWordDiffElementsFunction · 0.50
formatDiffFunction · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected