Gathering detailed insights and metrics for vue-jsondiffpatch
Gathering detailed insights and metrics for vue-jsondiffpatch
npm install vue-jsondiffpatch
Typescript
Module System
Min. Node Version
Node Version
NPM Version
76.7
Supply Chain
99.2
Quality
74.9
Maintenance
100
Vulnerability
99.6
License
TypeScript (95.28%)
CSS (3.53%)
JavaScript (1.19%)
Total Downloads
44,307
Last Day
134
Last Week
476
Last Month
1,481
Last Year
19,753
4,912 Stars
372 Commits
474 Forks
89 Watching
2 Branches
38 Contributors
Minified
Minified + Gzipped
Latest Version
0.3.11-1
Package Id
vue-jsondiffpatch@0.3.11-1
Unpacked Size
3.07 MB
Size
556.08 kB
File Count
16
NPM Version
6.4.1
Node Version
8.11.2
Cumulative downloads
Total Downloads
Last day
50.6%
134
Compared to previous day
Last week
61.9%
476
Compared to previous week
Last month
-0.5%
1,481
Compared to previous month
Last year
128.8%
19,753
Compared to previous year
2
32
Diff & patch JavaScript objects
/dist
folder with bundles for UMD, commonjs, or ES modules)objectHash
function (this is how objects are matched, otherwise a dumb match by position is used). For more details, check Array diff documentation./node_modules/.bin/jsondiffpatch left.json right.json
jsondiffpatch.clone(obj)
(deep clone)And you can test your current browser visiting the test page.
1 // sample data 2 var country = { 3 name: "Argentina", 4 capital: "Buenos Aires", 5 independence: new Date(1816, 6, 9), 6 unasur: true 7 }; 8 9 // clone country, using dateReviver for Date objects 10 var country2 = JSON.parse(JSON.stringify(country), jsondiffpatch.dateReviver); 11 12 // make some changes 13 country2.name = "Republica Argentina"; 14 country2.population = 41324992; 15 delete country2.capital; 16 17 var delta = jsondiffpatch.diff(country, country2); 18 19 assertSame(delta, { 20 "name":["Argentina","Republica Argentina"], // old value, new value 21 "population":["41324992"], // new value 22 "capital":["Buenos Aires", 0, 0] // deleted 23 }); 24 25 // patch original 26 jsondiffpatch.patch(country, delta); 27 28 // reverse diff 29 var reverseDelta = jsondiffpatch.reverse(delta); 30 // also country2 can be return to original value with: jsondiffpatch.unpatch(country2, delta); 31 32 var delta2 = jsondiffpatch.diff(country, country2); 33 assert(delta2 === undefined) 34 // undefined => no difference
Array diffing:
1 // sample data 2 var country = { 3 name: "Argentina", 4 cities: [ 5 { 6 name: 'Buenos Aires', 7 population: 13028000, 8 }, 9 { 10 name: 'Cordoba', 11 population: 1430023, 12 }, 13 { 14 name: 'Rosario', 15 population: 1136286, 16 }, 17 { 18 name: 'Mendoza', 19 population: 901126, 20 }, 21 { 22 name: 'San Miguel de Tucuman', 23 population: 800000, 24 } 25 ] 26 }; 27 28 // clone country 29 var country2 = JSON.parse(JSON.stringify(country)); 30 31 // delete Cordoba 32 country.cities.splice(1, 1); 33 34 // add La Plata 35 country.cities.splice(4, 0, { 36 name: 'La Plata' 37 }); 38 39 // modify Rosario, and move it 40 var rosario = country.cities.splice(1, 1)[0]; 41 rosario.population += 1234; 42 country.cities.push(rosario); 43 44 // create a configured instance, match objects by name 45 var diffpatcher = jsondiffpatch.create({ 46 objectHash: function(obj) { 47 return obj.name; 48 } 49 }); 50 51 var delta = diffpatcher.diff(country, country2); 52 53 assertSame(delta, { 54 "cities": { 55 "_t": "a", // indicates this node is an array (not an object) 56 "1": [ 57 // inserted at index 1 58 { 59 "name": "Cordoba", 60 "population": 1430023 61 }] 62 , 63 "2": { 64 // population modified at index 2 (Rosario) 65 "population": [ 66 1137520, 67 1136286 68 ] 69 }, 70 "_3": [ 71 // removed from index 3 72 { 73 "name": "La Plata" 74 }, 0, 0], 75 "_4": [ 76 // move from index 4 to index 2 77 '', 2, 3] 78 } 79 });
For more example cases (nested objects or arrays, long text diffs) check test/examples/
If you want to understand deltas, see delta format documentation
This works for node, or in browsers if you already do bundling on your app
1npm install jsondiffpatch
1var jsondiffpatch = require('jsondiffpatch').create(options);
In a browser, you could load directly a bundle in /dist
, eg. /dist/jsondiffpatch.umd.js
.
1var jsondiffpatch = require('jsondiffpatch').create({ 2 // used to match objects when diffing arrays, by default only === operator is used 3 objectHash: function(obj) { 4 // this function is used only to when objects are not equal by ref 5 return obj._id || obj.id; 6 }, 7 arrays: { 8 // default true, detect items moved inside the array (otherwise they will be registered as remove+add) 9 detectMove: true, 10 // default false, the value of items moved is not included in deltas 11 includeValueOnMove: false 12 }, 13 textDiff: { 14 // default 60, minimum string length (left and right sides) to use text diff algorythm: google-diff-match-patch 15 minLength: 60 16 }, 17 propertyFilter: function(name, context) { 18 /* 19 this optional function can be specified to ignore object properties (eg. volatile data) 20 name: property name, present in either context.left or context.right objects 21 context: the diff context (has context.left and context.right objects) 22 */ 23 return name.slice(0, 1) !== '$'; 24 }, 25 cloneDiffValues: false /* default false. if true, values in the obtained delta will be cloned 26 (using jsondiffpatch.clone by default), to ensure delta keeps no references to left or right objects. this becomes useful if you're diffing and patching the same objects multiple times without serializing deltas. 27 instead of true, a function can be specified here to provide a custom clone(value) 28 */ 29});
1<!DOCTYPE html> 2<html> 3 <head> 4 <script type='text/javascript' src="https://cdn.jsdelivr.net/npm/jsondiffpatch/dist/jsondiffpatch.umd.min.js"></script> 5 <link rel="stylesheet" href="./style.css" type="text/css" /> 6 <link rel="stylesheet" href="../formatters-styles/html.css" type="text/css" /> 7 <link rel="stylesheet" href="../formatters-styles/annotated.css" type="text/css" /> 8 </head> 9 <body> 10 <div id="visual"></div> 11 <hr/> 12 <div id="annotated"></div> 13 <script> 14 var left = { a: 3, b: 4 }; 15 var right = { a: 5, c: 9 }; 16 var delta = jsondiffpatch.diff(left, right); 17 18 // beautiful html diff 19 document.getElementById('visual').innerHTML = jsondiffpatch.formatters.html.format(delta, left); 20 21 // self-explained json 22 document.getElementById('annotated').innerHTML = jsondiffpatch.formatters.annotated.format(delta, left); 23 </script> 24 </body> 25</html>
To see formatters in action check the Live Demo.
For more details check Formatters documentation
1# diff two json files, colored output (using chalk lib) 2./node_modules/.bin/jsondiffpatch ./left.json ./right.json 3 4# or install globally 5npm install -g jsondiffpatch 6 7jsondiffpatch ./demo/left.json ./demo/right.json
diff()
, patch()
and reverse()
functions are implemented using Pipes & Filters pattern, making it extremely customizable by adding or replacing filters on a pipe.
Check Plugins documentation for details.
No vulnerabilities found.
Reason
no vulnerabilities detected
Reason
no dangerous workflow patterns detected
Reason
tokens are read-only in GitHub workflows
Reason
license file detected
Details
Reason
all dependencies are pinned
Details
Reason
no binaries found in the repo
Reason
GitHub code reviews found for 23 commits out of the last 30 -- score normalized to 7
Details
Reason
0 commit(s) out of 30 and 0 issue activity out of 30 found in the last 90 days -- score normalized to 0
Reason
no badge detected
Reason
branch protection not enabled on development/release branches
Details
Reason
security policy file not detected
Reason
no update tool detected
Details
Reason
project is not fuzzed
Score
Last Scanned on 2022-08-15
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More