-
Notifications
You must be signed in to change notification settings - Fork 101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: 한글 문장과 문자가 담긴 배열을 인자로 받아 규칙에 맞게 합성하는 assemble
함수 추가
#64
Conversation
🦋 Changeset detectedLatest commit: d791949 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@evan-moon is attempting to deploy a commit to the Toss Team on Vercel. A member of the Team first needs to authorize it. |
✅ Deploy Preview for es-hangul ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
export function joinString(...args: string[]) { | ||
return args.join(''); | ||
} | ||
|
||
export function isBlank(character: string) { | ||
return /^\s$/.test(character); | ||
} | ||
|
||
export default function assert(condition: boolean, errorMessage?: string): asserts condition { | ||
if (condition === false) { | ||
throw new Error(errorMessage ?? 'Invalid condition'); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
excludeLastElement
함수를 제외한 나머지가 이번에 추가된 함수들입니다.
src/_internal/hangul.ts
Outdated
`Invalid next character: ${nextCharacter}. Next character must be one of the chosung, jungsung, or jongsung.` | ||
); | ||
|
||
const sourceJamo = disassembleHangulToGroups(source)[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
disassembleHangulToGroups('각') = [['ㄱ', 'ㅏ', 'ㄱ']]
처럼 2차원 배열로 반환되기 때문에 바깥쪽 Array를 벗겨내어 ['ㄱ', 'ㅏ', 'ㄱ']
과 같은 1차원 배열로 변경합니다.
하나의 한글 문자를 분해하는 disassembleCompleteHangulCharacter
함수는 "각"처럼 완성된 한글 문자가 아닌 경우를 처리하지 못 하기 때문에 disassembleHangulToGroups
를 사용하였습니다.
const needLinking = canBeChosung(lastJamo) && canBeJungsung(nextCharacter); | ||
if (needLinking) { | ||
return linkHangulCharacters(source, nextCharacter); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
마지막 자모가 초성이 될 수 있는 문자이고 다음 입력 문자가 모음이면 연음법칙을 적용합니다.
const fixConsonant = curriedCombineHangulCharacter; | ||
const combineJungsung = fixConsonant(restJamos[0]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
source
가 자음과 모음이 합성된 한글 문자이니, sourceJamos
의 첫 알파벳은 자음으로 확정됩니다. (만약 모음이 첫 원소라면 source의 length가 1일 수 없음)
이제 자음 1개 + 모음 1개로 이루어진, 받침이 없는 문자에 대한 대응을 시작합니다.
const lastConsonant = lastJamo; | ||
|
||
if (hasSingleBatchim(source) && canBeJongsung(`${lastConsonant}${nextCharacter}`)) { | ||
return combineJongsung(`${lastConsonant}${nextCharacter}`); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이미 처음부터 받침을 가지고 있던 문자가 입력되었다면
- 연음법칙
- "홑받침 -> 겹받침"으로 변경
- 규칙에 위배되면 그냥 join
3개 케이스만 대응하면 됩니다. 연음법칙은 최상단에서 대응했으니, 겹받침을 생성하는 규칙만 적용해주면 됩니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
많은 PR 작업해주시느라 수고하셨습니다!!
src/utils.ts
Outdated
export function hasSingleBatchim(str: string) { | ||
const lastChar = str[str.length - 1]!; | ||
const disassembled = disassembleHangul(lastChar); | ||
|
||
return hasBatchim(lastChar) && disassembled.length === 3; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export function hasSingleBatchim(str: string) { | |
const lastChar = str[str.length - 1]!; | |
const disassembled = disassembleHangul(lastChar); | |
return hasBatchim(lastChar) && disassembled.length === 3; | |
} | |
export function hasSingleBatchim(str: string) { | |
const lastChar = str[str.length - 1]!; | |
if (!hasBatchim(lastChar)) return false; | |
const disassembled = disassembleHangul(lastChar); | |
return disassembled.length === 3; | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
받침이 없는 경우는 early return을 해주는 건 어떤가요?!
퍼포먼스에 큰 영향은 없을 것 같긴하네요.. ㅎㅎ
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
인지 부하를 줄일 수 있으니 가독성에는 좋은 영향이 있을 것 같습니다 ㅎㅎ 반영하고 핑 드릴게요 🙏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Codecov Report
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
고생하셨어요!!
Overview
#18 에서 이슈레이징되었던 한글 문장과 문자가 담긴 배열을 인자로 받아 규칙에 맞게 합성하는
assemble
함수, 그리고 한글 문장의 마지막 글자의 홑받침 여부를 판단하는hasSingleBatchim
를 추가합니다.기타 변경사항
_internal
모듈을 Directory로 변경하고, 내부에서만 사용할 한글 도메인의 함수를 추가하였습니다._internal
모듈에 문자열을 합성하는joinString
, 공백 문자열 여부를 판단하는isBlank
, throw 행위를 추상화하기 위한assert
함수가 추가되었습니다.src/chosungIncludes.ts
내에서 사용하고 있지 않은 모듈 디펜던시를 제거하였습니다.PR Checklist