retain
ts
function Delta.retain(
ops: Delta,
length: number,
attributes?: OpAttributes | null,
): DeltaAdds a retain operation to the delta, optionally with attributes to apply formatting.
Example
ts
import { Delta } from "@monstermann/delta";
Delta.retain([], 5);
// [{ retain: 5 }]
Delta.retain([], 5, { bold: true });
// [{ retain: 5, attributes: { bold: true } }]ts
import { Delta } from "@monstermann/delta";
pipe([], Delta.retain(5));
// [{ retain: 5 }]
pipe(
[],
Delta.retain(3),
Delta.retain(2, { italic: true })
);
// [{ retain: 3 },
// { retain: 2, attributes: { italic: true } }]Removing attributes
Use null to remove an attribute when composing deltas:
ts
import { Delta } from "@monstermann/delta";
const doc = Delta.insert([], "Hello", { bold: true });
// [{ insert: "Hello", attributes: { bold: true } }]
const removeBold = Delta.retain([], 5, { bold: null });
// [{ retain: 5, attributes: { bold: null } }]
Delta.compose(doc, removeBold);
// [{ insert: "Hello" }]