json-difference
Advanced tools
Comparing version 1.0.2 to 1.0.4
@@ -8,3 +8,3 @@ var JsonDiffer = /** @class */ (function () { | ||
removed: [], | ||
edited: [], | ||
edited: [] | ||
}; | ||
@@ -25,4 +25,4 @@ var struct1_paths = this.getStructPaths(struct1); | ||
for (var key in struct) { | ||
var path = currentpath !== '' ? currentpath + "/" + key : key; | ||
if (typeof struct[key] == "object") { | ||
var path = currentpath !== '' ? currentpath + '/' + key : key; | ||
if (typeof struct[key] == 'object') { | ||
this.getStructPaths(struct[key], paths, path); | ||
@@ -34,6 +34,5 @@ } | ||
} | ||
; | ||
return paths; | ||
}; | ||
// Diference by key | ||
// Difference by key | ||
JsonDiffer.prototype.getPathsDiff = function (struct1_paths, struct2_paths) { | ||
@@ -48,3 +47,3 @@ var diff = {}; | ||
}; | ||
// Diference by value | ||
// Difference by value | ||
JsonDiffer.prototype.getEditedPaths = function (struct1_paths, struct2_paths) { | ||
@@ -56,7 +55,7 @@ var _a; | ||
if (struct2_paths.hasOwnProperty(key)) { | ||
if (struct1_paths[key] != struct2_paths[key]) { | ||
if (struct1_paths[key] !== struct2_paths[key]) { | ||
diff = (_a = {}, | ||
_a[key] = { | ||
newvalue: struct1_paths[key], | ||
oldvalue: struct2_paths[key] | ||
oldvalue: struct1_paths[key], | ||
newvalue: struct2_paths[key] | ||
}, | ||
@@ -63,0 +62,0 @@ _a); |
export declare class JsonDiffer { | ||
constructor(); | ||
getDiff(struct1: any, struct2: any): { | ||
@@ -4,0 +3,0 @@ new: never[]; |
@@ -10,3 +10,3 @@ "use strict"; | ||
removed: [], | ||
edited: [], | ||
edited: [] | ||
}; | ||
@@ -27,4 +27,4 @@ var struct1_paths = this.getStructPaths(struct1); | ||
for (var key in struct) { | ||
var path = currentpath !== '' ? currentpath + "/" + key : key; | ||
if (typeof struct[key] == "object") { | ||
var path = currentpath !== '' ? currentpath + '/' + key : key; | ||
if (typeof struct[key] == 'object') { | ||
this.getStructPaths(struct[key], paths, path); | ||
@@ -36,6 +36,5 @@ } | ||
} | ||
; | ||
return paths; | ||
}; | ||
// Diference by key | ||
// Difference by key | ||
JsonDiffer.prototype.getPathsDiff = function (struct1_paths, struct2_paths) { | ||
@@ -50,3 +49,3 @@ var diff = {}; | ||
}; | ||
// Diference by value | ||
// Difference by value | ||
JsonDiffer.prototype.getEditedPaths = function (struct1_paths, struct2_paths) { | ||
@@ -58,7 +57,7 @@ var _a; | ||
if (struct2_paths.hasOwnProperty(key)) { | ||
if (struct1_paths[key] != struct2_paths[key]) { | ||
if (struct1_paths[key] !== struct2_paths[key]) { | ||
diff = (_a = {}, | ||
_a[key] = { | ||
newvalue: struct1_paths[key], | ||
oldvalue: struct2_paths[key] | ||
oldvalue: struct1_paths[key], | ||
newvalue: struct2_paths[key] | ||
}, | ||
@@ -65,0 +64,0 @@ _a); |
{ | ||
"name": "json-difference", | ||
"version": "1.0.2", | ||
"version": "1.0.4", | ||
"description": "json diff lib", | ||
@@ -12,6 +12,9 @@ "main": "dist/jsondiffer.js", | ||
"scripts": { | ||
"lint": "tslint --project tsconfig.json", | ||
"test": "jest --config jestconfig.json --coverage", | ||
"example": "tsc examples/index.ts && node examples/index.js", | ||
"build": "tsc && tsc -p tsconfig.browser.json", | ||
"format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"", | ||
"prepare": "npm run build" | ||
"prepare": "npm run build", | ||
"prepublishOnly": "npm test" | ||
}, | ||
@@ -29,4 +32,9 @@ "repository": { | ||
"devDependencies": { | ||
"@types/jest": "^23.3.2", | ||
"jest": "^23.6.0", | ||
"ts-jest": "^23.10.1", | ||
"tslint": "^5.20.1", | ||
"tslint-config-prettier": "^1.18.0", | ||
"typescript": "^3.0.3" | ||
} | ||
} | ||
} |
# jsondiffer | ||
[![npm version](http://img.shields.io/npm/v/json-difference.svg?style=flat)](https://www.npmjs.com/package/json-difference "View this project on npm") | ||
[![npm version](http://img.shields.io/npm/v/json-difference.svg?style=flat)](https://www.npmjs.com/package/json-difference 'View this project on npm') | ||
[![Build Status](https://travis-ci.org/lukascivil/jsondiffer.svg?branch=master)](https://travis-ci.org/lukascivil/jsondiffer) | ||
[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active) | ||
[![codecov](https://codecov.io/gh/lukascivil/jsondiffer/branch/master/graph/badge.svg)](https://codecov.io/gh/lukascivil/jsondiffer) | ||
[![MIT License](https://img.shields.io/npm/l/deep-object-diff.svg?style=flat)](https://github.com/lukascivil/jsondiffer/blob/master/LICENSE) | ||
## Example | ||
[master](http://jsondifference.lukascivil.com.br) | ||
@@ -13,4 +18,4 @@ | ||
```html | ||
<script type="module"> | ||
import {JsonDiffer} from "https://rawgit.com/lukascivil/jsondiffer/master/dist.browser/jsondiffer.js"; | ||
<script type="module"> | ||
import { JsonDiffer } from 'https://rawgit.com/lukascivil/jsondiffer/master/dist.browser/jsondiffer.js'; | ||
</script> | ||
@@ -30,3 +35,3 @@ ``` | ||
```ts | ||
import {JsonDiffer} from 'json-difference'; | ||
import { JsonDiffer } from 'json-difference'; | ||
@@ -39,26 +44,30 @@ const coffee = { color: { color1: 'black', color2: 'brown' }, special: true }; | ||
console.log(diff) | ||
console.log(diff); | ||
``` | ||
Output: | ||
```json | ||
{ | ||
"new": { | ||
"special2": false | ||
"new": { | ||
"special2": false | ||
}, | ||
"removed": { | ||
"special": true | ||
}, | ||
"edited": [ | ||
{ | ||
"color/color1": { | ||
"oldvalue": "black", | ||
"newvalue": "red" | ||
} | ||
}, | ||
"removed": { | ||
"special": true | ||
}, | ||
"edited": [{ | ||
"color/color1": { | ||
"newvalue": "black", | ||
"oldvalue": "red" | ||
} | ||
}, { | ||
"color/color2": { | ||
"newvalue": "brown", | ||
"oldvalue": "blue" | ||
} | ||
}] | ||
{ | ||
"color/color2": { | ||
"oldvalue": "brown", | ||
"newvalue": "blue" | ||
} | ||
} | ||
] | ||
} | ||
``` |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
8999
6
71
0
6
144