-
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: 문자열에서 한글만 반환하는 extractHangul을 구현합니다. #130
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5e81807
feat: parseHangul
Collection50 fca8a59
fix: parseHangul의 이름을 extractHangul로 수정 및 테스트 코드 보완
Collection50 c49d256
test: 일관된 테스트 코드 작성이 될 수 있도록 describe 설명 수정
Collection50 ee9b012
test: 테스트 코드 수정
Collection50 ce8e175
docs: extractHangul의 문서 작성
Collection50 3bf4fba
test: 테스트 문구 수정
Collection50 f7b29f2
fix: index.ts에 export 추가
Collection50 1d3df38
Merge branch 'main' into feat/parseHangul
Collection50 f8ef0b9
Create fresh-students-sit.md
okinawaa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
실제 사용할 수 있도록 src/index.ts에서 export 해주시면 좋을 것 같아요
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.
완료했습니다 ! 감사합니다 !