Skip to content
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

JSON output when diffing text #641

Open
wittwerch opened this issue Dec 18, 2020 · 0 comments
Open

JSON output when diffing text #641

wittwerch opened this issue Dec 18, 2020 · 0 comments

Comments

@wittwerch
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant