@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.
38 lines • 1.31 kB
JavaScript
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports"], factory);
}
})(function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = diffStrings;
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