openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
29 lines (28 loc) • 828 B
JavaScript
//#region src/shared/levenshtein-distance.ts
function levenshteinDistance(e, t, n) {
if (e === t) return 0;
if (!e || !t) return n === void 0 ? e.length + t.length : null;
if (n !== void 0 && Math.abs(e.length - t.length) > n) return null;
const r = new Uint32Array(t.length + 1);
for (let e = 0; e <= t.length; e += 1) r[e] = e;
for (let i = 0; i < e.length; i += 1) {
let a = i;
let o = i + 1;
r[0] = o;
let s = i + 1;
const c = e.charCodeAt(i);
for (let e = 0; e < t.length; e += 1) {
const n = c === t.charCodeAt(e) ? 0 : 1;
const i = r[e + 1];
o = Math.min(o + 1, i + 1, a + n);
r[e + 1] = o;
s = Math.min(s, o);
a = i;
}
if (n !== void 0 && s > n) return null;
}
const i = r[t.length];
return n !== void 0 && i > n ? null : i;
}
//#endregion
export { levenshteinDistance as t };