quill-delta
Advanced tools
Comparing version 3.2.0 to 3.3.0
@@ -93,2 +93,11 @@ var diff = require('fast-diff'); | ||
Delta.prototype.partition = function (predicate) { | ||
var passed = [], failed = []; | ||
this.forEach(function(op) { | ||
var target = predicate(op) ? passed : failed; | ||
target.push(op); | ||
}); | ||
return [passed, failed]; | ||
}; | ||
Delta.prototype.reduce = function (predicate, initial) { | ||
@@ -95,0 +104,0 @@ return this.ops.reduce(predicate, initial); |
{ | ||
"name": "quill-delta", | ||
"version": "3.2.0", | ||
"version": "3.3.0", | ||
"description": "Format for representing rich text documents and changes.", | ||
@@ -5,0 +5,0 @@ "author": "Jason Chen <jhchen7@gmail.com>", |
@@ -81,2 +81,3 @@ # Delta [![Build Status](https://travis-ci.org/quilljs/delta.svg?branch=master)](http://travis-ci.org/quilljs/delta) [![Coverage Status](https://img.shields.io/coveralls/quilljs/delta.svg)](https://coveralls.io/r/quilljs/delta) | ||
- [`map`](#map) | ||
- [`partition`](#partition) | ||
- [`reduce`](#reduce) | ||
@@ -457,2 +458,35 @@ - [`slice`](#slice) | ||
### partition() | ||
Create an array op two arrays, the first with operations that pass the given function, the other that failed. | ||
#### Methods | ||
- `partition(predicate)` | ||
#### Parameters | ||
- `predicate` - Function to call, passing in the current operation, returning whether that operation passed | ||
#### Returns | ||
- `Array` - A new array of two Arrays, the first with passed operations, the other with failed operations | ||
#### Example | ||
```js | ||
var delta = new Delta().insert('Hello', { bold: true }) | ||
.insert({ image: 'https://octodex.github.com/images/labtocat.png' }) | ||
.insert('World!'); | ||
var results = delta.partition(function(op) { | ||
return typeof op.insert === 'string'; | ||
}); | ||
var passed = results[0]; // [{ insert: 'Hello', attributes: { bold: true }}, | ||
{ insert: 'World'}] | ||
var failed = results[1]; // [{ insert: { image: 'https://octodex.github.com/images/labtocat.png' }}] | ||
``` | ||
--- | ||
### reduce() | ||
@@ -459,0 +493,0 @@ |
@@ -116,2 +116,11 @@ var Delta = require('../../lib/delta'); | ||
}); | ||
it('partition()', function () { | ||
var arr = this.delta.partition(function (op) { | ||
return typeof op.insert === 'string'; | ||
}); | ||
var passed = arr[0], failed = arr[1]; | ||
expect(passed).toEqual([this.delta.ops[0], this.delta.ops[2]]); | ||
expect(failed).toEqual([this.delta.ops[1]]); | ||
}); | ||
}); | ||
@@ -118,0 +127,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
65409
1292
634