MCPcopy Create free account
hub / github.com/arctic-cli/interface / trimDiff

Function trimDiff

packages/arctic/src/tool/edit.ts:606–640  ·  view source on GitHub ↗
(diff: string)

Source from the content-addressed store, hash-verified

604}
605
606export function trimDiff(diff: string): string {
607 const lines = diff.split("\n")
608 const contentLines = lines.filter(
609 (line) =>
610 (line.startsWith("+") || line.startsWith("-") || line.startsWith(" ")) &&
611 !line.startsWith("---") &&
612 !line.startsWith("+++"),
613 )
614
615 if (contentLines.length === 0) return diff
616
617 let min = Infinity
618 for (const line of contentLines) {
619 const content = line.slice(1)
620 if (content.trim().length > 0) {
621 const match = content.match(/^(\s*)/)
622 if (match) min = Math.min(min, match[1].length)
623 }
624 }
625 if (min === Infinity || min === 0) return diff
626 const trimmedLines = lines.map((line) => {
627 if (
628 (line.startsWith("+") || line.startsWith("-") || line.startsWith(" ")) &&
629 !line.startsWith("---") &&
630 !line.startsWith("+++")
631 ) {
632 const prefix = line[0]
633 const content = line.slice(1)
634 return prefix + content.slice(min)
635 }
636 return line
637 })
638
639 return trimmedLines.join("\n")
640}
641
642export function replace(content: string, oldString: string, newString: string, replaceAll = false): string {
643 if (oldString === newString) {

Callers 1

executeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected