MCPcopy
hub / github.com/codeaashu/claude-code / addLineNumbers

Function addLineNumbers

src/utils/file.ts:290–319  ·  view source on GitHub ↗
({
  content,
  // 1-indexed
  startLine,
}: {
  content: string
  startLine: number
})

Source from the content-addressed store, hash-verified

288 * Adds cat -n style line numbers to the content.
289 */
290export function addLineNumbers({
291 content,
292 // 1-indexed
293 startLine,
294}: {
295 content: string
296 startLine: number
297}): string {
298 if (!content) {
299 return ''
300 }
301
302 const lines = content.split(/\r?\n/)
303
304 if (isCompactLinePrefixEnabled()) {
305 return lines
306 .map((line, index) => `${index + startLine}\t${line}`)
307 .join('\n')
308 }
309
310 return lines
311 .map((line, index) => {
312 const numStr = String(index + startLine)
313 if (numStr.length >= 6) {
314 return `${numStr}→${line}`
315 }
316 return `${numStr.padStart(6, ' ')}→${line}`
317 })
318 .join('\n')
319}
320
321/**
322 * Inverse of addLineNumbers — strips the `N→` or `N\t` prefix from a single

Callers 2

formatFileLinesFunction · 0.85
getSnippetForPatchFunction · 0.85

Calls 1

Tested by

no test coverage detected