@monstermann/delta
v0.4.0
Published
Functional operational-transform.
Readme
Functional operational-transform.
Differences from quill-delta
This library has been largely ported from quill-delta, some differences:
- Immutable, functions take and return plain arrays
- Support for nested attributes has been removed
- Cloning is only done when the data actually changes
- Deep-cloning has been replaced with shallow-cloning
- One dependency, fast-diff
Example
import { Delta } from "@monstermann/delta";
// Create a document
const doc = Delta.insert([], "Hello world");
// Create a change that makes "Hello" bold
const change = Delta.retain([], 5, { bold: true });
// Apply the change
const result = Delta.compose(doc, change);
// [{ insert: "Hello", attributes: { bold: true } },
// { insert: " world" }]
// Compute the difference between two documents
const a = Delta.insert([], "Hello");
const b = Delta.insert([], "Hello world");
Delta.diff(a, b);
// [{ retain: 5 },
// { insert: " world" }]Installation
bun add @monstermann/deltaAPI
Everything is documented with JSDoc, including examples.
| | |
| ------- | -------------------------------------------------------------------------------------------------------------------------------------- |
| Delta | insert, retain, remove, push, compose, transform, invert, diff, concat, slice, chop, clean, equals, length |
| Op | length |
