(diff: string)
| 644 | } |
| 645 | |
| 646 | export function trimDiff(diff: string): string { |
| 647 | const lines = diff.split("\n") |
| 648 | const contentLines = lines.filter( |
| 649 | (line) => |
| 650 | (line.startsWith("+") || line.startsWith("-") || line.startsWith(" ")) && |
| 651 | !line.startsWith("---") && |
| 652 | !line.startsWith("+++"), |
| 653 | ) |
| 654 | |
| 655 | if (contentLines.length === 0) return diff |
| 656 | |
| 657 | let min = Infinity |
| 658 | for (const line of contentLines) { |
| 659 | const content = line.slice(1) |
| 660 | if (content.trim().length > 0) { |
| 661 | const match = content.match(/^(\s*)/) |
| 662 | if (match) min = Math.min(min, match[1].length) |
| 663 | } |
| 664 | } |
| 665 | if (min === Infinity || min === 0) return diff |
| 666 | const trimmedLines = lines.map((line) => { |
| 667 | if ( |
| 668 | (line.startsWith("+") || line.startsWith("-") || line.startsWith(" ")) && |
| 669 | !line.startsWith("---") && |
| 670 | !line.startsWith("+++") |
| 671 | ) { |
| 672 | const prefix = line[0] |
| 673 | const content = line.slice(1) |
| 674 | return prefix + content.slice(min) |
| 675 | } |
| 676 | return line |
| 677 | }) |
| 678 | |
| 679 | return trimmedLines.join("\n") |
| 680 | } |
| 681 | |
| 682 | export function replace(content: string, oldString: string, newString: string, replaceAll = false): string { |
| 683 | if (oldString === newString) { |
no outgoing calls
no test coverage detected