Use text-diff

This commit is contained in:
Dragon Fire
2021-02-09 16:57:22 -05:00
parent 4f3bd6464f
commit 47c234ae54
3 changed files with 11 additions and 16 deletions
-14
View File
@@ -181,20 +181,6 @@ module.exports = class Util {
return ((r << 16) | (g << 8) | b).toString(16);
}
static textDiff(oldText, newText) {
let changed = [];
return oldText.split('').map((char, i) => {
if (char === newText.charAt(i)) {
const chars = changed.length ? `**${changed.join('')}**${char}` : char;
if (changed.length) changed = [];
const extraText = newText.slice(oldText.length);
return i === oldText.length - 1 ? `${chars}${extraText.length ? `**${extraText}**` : ''}` : chars;
}
changed.push(newText.charAt(i));
return i === oldText.length - 1 ? `**${changed.join('')}${newText.slice(oldText.length)}**` : '';
}).join('');
}
static magikToBuffer(magik) {
return new Promise((res, rej) => {
magik.toBuffer((err, buffer) => {