MCPcopy Create free account
hub / github.com/codeaashu/claude-code / truncate

Function truncate

src/utils/truncate.ts:134–158  ·  view source on GitHub ↗
(
  str: string,
  maxWidth: number,
  singleLine: boolean = false,
)

Source from the content-addressed store, hash-verified

132 * @returns The truncated string with ellipsis if needed
133 */
134export function truncate(
135 str: string,
136 maxWidth: number,
137 singleLine: boolean = false,
138): string {
139 let result = str
140
141 // If singleLine is true, truncate at first newline
142 if (singleLine) {
143 const firstNewline = str.indexOf('\n')
144 if (firstNewline !== -1) {
145 result = str.substring(0, firstNewline)
146 // Ensure total width including ellipsis doesn't exceed maxWidth
147 if (stringWidth(result) + 1 > maxWidth) {
148 return truncateToWidth(result, maxWidth)
149 }
150 return `${result}…`
151 }
152 }
153
154 if (stringWidth(result) <= maxWidth) {
155 return result
156 }
157 return truncateToWidth(result, maxWidth)
158}
159
160export function wrapText(text: string, width: number): string[] {
161 const lines: string[] = []

Callers 2

formatModelAndBillingFunction · 0.70

Calls 1

truncateToWidthFunction · 0.85

Tested by

no test coverage detected