Skip to content

Commit

Permalink
feat(romanize): 초성이 될수 없는 겹자음은 분리하여 처리
Browse files Browse the repository at this point in the history
  • Loading branch information
2wheeh committed Aug 5, 2024
1 parent 4a836d9 commit 9ad42e6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/romanize.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ describe('romanize', () => {
expect(romanize('가나다라ㅁㅂㅅㅇ')).toBe('ganadarambs');
expect(romanize('ㅏ')).toBe('a');
expect(romanize('ㅘ')).toBe('wa');
expect(romanize('ㄳ')).toBe('gs');
});

it('특수문자는 로마자 표기로 변경하지 않는다', () => {
Expand Down
18 changes: 14 additions & 4 deletions src/romanize.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import assert from './_internal';
import { isHangulCharacter } from './_internal/hangul';
import { assembleHangul } from './assemble';
import { 종성_알파벳_발음, 중성_알파벳_발음, 초성_알파벳_발음 } from './constants';
import {
DISASSEMBLED_CONSONANTS_BY_CONSONANT,
종성_알파벳_발음,
중성_알파벳_발음,
초성_알파벳_발음,
} from './constants';
import { disassembleCompleteHangulCharacter } from './disassembleCompleteHangulCharacter';
import { standardizePronunciation } from './standardizePronunciation';
import { canBeChoseong } from './utils';
import { hasProperty } from './utils';

/**
* 주어진 한글 문자열을 로마자로 변환합니다.
Expand Down Expand Up @@ -47,8 +53,12 @@ const romanizeSyllableHangul = (arrayHangul: string[], index: number): string =>
return 중성_알파벳_발음[syllable];
}

if (hasProperty(초성_알파벳_발음, syllable)) {
return 초성_알파벳_발음[syllable];
if (hasProperty(DISASSEMBLED_CONSONANTS_BY_CONSONANT, syllable)) {
return DISASSEMBLED_CONSONANTS_BY_CONSONANT[syllable].split('').reduce((acc, consonant) => {
assert(hasProperty(초성_알파벳_발음, consonant), `${consonant}에 해당하는 알파벳 발음이 존재하지 않습니다.`);

return acc + 초성_알파벳_발음[consonant];
}, '');
}

return syllable;
Expand Down

0 comments on commit 9ad42e6

Please sign in to comment.