-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 문자열에서 한글만 반환하는 extractHangul을 구현합니다. (#130)
* feat: parseHangul * fix: parseHangul의 이름을 extractHangul로 수정 및 테스트 코드 보완 * test: 일관된 테스트 코드 작성이 될 수 있도록 describe 설명 수정 * test: 테스트 코드 수정 * docs: extractHangul의 문서 작성 * test: 테스트 문구 수정 * fix: index.ts에 export 추가 * Create fresh-students-sit.md --------- Co-authored-by: 박찬혁 <[email protected]>
- Loading branch information
1 parent
b25fcc5
commit acd6edb
Showing
6 changed files
with
97 additions
and
0 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 | ||
--- | ||
|
||
feat: 문자열에서 한글만 반환하는 extractHangul을 구현합니다. |
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,23 @@ | ||
--- | ||
title: extractHangul | ||
--- | ||
|
||
# extractHangul | ||
|
||
Extracts and returns only Korean characters from the string. | ||
|
||
For detailed examples, see below. | ||
|
||
```typescript | ||
function extractHangul(str: string): string; | ||
``` | ||
|
||
## Examples | ||
|
||
```tsx | ||
extractHangul('안녕하세요1234abc'); // '안녕하세요' | ||
extractHangul('abcde'); // '' | ||
extractHangul('안녕하세요ㄱㄴ'); // '안녕하세요ㄱㄴ' | ||
extractHangul('안녕하세요 만나서 반갑습니다'); // '안녕하세요 만나서 반갑습니다' | ||
extractHangul('가나다!-29~라마바.,,사'); // '가나다라마바사' | ||
``` |
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,23 @@ | ||
--- | ||
title: extractHangul | ||
--- | ||
|
||
# extractHangul | ||
|
||
문자열에서 한글만 추출하여 반환합니다. | ||
|
||
자세한 예시는 아래 Example을 참고하세요. | ||
|
||
```typescript | ||
function extractHangul(str: string): string; | ||
``` | ||
|
||
## Examples | ||
|
||
```tsx | ||
extractHangul('안녕하세요1234abc'); // '안녕하세요' | ||
extractHangul('abcde'); // '' | ||
extractHangul('안녕하세요ㄱㄴ'); // '안녕하세요ㄱㄴ' | ||
extractHangul('안녕하세요 만나서 반갑습니다'); // '안녕하세요 만나서 반갑습니다' | ||
extractHangul('가나다!-29~라마바.,,사'); // '가나다라마바사' | ||
``` |
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,27 @@ | ||
import { extractHangul } from './extractHangul'; | ||
|
||
describe('extractHangul', () => { | ||
it('숫자와 알파벳과 특수문자를 제외한 한글 반환', () => { | ||
expect(extractHangul('안녕하세요1234abc!@#')).toBe('안녕하세요'); | ||
}); | ||
|
||
it('한글이 없는 문자열', () => { | ||
expect(extractHangul('1234abc')).toBe(''); | ||
}); | ||
|
||
it('한글과 공백을 제외한 다른 문자는 제거', () => { | ||
expect(extractHangul('한글과 영어가 섞인 문장입니다. Hello!')).toBe('한글과 영어가 섞인 문장입니다 '); | ||
}); | ||
|
||
it('escape 문자열 유지', () => { | ||
expect(extractHangul('한글과\n\t줄바꿈')).toBe('한글과\n\t줄바꿈'); | ||
}); | ||
|
||
it('모음은 제거하지 않음', () => { | ||
expect(extractHangul('ㅠㅠ')).toBe('ㅠㅠ'); | ||
}); | ||
|
||
it('자음은 제거하지 않음', () => { | ||
expect(extractHangul('ㄱㄴㄱㄴ')).toBe('ㄱㄴㄱㄴ'); | ||
}); | ||
}); |
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,18 @@ | ||
/** | ||
* @name extractHangul | ||
* @description | ||
* 문자열을 입력받고 한글만 추출해 반환합니다. | ||
* | ||
* @param {string} chars 모든 문자열 | ||
* | ||
* @example | ||
* extractHangul('안녕하세요1234abc') // '안녕하세요' | ||
* extractHangul('abcde') // '' | ||
* extractHangul('안녕하세요ㄱㄴ') // '안녕하세요ㄱㄴ' | ||
* extractHangul('안녕하세요 만나서 반갑습니다') // '안녕하세요 만나서 반갑습니다' | ||
* extractHangul('가나다!-29~라마바.,,사') // '가나다라마바사' | ||
*/ | ||
|
||
export function extractHangul(str: string): string { | ||
return str.replace(/[^ㄱ-ㅎㅏ-ㅣ가-힣\s]+/g, ''); | ||
} |
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