(a: string, operations: Operation[])
| 1 | import type { Operation } from './diff'; |
| 2 | |
| 3 | export function patch(a: string, operations: Operation[]) { |
| 4 | let result = ''; |
| 5 | |
| 6 | for (const op of operations) { |
| 7 | if (op.type === 'COPY') { |
| 8 | result += a.slice(op.start, op.start + op.len); |
| 9 | } else if (op.type === 'INSERT') { |
| 10 | result += op.content; |
| 11 | } |
| 12 | } |
| 13 | |
| 14 | return result; |
| 15 | } |