Easily find the difference between two strings using Levenshtein distance.
A demo is available on my playground.
To find the diff between two strings, specify the source and the final string to find the transformation.
const source = 'pineapple';
const destination = 'apple';
iqwerty.diff.diff(source, destination);A DiffObject is returned. It contains the following properties:
The source string - in this case: 'pineapple'.
The destination string - in this case: 'apple'.
The edit distance, or the amount of changes needed to transform the source to destination string.
An array containing the changes needed to transform the source string. You may parse this yourself if you wish.
Call this method to print the default string with changes made. In this case, .toString() will output an object:
{
plainText: '(-pine)apple',
richText: '<span class="iqwerty-diff-remove">(-pine)</span>apple',
}The iqwerty-diff-remove and iqwerty-diff-add classes can be styled however you like.