prettydiff icon indicating copy to clipboard operation
prettydiff copied to clipboard

JSON output when diffing text

Open wittwerch opened this issue 5 years ago • 0 comments

I'm trying to build an app that compares typed text to a template and outputs a report to the user. The mockup looks like this:

Screenshot 2020-12-18 at 07 47 24

You typed "Goo dog" and the app tells you that you missed one character ("-" symbol)

So I'm looking into various libraries to compare the strings and prettydiff looks promising.

Screenshot 2020-12-18 at 07 51 53

Essentially I just need that information in a programmable output. I figured out that the json output might be what I want, because I need to apply some post-processing to get that report.

let prettydiff = require("prettydiff");

let options    = prettydiff.options;

options.source = 'Good dog';
options.diff = 'Goo dog';
options.mode = 'diff'
options.language = 'text';
options.diff_format = 'json'
options.report = true;


let output = prettydiff();

console.log(output);

Which gives me the following output:

{
   "diff":[
      [
         "r",
         "Good dog",
         "Goo dog"
      ]
   ]
}

I'm not sure if I missed something, but that essentially contains no information about what's different? Is there any other way to get that output?

wittwerch avatar Dec 18 '20 06:12 wittwerch