X Tutup
The Wayback Machine - https://web.archive.org/web/20210106152237/https://github.com/henoc/diffsonjs
Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

diffsonjs

travis_ci codecov npm

A javascript JSON diff and patch implementation of the RFC-6902. This library refers to diffson.

Install

npm install diffsonjs

Usage

var diffsonjs = require('diffsonjs');

var left = {a: 1, b: true};
var right = {a: 2};

var delta = diffsonjs.diff(left, right);
console.log(delta);
// [
//   { op: 'replace', path: '/a', value: 2 },
//   { op: 'remove', path: '/b' }
// ]

var result = diffsonjs.patch(left, delta);
console.log(result);
// {a: 2}

API

diff(json1, json2, options?)

Compute the diff between two json objects.

diff options

interface DiffOptions {
    omitArrayDiffs?: boolean // default false, different arrays are represented by repleacement.
    remember?: boolean // default false, set the previous value as `oldValue` property for replacement or movement.
    equals?: (left: unknown, right: unknown) => boolean // if it exists, use it instead of the normal json comparison function.
    hashCode?: (value: any) => number // if it exists, it is used to speed up comparison of arrays.
}

patch(json, delta, options?)

Apply a patch to json and return the result.

patch options

interface PatchOptions {
    equals?: (left: unknown, right: unknown) => boolean // if it exists, use it for tests.
}

About

A json diff/patch implementation of the RFC-6902

Topics

Resources

Packages

No packages published
You can’t perform that action at this time.
X Tutup