-
Notifications
You must be signed in to change notification settings - Fork 526
Closed
Description
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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels