-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Handle spaces in initialConsonants search inputs properly (#42)
* fix: Handle spaces in initialConsonants search inputs properly * test: Add test cases for initialConsonants search with space * fix: remove unused function * refactor: 공백을 제거하는 역할을 chosungIncludes에 맡기도록 개선 * test: 초성자리에 공백만 들어갈 경우에 대한 테스트 케이스 추가 * fix: 초성 자리에 공백만 들어간 예외사항 처리 * refactor: trim된 문자열을 trimmedStr로 변경 Co-authored-by: 박찬혁 <[email protected]> * fix: 누락된 trimmedY의 변수명 변경 반영 * Create kind-pianos-thank.md --------- Co-authored-by: 박찬혁 <[email protected]>
- Loading branch information
1 parent
8a68b73
commit f668e15
Showing
3 changed files
with
29 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"es-hangul": patch | ||
--- | ||
|
||
fix: Handle spaces in initialConsonants search inputs properly |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,29 @@ | ||
import { HANGUL_CHARACTERS_BY_FIRST_INDEX } from './constants'; | ||
import { disassembleHangulToGroups } from './disassemble'; | ||
import { canBeChosung, getFirstConsonants, hasValueInReadOnlyStringList } from './utils'; | ||
import { canBeChosung, getFirstConsonants } from './utils'; | ||
|
||
export function chosungIncludes(x: string, y: string) { | ||
if (!isOnlyInitialConsonant(y)) { | ||
const trimmedY = y.replace(/\s/g, ''); | ||
|
||
if (!isOnlyInitialConsonant(trimmedY)) { | ||
return false; | ||
} | ||
|
||
const initialConsonantsX = getFirstConsonants(x).replace(/\s/g, ''); | ||
const initialConsonantsY = getFirstConsonants(y).replace(/\s/g, ''); | ||
const initialConsonantsY = trimmedY; | ||
|
||
return initialConsonantsX.includes(initialConsonantsY); | ||
} | ||
|
||
/* | ||
* @description 한글초성으로만 주어진 경우 | ||
* @description 문자열이 한글초성으로만 주어진 경우 | ||
*/ | ||
function isOnlyInitialConsonant(str: string) { | ||
return disassembleHangulToGroups(str).every(disassembled => { | ||
const groups = disassembleHangulToGroups(str); | ||
if (groups.length === 0) { | ||
return false; | ||
} | ||
|
||
return groups.every(disassembled => { | ||
return disassembled.length === 1 && canBeChosung(disassembled[0]); | ||
}); | ||
} |