New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

json-difference

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-difference - npm Package Compare versions

Comparing version 1.1.6 to 1.1.7

dist/core/get-edited-paths.d.ts

4

dist/core/get-diff.js

@@ -5,3 +5,3 @@ "use strict";

// Packages
var get_edited_patch_1 = require("./get-edited-patch");
var get_edited_paths_1 = require("./get-edited-paths");
var get_paths_diff_1 = require("./get-paths-diff");

@@ -22,5 +22,5 @@ var get_struct_paths_1 = require("./get-struct-paths");

// a->b
delta.edited = (0, get_edited_patch_1.getEditedPaths)(oldStructPaths, newStructPaths);
delta.edited = (0, get_edited_paths_1.getEditedPaths)(oldStructPaths, newStructPaths);
return delta;
};
exports.getDiff = getDiff;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var _1 = require(".");
test('Should return the difference between two basic structures', function () {
var struct1 = { 1: { 2: 7, 3: { 4: 6 } } };
var struct2 = { 1: { 3: { 4: 5 } } };
var expectedResult = { edited: [{ '1/3/4': { newValue: 5, oldValue: 6 } }], new: {}, removed: { '1/2': 7 } };
var result = (0, _1.getDiff)(struct1, struct2);
expect(result).toEqual(expectedResult);
describe('GetDiff function', function () {
test('Should return the difference between two basic structures', function () {
var struct1 = { 1: { 2: 7, 3: { 4: 6 } } };
var struct2 = { 1: { 3: { 4: 5 } } };
var expectedResult = { edited: [{ '1/3/4': { newValue: 5, oldValue: 6 } }], new: {}, removed: { '1/2': 7 } };
var result = (0, _1.getDiff)(struct1, struct2);
expect(result).toEqual(expectedResult);
});
test('Should return the difference between two structures containing Array property', function () {
var struct1 = { a: 1, b: [{ c1: 1 }, { c2: 2 }] };
var struct2 = { a: 11, b: [{ c1: 1 }, { c2: 22 }] };
var expectedResult = {
edited: [{ a: { newValue: 11, oldValue: 1 } }, { 'b/1/c2': { newValue: 22, oldValue: 2 } }],
new: {},
removed: {}
};
var result = (0, _1.getDiff)(struct1, struct2);
expect(result).toEqual(expectedResult);
});
test('Should return the difference between two structures containing deep Array nodes', function () {
var struct1 = { a: 1, b: [{ c1: [{ c3: { c5: [1, 2, { c6: 3 }] } }, { c4: 6 }] }, { c2: 2 }] };
var struct2 = { a: 11, b: [{ c1: [{ c3: { c5: [1, 2, { c6: 4 }] } }, { c4: 6 }] }, { c2: 2 }] };
var expectedResult = {
edited: [{ a: { newValue: 11, oldValue: 1 } }, { 'b/0/c1/0/c3/c5/2/c6': { newValue: 4, oldValue: 3 } }],
new: {},
removed: {}
};
var result = (0, _1.getDiff)(struct1, struct2);
expect(result).toEqual(expectedResult);
});
test('Should return the difference between two structures containing different node types', function () {
var struct1 = { a: 1, b: { c1: 2 }, c: 3 };
var struct2 = { a: '1', b: 2, c: true };
var expectedResult = {
edited: [{ a: { newValue: '1', oldValue: 1 } }, { c: { newValue: true, oldValue: 3 } }],
new: { b: 2 },
removed: { 'b/c1': 2 }
};
var result = (0, _1.getDiff)(struct1, struct2);
expect(result).toEqual(expectedResult);
});
});
test('Should return the difference between two structures containing Array Property', function () {
var struct1 = { a: 1, b: [{ c1: 1 }, { c2: 2 }] };
var struct2 = { a: 11, b: [{ c1: 1 }, { c2: 22 }] };
var expectedResult = {
edited: [{ a: { newValue: 11, oldValue: 1 } }, { 'b/1/c2': { newValue: 22, oldValue: 2 } }],
new: {},
removed: {}
};
var result = (0, _1.getDiff)(struct1, struct2);
expect(result).toEqual(expectedResult);
});
test('Should return the difference between two structures containing deep Array nodes', function () {
var struct1 = { a: 1, b: [{ c1: [{ c3: { c5: [1, 2, { c6: 3 }] } }, { c4: 6 }] }, { c2: 2 }] };
var struct2 = { a: 11, b: [{ c1: [{ c3: { c5: [1, 2, { c6: 4 }] } }, { c4: 6 }] }, { c2: 2 }] };
var expectedResult = {
edited: [{ a: { newValue: 11, oldValue: 1 } }, { 'b/0/c1/0/c3/c5/2/c6': { newValue: 4, oldValue: 3 } }],
new: {},
removed: {}
};
var result = (0, _1.getDiff)(struct1, struct2);
expect(result).toEqual(expectedResult);
});
test('Should return the difference between two structures containing different node types', function () {
var struct1 = { a: 1, b: { c1: 2 }, c: 3 };
var struct2 = { a: '1', b: 2, c: true };
var expectedResult = {
edited: [{ a: { newValue: '1', oldValue: 1 } }, { c: { newValue: true, oldValue: 3 } }],
new: { b: 2 },
removed: { 'b/c1': 2 }
};
var result = (0, _1.getDiff)(struct1, struct2);
expect(result).toEqual(expectedResult);
});
export * from './get-diff';
export * from './get-paths-diff';
export * from './get-struct-paths';
export * from './get-edited-patch';
export * from './get-edited-paths';

@@ -16,2 +16,2 @@ "use strict";

__exportStar(require("./get-struct-paths"), exports);
__exportStar(require("./get-edited-patch"), exports);
__exportStar(require("./get-edited-paths"), exports);
{
"name": "json-difference",
"version": "1.1.6",
"version": "1.1.7",
"description": "json diff lib",

@@ -20,3 +20,3 @@ "license": "MIT",

"test:local": "jest --watchAll --config jestconfig.json",
"example": "echo Use {simple} or {stress} as example param && cd ./examples && npm run",
"example": "echo Use {simple} or {stress} as example param && cd ./examples && yarn",
"build": "tsc && vite build",

@@ -23,0 +23,0 @@ "format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"",

@@ -11,10 +11,18 @@ # jsondiffer

Computes the difference between two objects and returns an intuitive result. No matter how big your JSON is, the diff will be returned pretty fast.
The question you should ask is: Given my old structure what was changed, removed or added to the new structure?
## Example
[master](http://jsondifference.lukascivil.com.br)
[Last release](http://jsondifference.lukascivil.com.br)
## Installation
`npm install json-difference --save`
```sh
yarn add json-difference
```
Or
```html

@@ -30,3 +38,3 @@ <script type="module">

`npm run example {simple, stress}`
`yarn example {simple, stress}`

@@ -39,3 +47,3 @@ ## Usage

Returns the structural diff between `oldStruct` and `newStruct`.
Returns the structural difference between `oldStruct` and `newStruct`.

@@ -45,3 +53,3 @@ Simple usage:

```ts
import { JsonDiffer } from 'json-difference';
import { getDiff } from 'json-difference';

@@ -51,4 +59,3 @@ const coffee = { color: { color1: 'black', color2: 'brown' }, special: true };

const jsondifference = new JsonDiffer();
let diff = jsondifference.getDiff(coffee, oil);
let diff = getDiff(coffee, oil);

@@ -71,4 +78,4 @@ console.log(diff);

"color/color1": {
"oldvalue": "black",
"newvalue": "red"
"oldValue": "black",
"newValue": "red"
}

@@ -78,4 +85,4 @@ },

"color/color2": {
"oldvalue": "brown",
"newvalue": "blue"
"oldValue": "brown",
"newValue": "blue"
}

@@ -82,0 +89,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc