(path: string, chunks: ReadonlyArray<UpdateFileChunk>, original: string)
| 69 | } |
| 70 | |
| 71 | export function derive(path: string, chunks: ReadonlyArray<UpdateFileChunk>, original: string): FileUpdate { |
| 72 | const source = splitBom(original) |
| 73 | const lines = source.text.split("\n") |
| 74 | if (lines.at(-1) === "") lines.pop() |
| 75 | const replacements = computeReplacements(lines, path, chunks) |
| 76 | const updated = [...lines] |
| 77 | for (const [start, remove, insert] of replacements.toReversed()) updated.splice(start, remove, ...insert) |
| 78 | if (updated.at(-1) !== "") updated.push("") |
| 79 | const next = splitBom(updated.join("\n")) |
| 80 | return { content: next.text, bom: source.bom || next.bom } |
| 81 | } |
| 82 | |
| 83 | export function joinBom(text: string, bom: boolean) { |
| 84 | const stripped = splitBom(text).text |
nothing calls this directly
no test coverage detected