Files
TrueGrowth/vendor/aigcpanel/electron/lib/pinyin-util.ts
Jammy 52636c91ae
Some checks failed
CI / main (push) Has been cancelled
CI / release-e2e (push) Has been cancelled
Track bundled vendor runtime sources
2026-07-07 10:05:50 +08:00

29 lines
808 B
TypeScript

import PinyinMatch from "pinyin-match";
export const PinyinUtil = {
match(input, keywords) {
const index = PinyinMatch.match(input, keywords);
let inputMark = input;
let similarity = 0;
if (index) {
const indexStart = index[0];
const indexEnd = index[1];
inputMark =
input.substring(0, indexStart) +
"<mark>" +
input.substring(indexStart, indexEnd + 1) +
"</mark>" +
input.substring(indexEnd + 1);
similarity = (indexEnd - indexStart + 1) / input.length;
}
return {
matched: !!index,
inputMark,
similarity,
};
},
mark(text) {
return `<mark>${text}</mark>`;
},
};