Skip to content

Commit

Permalink
fix: 메서드 컨벤션을 적용합니다 toss#132
Browse files Browse the repository at this point in the history
  • Loading branch information
po4tion committed Jul 2, 2024
1 parent 3641f8b commit 59c79fd
Show file tree
Hide file tree
Showing 17 changed files with 584 additions and 584 deletions.
28 changes: 28 additions & 0 deletions docs/src/pages/docs/api/romanize.en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
title: romanize
---

# romanize

Change the Hangul string to Roman.

For detailed examples, see below.

```typescript
function romanize(hangul: string): string;
```

## Examples

```tsx
romanize('백마'); // 'baengma'
romanize('학여울'); // 'hangnyeoul'
romanize('해돋이'); // 'haedoji'
romanize('좋고'); // 'joko'
romanize('압구정'); // 'apgujeong'
romanize('구미'); // 'gumi'
romanize('대관령'); // 'daegwallyeong'
romanize(''); // 'g'
romanize('한국어!'); // 'hangugeo!'
romanize('안녕하세요'); // 'annyeonghaseyo'
```
28 changes: 28 additions & 0 deletions docs/src/pages/docs/api/romanize.ko.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
title: romanize
---

# romanize

한글 문자열을 로마자로 변경합니다.

자세한 예시는 아래 Example을 참고하세요.

```typescript
function romanize(hangul: string): string;
```

## Examples

```tsx
romanize('백마'); // 'baengma'
romanize('학여울'); // 'hangnyeoul'
romanize('해돋이'); // 'haedoji'
romanize('좋고'); // 'joko'
romanize('압구정'); // 'apgujeong'
romanize('구미'); // 'gumi'
romanize('대관령'); // 'daegwallyeong'
romanize(''); // 'g'
romanize('한국어!'); // 'hangugeo!'
romanize('안녕하세요'); // 'annyeonghaseyo'
```
28 changes: 0 additions & 28 deletions docs/src/pages/docs/api/romanizeHangul.en.md

This file was deleted.

28 changes: 0 additions & 28 deletions docs/src/pages/docs/api/romanizeHangul.ko.md

This file was deleted.

42 changes: 0 additions & 42 deletions docs/src/pages/docs/api/standardPronunciation.en.md

This file was deleted.

42 changes: 0 additions & 42 deletions docs/src/pages/docs/api/standardPronunciation.ko.md

This file was deleted.

42 changes: 42 additions & 0 deletions docs/src/pages/docs/api/standardizePronunciation.en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
title: standardizePronunciation
---

# standardizePronunciation

Change the Hangul string to standard pronunciation.

For detailed examples, see below.

```typescript
function standardizePronunciation(
// Input a Hangul string
hangul: string,
options: {
// Set whether to apply hard sounds. Default is true."
hardConversion: boolean;
} = { hardConversion: true }
): string;
```

## Examples

```tsx
standardizePronunciation('디귿이'); // '디그시'
standardizePronunciation('굳이'); // '구지'
standardizePronunciation('담요'); // '딤뇨'
standardizePronunciation('침략'); // '침냑'
standardizePronunciation('먹는'); // '멍는'
standardizePronunciation('신라'); // '실라'
standardizePronunciation('놓고'); // '노코'
standardizePronunciation('곧이듣다'); // '고지듣따'
standardizePronunciation('곧이듣다', { hardConversion: false }); // '고지듣다'
standardizePronunciation('닦다'); // '닥따'
standardizePronunciation('닦다', { hardConversion: false }); // '닥다'
standardizePronunciation('있다'); // '읻따'
standardizePronunciation('있다', { hardConversion: false }); // '읻다'
standardizePronunciation('핥다'); // '할따'
standardizePronunciation('핥다', { hardConversion: false }); // '할다'
standardizePronunciation('젊다'); // '점따'
standardizePronunciation('젊다', { hardConversion: false }); // '점다'
```
42 changes: 42 additions & 0 deletions docs/src/pages/docs/api/standardizePronunciation.ko.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
title: standardizePronunciation
---

# standardizePronunciation

한글 문자열을 표준 발음법으로 변경합니다.

자세한 예시는 아래 Example을 참고하세요.

```typescript
function standardizePronunciation(
// 한글 문자열을 입력합니다.
hangul: string,
options: {
// 경음화 등의 된소리를 적용할지 여부를 설정합니다. 기본값은 true입니다.
hardConversion: boolean;
} = { hardConversion: true }
): string;
```

## Examples

