@azizbecha/strkit
Version:
strkit is a utility library offering a collection of essential string functions including validation, case conversion, truncation, and more. Ideal for both JavaScript and TypeScript developers to simplify string operations in their applications.
25 lines • 762 B
JavaScript
export default function diffStrings(str1, str2) {
const diff = [];
let i = 0;
let j = 0;
while (i < str1.length || j < str2.length) {
if (str1[i] === str2[j]) {
let equalChars = '';
while (str1[i] === str2[j] && i < str1.length) {
equalChars += str1[i];
i++;
j++;
}
if (equalChars)
diff.push({ type: 'equal', value: equalChars });
}
else {
if (i < str1.length)
diff.push({ type: 'removed', value: str1[i++] });
if (j < str2.length)
diff.push({ type: 'added', value: str2[j++] });
}
}
return diff;
}
//# sourceMappingURL=diffStrings.js.map