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

Commit 2123c7c

Browse files
committed
rebase
1 parent d42ebdd commit 2123c7c

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

lib/rebase.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
'use strict'
2+
3+
var ooPointer = require('json8-pointer')
4+
var decode = ooPointer.decode
5+
6+
// because the pointer "/0" doesn't let differentiate between
7+
// {"0": value} and [value] we always use an object
8+
function createContext (op) {
9+
var context = undefined
10+
var path = decode(op.path)
11+
return {} // fix edge cases!!
12+
// console.log(path)
13+
}
14+
15+
function rebase(patch) {
16+
if (patch.length < 2) return patch
17+
18+
var ctx = createContext(patch[0])
19+
20+
for (var i = 0, l = patch.length; i < l; i++) {
21+
22+
rebase[patch[i].path] = [patch[i].op, patch[i].value]
23+
}
24+
}
25+
26+
var patch = [
27+
{op: "add", value: "bar", path: "/foo/machin"},
28+
{op: "remove", path: "/foo"}
29+
]
30+
31+
console.log(rebase(patch))
32+

0 commit comments

Comments
 (0)