Skip to content

Commit

Permalink
fix: 인자로 빈 문자열이 들어올 경우 얼리리턴하도록 수정 (#86)
Browse files Browse the repository at this point in the history
* fix: 빈 문자열이 들어올 때 false 처리

* chore: changeset 추가
  • Loading branch information
kangju2000 authored May 7, 2024
1 parent 1292575 commit 28fb57a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/friendly-news-draw.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"es-hangul": patch
---

fix: 인자로 빈 문자열이 들어올 경우 얼리리턴하도록 수정
12 changes: 9 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ import { disassembleCompleteHangulCharacter } from './disassembleCompleteHangulC
* hasBatchim('토') // false
*/
export function hasBatchim(str: string) {
const lastChar = str[str.length - 1]!;
const lastChar = str[str.length - 1];

if(lastChar == null) {
return false;
}

const disassembled = disassembleCompleteHangulCharacter(lastChar);
return disassembled != null && disassembled.last !== '';
}
Expand All @@ -42,8 +47,9 @@ export function hasBatchim(str: string) {
* hasSingleBatchim('토') // false
*/
export function hasSingleBatchim(str: string) {
const lastChar = str[str.length - 1]!;
if (hasBatchim(lastChar) === false) {
const lastChar = str[str.length - 1];

if (lastChar == null || hasBatchim(lastChar) === false) {
return false;
}

Expand Down

0 comments on commit 28fb57a

Please sign in to comment.