-
Notifications
You must be signed in to change notification settings - Fork 478
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convert from RFC 6902 to jsondiffpatch #381
Comments
I also had this question today. Seeing this issue, I decided to take a crack at it. At first I thought it would look something like this: import type { AddedDelta, ModifiedDelta, DeletedDelta, MovedDelta, Delta } from 'jsondiffpatch'
import type { Op } from "jsondiffpatch/formatters/jsonpatch"
export function parse(jsonpatch: Op[]): Delta[] { // wrong
const deltas: Delta[] = [] // wrong
for (const op of jsonpatch) {
switch (op.op) {
case 'add':
deltas.push([op.value] as AddedDelta)
break
case 'remove':
deltas.push([undefined, 0, 0] as DeletedDelta)
break
case 'replace':
deltas.push([undefined, op.value] as ModifiedDelta)
break
case 'move':
deltas.push([op.from, parseInt(op.path.match(/\d+$/)[0]), 3] as MovedDelta)
break
}
}
return deltas
} ...but then I realized that it shouldn't be returning an array of Those are my thoughts on this, from a quick exploration. I'd be happy to know if I'm wrong :) |
Hi,
I see that there is a custom formatter designed to convert from the jsondiffpatch format to RFC 6902. Is there a way to go in the reverse direction?
I've got RFC 6902 patches coming from a backend service and would like to use the HTML formatter provided by this library, but it only takes the jsondiffpatch specific diff format.
The text was updated successfully, but these errors were encountered: