insomnia/packages/insomnia-app/app/sync/delta/patch.ts
2021-05-19 08:32:18 +12:00

16 lines
336 B
TypeScript

import type { Operation } from './diff';
export function patch(a: string, operations: Operation[]) {
let result = '';
for (const op of operations) {
if (op.type === 'COPY') {
result += a.slice(op.start, op.start + op.len);
} else if (op.type === 'INSERT') {
result += op.content;
}
}
return result;
}