From 5587a358cec71c0b74722d20c53355c1a5013053 Mon Sep 17 00:00:00 2001 From: hide_d Date: Tue, 7 Dec 2021 02:03:10 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=B4=88=EC=84=B1=20=EA=B2=80=EC=83=89?= =?UTF-8?q?=EC=97=90=EC=84=9C=20'=EC=95=8C=ED=8C=8C=EB=B2=B3'=20=EB=8C=80?= =?UTF-8?q?=EC=8B=A0=20=EA=B2=80=EC=83=89=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/ts/ReservedCommand.vue | 6 +++--- hwe/ts/util/filter초성withAlphabet.ts | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 hwe/ts/util/filter초성withAlphabet.ts diff --git a/hwe/ts/ReservedCommand.vue b/hwe/ts/ReservedCommand.vue index b0a1ade8..acf433d3 100644 --- a/hwe/ts/ReservedCommand.vue +++ b/hwe/ts/ReservedCommand.vue @@ -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}` } } diff --git a/hwe/ts/util/filter초성withAlphabet.ts b/hwe/ts/util/filter초성withAlphabet.ts new file mode 100644 index 00000000..a071b512 --- /dev/null +++ b/hwe/ts/util/filter초성withAlphabet.ts @@ -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('')]; +} \ No newline at end of file