MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / safeJoinLines

Function safeJoinLines

source code/utils/stringUtils.ts:100–135  ·  view source on GitHub ↗
(
  lines: string[],
  delimiter: string = ',',
  maxSize: number = MAX_STRING_LENGTH,
)

Source from the content-addressed store, hash-verified

98 * @returns The joined string, truncated if necessary
99 */
100export function safeJoinLines(
101 lines: string[],
102 delimiter: string = ',',
103 maxSize: number = MAX_STRING_LENGTH,
104): string {
105 const truncationMarker = '...[truncated]'
106 let result = ''
107
108 for (const line of lines) {
109 const delimiterToAdd = result ? delimiter : ''
110 const fullAddition = delimiterToAdd + line
111
112 if (result.length + fullAddition.length <= maxSize) {
113 // The full line fits
114 result += fullAddition
115 } else {
116 // Need to truncate
117 const remainingSpace =
118 maxSize -
119 result.length -
120 delimiterToAdd.length -
121 truncationMarker.length
122
123 if (remainingSpace > 0) {
124 // Add delimiter and as much of the line as will fit
125 result +=
126 delimiterToAdd + line.slice(0, remainingSpace) + truncationMarker
127 } else {
128 // No room for any of this line, just add truncation marker
129 result += truncationMarker
130 }
131 return result
132 }
133 }
134 return result
135}
136
137/**
138 * A string accumulator that safely handles large outputs by truncating from the end

Callers 2

#updateProgressMethod · 0.85
getStdoutMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected