Skip to content
This repository was archived by the owner on Mar 6, 2018. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ JSON8 Patch passes the entire [json-patch-tests](https://github.com/json-patch/j
* [revert](#revert)
* [diff](#diff)
* [valid](#valid)
* [concat](#concat)
* [Operations](#operations)
* [add](#add)
* [remove](#remove)
Expand Down Expand Up @@ -137,6 +138,23 @@ ooPatch.valid([{op: "add", path: "/foo", value: "bar"}]) // true

[↑](#json8-patch)

## concat

Concats multiple patches into one.

```javascript
var patch1 = [{op: "add", value: "bar", path: "/foo"}]
var patch2 = [{op: "remove", path: "/foo"}]
var patch = ooPatch.concat(patch1, patch2)

// patch is
[
{op: "add", value: "bar", path: "/foo"},
{op: "remove", path: "/foo"}
]
```

[↑](#json8-patch)

## Operations

Expand Down
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ module.exports.has = require('./lib/has')
// Packing
module.exports.pack = require('./lib/pack')
module.exports.unpack = require('./lib/unpack')

// Utilities
module.exports.concat = require('./lib/concat')
9 changes: 9 additions & 0 deletions lib/concat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict'

/**
* concat (or merge) multiple patches into one
* @returns {Array}
*/
module.exports = function concat(/* patch0, patch1, ... */) {
return [].concat.apply([], arguments)
}
14 changes: 14 additions & 0 deletions test/concat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict'

import assert from 'assert'
import concat from '../lib/concat'

describe('concat', () => {
it('concats the patches into a bigger patch', () => {
const patch0 = [{}]
const patch1 = [{}]
const patch2 = [{}]
const patch = concat(patch0, patch1, patch2)
assert.deepEqual(patch, [{}, {}, {}])
})
})