MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / addLineNumbers

Function addLineNumbers

src/integrations/misc/extract-text.ts:136–160  ·  view source on GitHub ↗
(content: string, startLine: number = 1)

Source from the content-addressed store, hash-verified

134}
135
136export function addLineNumbers(content: string, startLine: number = 1): string {
137 // If content is empty, return empty string - empty files should not have line numbers
138 // If content is empty but startLine > 1, return "startLine | " because we know the file is not empty
139 // but the content is empty at that line offset
140 if (content === "") {
141 return startLine === 1 ? "" : `${startLine} | \n`
142 }
143
144 // Split into lines and handle trailing line feeds (\n)
145 const lines = content.split("\n")
146 const lastLineEmpty = lines[lines.length - 1] === ""
147 if (lastLineEmpty) {
148 lines.pop()
149 }
150
151 const maxLineNumberWidth = String(startLine + lines.length - 1).length
152 const numberedContent = lines
153 .map((line, index) => {
154 const lineNumber = String(startLine + index).padStart(maxLineNumberWidth, " ")
155 return `${lineNumber} | ${line}`
156 })
157 .join("\n")
158
159 return numberedContent + "\n"
160}
161// Checks if every line in the content has line numbers prefixed (e.g., "1 | content" or "123 | content")
162// Line numbers must be followed by a single pipe character (not double pipes)
163export function everyLineHasLineNumbers(content: string): boolean {

Callers 6

handleBinaryFileMethod · 0.90
applyDiffMethod · 0.90
extractTextFromPDFFunction · 0.85
extractTextFromDOCXFunction · 0.85
extractTextFromIPYNBFunction · 0.85

Calls 2

popMethod · 0.80
StringInterface · 0.50

Tested by

no test coverage detected