```tsx
standardizePronunciation('디귿이'); // '디그시'
standardizePronunciation('굳이'); // '구지'
standardizePronunciation('담요'); // '딤뇨'
standardizePronunciation('침략'); // '침냑'
standardizePronunciation('먹는'); // '멍는'
standardizePronunciation('신라'); // '실라'
standardizePronunciation('놓고'); // '노코'
standardizePronunciation('곧이듣다'); // '고지듣따'
standardizePronunciation('곧이듣다', { hardConversion: false }); // '고지듣다'
standardizePronunciation('닦다'); // '닥따'
standardizePronunciation('닦다', { hardConversion: false }); // '닥다'
standardizePronunciation('있다'); // '읻따'
standardizePronunciation('있다', { hardConversion: false }); // '읻다'
standardizePronunciation('핥다'); // '할따'
standardizePronunciation('핥다', { hardConversion: false }); // '할다'
standardizePronunciation('젊다'); // '점따'
standardizePronunciation('젊다', { hardConversion: false }); // '점다'
```
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export { extractHangul } from './extractHangul';
export { hangulIncludes } from './hangulIncludes';
export { josa } from './josa';
export { removeLastHangulCharacter } from './removeLastHangulCharacter';
export { romanizeHangul } from './romanizeHangul';
export { standardPronunciation } from './standardPronunciation';
export { romanize } from './romanize';
export { standardizePronunciation } from './standardizePronunciation';
export {
canBeChosung,
canBeJongsung,
Expand Down
81 changes: 81 additions & 0 deletions src/romanize.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { romanize } from './romanize';

describe('romanize', () => {
it('자음 사이에서 동화 작용이 일어나는 경우', () => {
expect(romanize('백마')).toBe('baengma');
expect(romanize('종로')).toBe('jongno');
expect(romanize('왕십리')).toBe('wangsimni');
expect(romanize('별래')).toBe('byeollae');
expect(romanize('신라')).toBe('silla');
});

it('ㄴ, ㄹ’이 덧나는 경우', () => {
expect(romanize('학여울')).toBe('hangnyeoul');
expect(romanize('알약')).toBe('allyak');
});

it('구개음화가 되는 경우', () => {
expect(romanize('해돋이')).toBe('haedoji');
expect(romanize('같이')).toBe('gachi');
expect(romanize('굳히다')).toBe('guchida');
});

it('"ㄱ, ㄷ, ㅂ, ㅈ"이 "ㅎ"과 합하여 거센소리로 소리 나는 경우', () => {
expect(romanize('좋고')).toBe('joko');
expect(romanize('놓다')).toBe('nota');
expect(romanize('잡혀')).toBe('japyeo');
expect(romanize('낳지')).toBe('nachi');
});

it('된소리되기는 표기에 반영하지 않는다', () => {
expect(romanize('압구정')).toBe('apgujeong');
expect(romanize('낙동강')).toBe('nakdonggang');
expect(romanize('죽변')).toBe('jukbyeon');
expect(romanize('낙성대')).toBe('nakseongdae');
expect(romanize('합정')).toBe('hapjeong');
expect(romanize('팔당')).toBe('paldang');
expect(romanize('샛별')).toBe('saetbyeol');
expect(romanize('울산')).toBe('ulsan');
});

it('"ㄱ, ㄷ, ㅂ"은 모음 앞에서는 "g, d, b"로, 자음 앞이나 어말에서는 "k, t, p"로 적는다', () => {
expect(romanize('구미')).toBe('gumi');
expect(romanize('영동')).toBe('yeongdong');
expect(romanize('백암')).toBe('baegam');
expect(romanize('옥천')).toBe('okcheon');
expect(romanize('합덕')).toBe('hapdeok');
expect(romanize('호법')).toBe('hobeop');
expect(romanize('월곶')).toBe('wolgot');
expect(romanize('벚꽃')).toBe('beotkkot');
expect(romanize('한밭')).toBe('hanbat');
});

it('"ㄹ"은 모음 앞에서는 "r"로, 자음 앞이나 어말에서는 "l"로 적는다. 단, "ㄹㄹ"은 "ll"로 적는다', () => {
expect(romanize('구리')).toBe('guri');
expect(romanize('설악')).toBe('seorak');
expect(romanize('칠곡')).toBe('chilgok');
expect(romanize('임실')).toBe('imsil');
expect(romanize('울릉')).toBe('ulleung');
expect(romanize('대관령')).toBe('daegwallyeong');
});

it('완성된 음절이 아닌 경우에는 그대로 반환한다', () => {
expect(romanize('ㄱ')).toBe('g');
expect(romanize('가나다라ㅁㅂㅅㅇ')).toBe('ganadarambs');
expect(romanize('ㅏ')).toBe('a');
expect(romanize('ㅘ')).toBe('wa');
});

it('특수문자는 로마자 표기로 변경하지 않는다', () => {
expect(romanize('안녕하세요')).toBe('annyeonghaseyo');
expect(romanize('한국어!')).toBe('hangugeo!');
expect(romanize('')).toBe('');
expect(romanize('!?/')).toBe('!?/');
});

it('한글과 영어가 혼합된 경우에는 영어는 그대로 반환된다', () => {
expect(romanize('안녕하세요 es-hangul')).toBe('annyeonghaseyo es-hangul');
expect(romanize('한국은korea')).toBe('hangugeunkorea');
expect(romanize('고양이는cat')).toBe('goyangineuncat');
});
});
6 changes: 3 additions & 3 deletions src/romanizeHangul.ts → src/romanize.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { assembleHangul, canBeChosung, disassembleCompleteHangulCharacter } from '.';
import { isHangulCharacter } from './_internal/hangul';
import { 종성_알파벳_발음, 중성_알파벳_발음, 초성_알파벳_발음 } from './constants';
import { standardPronunciation } from './standardPronunciation';
import { standardizePronunciation } from './standardizePronunciation';

/**
* 주어진 한글 문자열을 로마자로 변환합니다.
* @param hangul 한글 문자열을 입력합니다.
* @returns 변환된 로마자를 반환합니다.
*/
export function romanizeHangul(hangul: string): string {
const changedHangul = standardPronunciation(hangul, { hardConversion: false });
export function romanize(hangul: string): string {
const changedHangul = standardizePronunciation(hangul, { hardConversion: false });

return changedHangul
.split('')
Expand Down
Loading

0 comments on commit 59c79fd

Please sign in to comment.