Initial clean project import
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
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>`;
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user