diff --git a/.changeset/few-lies-give.md b/.changeset/few-lies-give.md new file mode 100644 index 00000000..2da37fb4 --- /dev/null +++ b/.changeset/few-lies-give.md @@ -0,0 +1,5 @@ +--- +"es-hangul": patch +--- + +chore: hasbatchim 함수의 조건문 검사 로직을 개선합니다. diff --git a/src/hasBatchim/hasBatchim.ts b/src/hasBatchim/hasBatchim.ts index c004a0aa..434a3bd8 100644 --- a/src/hasBatchim/hasBatchim.ts +++ b/src/hasBatchim/hasBatchim.ts @@ -41,21 +41,24 @@ export function hasBatchim( return false; } const charCode = lastChar.charCodeAt(0); - const isCompleteHangul = COMPLETE_HANGUL_START_CHARCODE <= charCode && charCode <= COMPLETE_HANGUL_END_CHARCODE; + const isNotCompleteHangul = charCode < COMPLETE_HANGUL_START_CHARCODE || charCode > COMPLETE_HANGUL_END_CHARCODE; - if (!isCompleteHangul) { + if (isNotCompleteHangul) { return false; } const batchimCode = (charCode - COMPLETE_HANGUL_START_CHARCODE) % NUMBER_OF_JONGSEONG; + const batchimLength = JONGSEONGS[batchimCode].length; - if (options?.only === 'single') { - return JONGSEONGS[batchimCode].length === 1; + switch (options?.only) { + case 'single': { + return batchimLength === 1; + } + case 'double': { + return batchimLength === 2; + } + default: { + return batchimCode > 0; + } } - - if (options?.only === 'double') { - return JONGSEONGS[batchimCode].length === 2; - } - - return batchimCode > 0; }