Skip to content

A Javascript helper to get diff of String return into an array.

License

Notifications You must be signed in to change notification settings

canfone/string-diff-helper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

string-diff-helper

A simple javascript helper to get diff of String return into an array.

See live demo here

How to use

Using native javascript, first you need to include the library file in your application.

<script type="text/javascript" src="src/string-diff-helper.js"></script>

After that you can now access the StringDiffHelper object to get the difference of two strings.

let string1 = "Your first string here...";
let string2 = "Your second string here...";

let diff = StringDiffHelper.lineOutputBuilder(string1, string2);

The returned variable diff will be an array of lines if your strings are multiple line strings. If your strings are just single line then it will return a single element array. Each element is an object of three keys, the remark, diff1 and diff2.

{
    remark: "<>",
    diff1: "Your <mark>fir</mark>s<mark>t</mark> string here...",
    diff2: Your s<mark>econd</mark> string here...
}

Notice the <mark> tag, that portion of your string was the diff.

You can fully customize your application based on your preferences using this helper. Just play around with it. :)

License

Copyright (c) 2017 Cliff Richard Anfone. Released under the terms of the MIT license.

About

A Javascript helper to get diff of String return into an array.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published