Skip to content

JSON output when diffing text #641

Open
@wittwerch

Description

@wittwerch

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions