-
Notifications
You must be signed in to change notification settings - Fork 208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[just-diff] keep the old value in the diff #520
Labels
Comments
eviltik
pushed a commit
to eviltik/just
that referenced
this issue
Dec 5, 2022
I think it is a good proposal but PR needs work (see PR for comments) |
I also had the same problem and created a patch on my own. I am not too sure whether there's any interest, but this is it: diff --git a/node_modules/just-diff/index.cjs b/node_modules/just-diff/index.cjs
index b74099d..ab24a56 100644
--- a/node_modules/just-diff/index.cjs
+++ b/node_modules/just-diff/index.cjs
@@ -96,6 +96,7 @@ function diff(obj1, obj2, pathConverter) {
diffs.remove.push({
op: 'remove',
path: pathConverter(path),
+ value: obj1[key]
});
}
}
@@ -118,6 +119,7 @@ function diff(obj1, obj2, pathConverter) {
diffs.remove.push({
op: 'remove',
path: pathConverter(path),
+ value: obj2[key]
});
}
@@ -168,12 +170,12 @@ function diff(obj1, obj2, pathConverter) {
if(Object(obj1AtKey) !== obj1AtKey ||
Object(obj2AtKey) !== obj2AtKey || differentTypes(obj1AtKey, obj2AtKey)
) {
- pushReplace(path, diffs, obj2AtKey);
+ pushReplace(path, diffs, obj2AtKey, obj1AtKey);
} else {
if(!Object.keys(obj1AtKey).length &&
!Object.keys(obj2AtKey).length &&
String(obj1AtKey) != String(obj2AtKey)) {
- pushReplace(path, diffs, obj2AtKey);
+ pushReplace(path, diffs, obj2AtKey, obj1AtKey);
} else {
getDiff({
obj1: obj1[key],
@@ -186,11 +188,12 @@ function diff(obj1, obj2, pathConverter) {
}
}
- function pushReplace(path, diffs, newValue) {
+ function pushReplace(path, diffs, newValue, oldValue) {
diffs.replace.push({
op: 'replace',
path: pathConverter(path),
value: newValue,
+ oldValue
});
}
}
diff --git a/node_modules/just-diff/index.mjs b/node_modules/just-diff/index.mjs
index 4a84787..36eac99 100644
--- a/node_modules/just-diff/index.mjs
+++ b/node_modules/just-diff/index.mjs
@@ -91,6 +91,7 @@ function diff(obj1, obj2, pathConverter) {
diffs.remove.push({
op: 'remove',
path: pathConverter(path),
+ value: obj1[key]
});
}
}
@@ -113,6 +114,7 @@ function diff(obj1, obj2, pathConverter) {
diffs.remove.push({
op: 'remove',
path: pathConverter(path),
+ value: obj2[key]
});
}
@@ -163,7 +165,7 @@ function diff(obj1, obj2, pathConverter) {
if(Object(obj1AtKey) !== obj1AtKey ||
Object(obj2AtKey) !== obj2AtKey || differentTypes(obj1AtKey, obj2AtKey)
) {
- pushReplace(path, diffs, obj2AtKey);
+ pushReplace(path, diffs, obj2AtKey, obj1AtKey);
} else {
if(!Object.keys(obj1AtKey).length &&
!Object.keys(obj2AtKey).length &&
@@ -181,11 +183,12 @@ function diff(obj1, obj2, pathConverter) {
}
}
- function pushReplace(path, diffs, newValue) {
+ function pushReplace(path, diffs, newValue, oldValue) {
diffs.replace.push({
op: 'replace',
path: pathConverter(path),
value: newValue,
+ oldValue
});
}
}
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi guys, thank you for this great libs. I'm using it to compare diff between CVE entries (NVD api v2). Works great.
Request feature : it should be great to add attribute "oldValue" here, with the previous values. Currently we got only the new value.
just/packages/collection-diff/index.js
Line 146 in 3c9d3fb
The text was updated successfully, but these errors were encountered: