-
Notifications
You must be signed in to change notification settings - Fork 516
Closed as not planned
Labels
Description
I've tried the solution here but doesn't seem to work #249 (comment)
import { createPatch } from 'diff';
const compare = JSON.stringify({ test: '123' }, null, 2);
const to = JSON.stringify({ test: '123' }, null, 2);
const test = createPatch('Compare', compare, to, undefined, undefined, { context: Number.MAX_SAFE_INTEGER });
Will result in
Index: Compare
===================================================================
--- Compare
+++ Compare
My use case is I'm trying to feed the unified diff into https://github.com/rtfpessoa/diff2html and display the file content even if there are no changes at all, diff2html will render nothing as it's based on the diff itself which is empty.
If I simply add a space to the end of the json string so there is a change, it shows the content, but this obviously highlights the space diff.
const compare = JSON.stringify({ test: '123' }, null, 2);
let to = JSON.stringify({ test: '123' }, null, 2);
to += ' ';
const test = createPatch('Compare', compare, to, undefined, undefined, { context: Number.MAX_SAFE_INTEGER });
Index: Compare
===================================================================
--- Compare
+++ Compare
@@ -1,3 +1,3 @@
{
"test": "123"
-}
\ No newline at end of file
+}
\ No newline at end of file
I've managed to work around this by constructing the unified diff string myself if the json strings are identical and feeding that into diff2html, but would be good to support this out of the box.