Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function test_DeltaDiff() {
const a = new Delta().insert('Hello');
const b = new Delta().insert('Hello!');
const diff = a.diff(b); // { ops: [{ retain: 5 }, { insert: '!' }] }
// a.compose(diff) == b
const diff2 = a.diff(b, 0); // { ops: [{ retain: 5 }, { insert: '!' }] }
// a.compose(diff) == b
}
function test_DeltaCompose() {
const a = new Delta().insert('abc');
const b = new Delta().retain(1).delete(1);
const composed = a.compose(b); // composed == new Delta().insert('ac');
}
function test_DeltaCompose() {
const a = new Delta().insert('abc');
const b = new Delta().retain(1).delete(1);
const composed = a.compose(b); // composed == new Delta().insert('ac');
}
function test_DeltatransformPosition() {
const delta = new Delta().retain(5).insert('a');
const n1: number = delta.transformPosition(4); // 4
const n2: number = delta.transformPosition(5); // 6
const n3: number = delta.transformPosition(5, true);
const n4: number = delta.transformPosition(5, false);
}
function test_DeltaTransform() {
const a = new Delta().insert('a');
const b = new Delta().insert('b').retain(5).insert('c');
const d1: DeltaStatic = a.transform(b, true); // new Delta().retain(1).insert('b').retain(5).insert('c');
const d2: DeltaStatic = a.transform(b, false); // new Delta().insert('b').retain(6).insert('c');
const n1: number = a.transform(5);
const n2: number = a.transform(5, true);
const n3: number = a.transform(5, false);
}
function test_DeltaForEach() {
const delta = new Delta();
delta.forEach((op: any) => console.log(op));
}
function test_DeltaChaining() {
const delta = new Delta()
.insert('Hello', { bold: true })
.insert('World')
.delete(5)
.retain(5)
.retain(5, { color: '#0c6' });
}
function test_setDeltaContents() {
const quillEditor = new Quill('#editor');
quillEditor.setContents(new Delta({ ops: [
{ insert: 'Hello ' },
{ insert: 'World!', attributes: { bold: true } },
{ insert: '\n' }
]}));
}
function test_DeltaFilter() {
const delta = new Delta().insert('Hello', { bold: true })
.insert({ image: 'https://octodex.github.com/images/labtocat.png' })
.insert('World!');
const text = delta
.filter((op: any) => typeof op.insert === 'string')
.map((op: any) => op.insert)
.join('');
}
createDeltaSegmentStateMachineHasLearnt(value: boolean, index: number, segment: Segment,
length: number = 1): DeltaStatic {
const format: FormatMachine = {};
if (segment.state.status != null) {
format.status = segment.state.status.toString();
}
format.machineHasLearnt = value.toString();
const formats: StringMap = { state: format };
return new Delta().retain(index).retain(length, formats);
}