Skip to content
This repository was archived by the owner on Mar 6, 2018. It is now read-only.

Commit b5e20a1

Browse files
committed
Merge pull request #16 from JSON8/concat
concat method
2 parents 8facc30 + 8a346c7 commit b5e20a1

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ JSON8 Patch passes the entire [json-patch-tests](https://github.com/json-patch/j
1616
* [revert](#revert)
1717
* [diff](#diff)
1818
* [valid](#valid)
19+
* [concat](#concat)
1920
* [Operations](#operations)
2021
* [add](#add)
2122
* [remove](#remove)
@@ -137,6 +138,23 @@ ooPatch.valid([{op: "add", path: "/foo", value: "bar"}]) // true
137138
138139
[↑](#json8-patch)
139140
141+
## concat
142+
143+
Concats multiple patches into one.
144+
145+
```javascript
146+
var patch1 = [{op: "add", value: "bar", path: "/foo"}]
147+
var patch2 = [{op: "remove", path: "/foo"}]
148+
var patch = ooPatch.concat(patch1, patch2)
149+
150+
// patch is
151+
[
152+
{op: "add", value: "bar", path: "/foo"},
153+
{op: "remove", path: "/foo"}
154+
]
155+
```
156+
157+
[↑](#json8-patch)
140158
141159
## Operations
142160

index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,6 @@ module.exports.has = require('./lib/has')
2323
// Packing
2424
module.exports.pack = require('./lib/pack')
2525
module.exports.unpack = require('./lib/unpack')
26+
27+
// Utilities
28+
module.exports.concat = require('./lib/concat')

lib/concat.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'use strict'
2+
3+
/**
4+
* concat (or merge) multiple patches into one
5+
* @returns {Array}
6+
*/
7+
module.exports = function concat(/* patch0, patch1, ... */) {
8+
return [].concat.apply([], arguments)
9+
}

test/concat.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict'
2+
3+
import assert from 'assert'
4+
import concat from '../lib/concat'
5+
6+
describe('concat', () => {
7+
it('concats the patches into a bigger patch', () => {
8+
const patch0 = [{}]
9+
const patch1 = [{}]
10+
const patch2 = [{}]
11+
const patch = concat(patch0, patch1, patch2)
12+
assert.deepEqual(patch, [{}, {}, {}])
13+
})
14+
})

0 commit comments

Comments
 (0)