A line-based operational transform algorithm
npm install otjs
var transform = require('otjs');
var res = transform.transformBatch([
// Operation "S"
{ type: 'del', line: 0 },
{ type: 'del', line: 0 },
{ type: 'del', line: 0 }
], [
// Operation "C"
{ type: 'add', line: 0, text: '0' },
{ type: 'add', line: 2, text: '2' },
{ type: 'add', line: 4, text: '4' }
]);
expect(res).to.eql([
[
// Operation "S'"
{ type: 'del', line: 1 },
{ type: 'del', line: 2 },
{ type: 'del', line: 3 }
], [
// Operation "C'"
{ type: 'add', line: 0, text: '0' },
{ type: 'add', line: 1, text: '2' },
{ type: 'add', line: 2, text: '4' }
]
]);
// S + C' === C + S'