* Apply replacements to the original lines, returning the modified content. * Replacements must be applied in reverse order to preserve indices.
(lines: string[], replacements: Array<[number, number, string[]]>)
| 99 | * Replacements must be applied in reverse order to preserve indices. |
| 100 | */ |
| 101 | function applyReplacements(lines: string[], replacements: Array<[number, number, string[]]>): string[] { |
| 102 | const result = [...lines] |
| 103 | |
| 104 | // Apply in reverse order so earlier replacements don't shift later indices |
| 105 | for (let i = replacements.length - 1; i >= 0; i--) { |
| 106 | const [startIdx, oldLen, newSegment] = replacements[i]! |
| 107 | |
| 108 | // Remove old lines |
| 109 | result.splice(startIdx, oldLen, ...newSegment) |
| 110 | } |
| 111 | |
| 112 | return result |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * Apply chunks to file content, returning the new content. |
no outgoing calls
no test coverage detected