feat: 초성 검색에서 '알파벳' 대신 검색 추가

This commit is contained in:
2021-12-07 02:03:10 +09:00
parent 40b52dd517
commit 5587a358ce
2 changed files with 27 additions and 3 deletions
+3 -3
View File
@@ -198,7 +198,7 @@ import { mb_strwidth } from "./util/mb_strwidth";
import { parseTime } from "./util/parseTime";
import { parseYearMonth } from "./util/parseYearMonth";
import { sammoAPI } from "./util/sammoAPI";
import { filter초성 } from "./util/filter초성";
import { filter초성withAlphabet } from "./util/filter초성withAlphabet";
type commandItem = {
value: string;
@@ -473,8 +473,8 @@ export default defineComponent({
if(command.searchText){
continue;
}
const filteredText = filter초성(command.simpleName).replace(/\s+/g, '');
command.searchText = `${command.simpleName} ${filteredText}`
const [filteredTextH, filteredTextA] = filter초성withAlphabet(command.simpleName.replace(/\s+/g, ''));
command.searchText = `${command.simpleName} ${filteredTextH} ${filteredTextA}`
}
}
+24
View File
@@ -0,0 +1,24 @@
export function filter초성withAlphabet(text: string): [string, string] {
const = [
"ㄱ", "ㄲ", "ㄴ", "ㄷ", "ㄸ", "ㄹ", "ㅁ", "ㅂ", "ㅃ",
"ㅅ", "ㅆ", "ㅇ", "ㅈ", "ㅉ", "ㅊ", "ㅋ", "ㅌ", "ㅍ", "ㅎ"
];
const alphabets = [
"r", "R", "s", "e", "E", "f", "a", "q", "Q",
"t", "T", "d", "w", "W", "c", "z", "x", "v", "g"
];
const resultH: string[] = [];
const resultA: string[] = [];
for (const char of text) {
const code = (char.codePointAt(0) ?? 0) - 44032;
if (0 <= code && code < 11172) {
resultH.push([~~(code / 588)]);
resultA.push(alphabets[~~(code / 588)]);
}
else {
resultH.push(char);
resultA.push(char);
}
}
return [resultH.join(''), resultA.join('')];
}