invert
ts
function Delta.invert(a: Delta, b: Delta): DeltaReturns the inverse of a delta against a base document. Applying the inverted delta undoes the original change.
Example
ts
import { Delta } from "@monstermann/delta";
const base = Delta.insert([], "Hello");
const change = Delta.retain([], 5, { bold: true });
Delta.invert(change, base);
// [{ retain: 5, attributes: { bold: null } }]
const insert = pipe(
[],
Delta.retain(5),
Delta.insert(" world")
);
Delta.invert(insert, base);
// [{ retain: 5 },
// { delete: 6 }]ts
import { Delta } from "@monstermann/delta";
const base = Delta.insert([], "Hello");
const change = Delta.retain([], 5, { bold: true });
pipe(change, Delta.invert(base));
// [{ retain: 5, attributes: { bold: null } }]