I'm using jsdiff to show a diff if two objects are not equal.
const { diffJson } = require('diff');
const isEqual = require('lodash.isequal');
check({ x: 1, y: undefined }, { x: 1 });
function check(expected, actual) {
if (!isEqual(expected, actual)) { //=> false
console.log(diffJson(expected, actual)); //=> [ { value: '{\n "x": 1\n}', count: 3 } ]
}
}
Now it's ignoring undefined value due to default JSON.stringify behaviour.
I propose to add an option to diffJson method to show changes. The simplest way I found is to add a custom replacer function (https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify) in JSON.stringify (see ewnd9@c6daea7)
I would love to make a PR if the change is welcomed
I'm using
jsdiffto show a diff if two objects are not equal.Now it's ignoring
undefinedvalue due to defaultJSON.stringifybehaviour.I propose to add an option to
diffJsonmethod to show changes. The simplest way I found is to add a customreplacerfunction (https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify) inJSON.stringify(see ewnd9@c6daea7)I would love to make a PR if the change is welcomed