rich-text
Advanced tools
Comparing version 2.0.0 to 2.1.0
@@ -0,5 +1,13 @@ | ||
## v2.1.0 | ||
#### Features | ||
- Add `concat()` method for document Deltas | ||
## v2.0.0 | ||
Changes: | ||
#### Breaking Changes | ||
- `compose()` returns a new Delta instead of self-modifying | ||
#### Features | ||
- Support embed being any non-string type |
@@ -148,2 +148,11 @@ var diff = require('fast-diff'); | ||
Delta.prototype.concat = function (other) { | ||
var delta = this.slice(); | ||
if (other.ops.length > 0) { | ||
delta.push(other.ops[0]); | ||
delta.ops = delta.ops.concat(other.ops.slice(1)); | ||
} | ||
return delta; | ||
}; | ||
Delta.prototype.diff = function (other) { | ||
@@ -150,0 +159,0 @@ var delta = new Delta(); |
{ | ||
"name": "rich-text", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Format for representing rich text documents and changes.", | ||
@@ -5,0 +5,0 @@ "author": "Jason Chen <jhchen7@gmail.com>", |
@@ -372,2 +372,36 @@ # Rich Text [![Build Status](https://travis-ci.org/ottypes/rich-text.svg?branch=master)](http://travis-ci.org/ottypes/rich-text) [![Coverage Status](https://img.shields.io/coveralls/ottypes/rich-text.svg)](https://coveralls.io/r/ottypes/rich-text) | ||
### concat() | ||
Returns a new Delta representing the concatenation of this and another document Delta's operations. | ||
#### Methods | ||
- `concat(other)` | ||
#### Parameters | ||
- `other` - Document Delta to concatenate | ||
#### Returns | ||
- `Delta` - Concatenated document Delta | ||
#### Example | ||
```js | ||
var a = new Delta().insert('Hello'); | ||
var b = new Delta().insert('!', { bold: true }); | ||
// { | ||
// ops: [ | ||
// { insert: 'Hello' }, | ||
// { insert: '!', attributes: { bold: true } } | ||
// ] | ||
// } | ||
var concat = a.concat(b); | ||
``` | ||
--- | ||
### diff() | ||
@@ -374,0 +408,0 @@ |
@@ -6,2 +6,25 @@ var Delta = require('../../lib/delta'); | ||
describe('helpers', function () { | ||
describe('concat()', function () { | ||
it('empty delta', function () { | ||
var delta = new Delta().insert('Test'); | ||
var concat = new Delta(); | ||
var expected = new Delta().insert('Test'); | ||
expect(delta.concat(concat)).to.deep.equal(expected); | ||
}); | ||
it('unmergeable', function () { | ||
var delta = new Delta().insert('Test'); | ||
var concat = new Delta().insert('!', { bold: true }); | ||
var expected = new Delta().insert('Test').insert('!', { bold: true }); | ||
expect(delta.concat(concat)).to.deep.equal(expected); | ||
}); | ||
it('mergeable', function () { | ||
var delta = new Delta().insert('Test', { bold: true }); | ||
var concat = new Delta().insert('!', { bold: true }).insert('\n'); | ||
var expected = new Delta().insert('Test!', { bold: true }).insert('\n'); | ||
expect(delta.concat(concat)).to.deep.equal(expected); | ||
}); | ||
}); | ||
describe('chop()', function () { | ||
@@ -8,0 +31,0 @@ it('retain', function () { |
68588
1560
432