Skip to content
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 : 문장의 각 단어 중 첫 문자만 뽑는 함수추가 ( #128 이슈에 대한 ) #133

Merged
merged 26 commits into from
Jun 29, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c811e8d
feat : 문장의 각 단어 중 첫 문자만 뽑는 함수추가
KNU-K Jun 25, 2024
2b7fbd4
add : 한글 문장인지 여부 판별 함수 추가
KNU-K Jun 28, 2024
cc53591
fix : 한글 문장인지 여부 판별 기저 및 오류 추가 / arg 이름 변경
KNU-K Jun 28, 2024
dcecb15
fix: src/_internal/hangul.ts
KNU-K Jun 29, 2024
b31a5b3
fix : rename function
KNU-K Jun 29, 2024
2e2b134
fix : rename function
KNU-K Jun 29, 2024
ea4cb1b
Merge branch 'main' of https://github.com/KNU-K/es-hangul
KNU-K Jun 29, 2024
83fd467
Merge branch 'main' into main
KNU-K Jun 29, 2024
7bd33ed
fix : lint error
KNU-K Jun 29, 2024
fffd30e
Merge branch 'main' of https://github.com/KNU-K/es-hangul
KNU-K Jun 29, 2024
1d74c1e
fix : index에 추가
KNU-K Jun 29, 2024
e5e7765
chore : doc 추가
KNU-K Jun 29, 2024
9c72739
fix : 문서화 한글 영어 바뀐거 바로 변경
KNU-K Jun 29, 2024
1ba5c31
Merge branch 'main' into main
KNU-K Jun 29, 2024
53544bd
fix : isHangul로 대체 #136 으로
KNU-K Jun 29, 2024
444e217
Merge branch 'main' of https://github.com/KNU-K/es-hangul
KNU-K Jun 29, 2024
4afa4d9
chore : doc수정
KNU-K Jun 29, 2024
8079b7d
Update docs/src/pages/docs/api/getHangulAcronym.en.mdx
KNU-K Jun 29, 2024
e409273
fix : Update hangul.ts
KNU-K Jun 29, 2024
4e4e5bd
Update getHangulAcronym.ko.mdx
KNU-K Jun 29, 2024
c6f1bc4
Update getHangulAcronym.en.mdx
KNU-K Jun 29, 2024
ba3ed2a
Update src/getHangulAcronym.ts
KNU-K Jun 29, 2024
00b3560
Update src/getHangulAcronym.ts
KNU-K Jun 29, 2024
b7dd6a7
Update getHangulAcronym.ts
KNU-K Jun 29, 2024
a36ab58
Update getHangulAcronym.spec.ts
KNU-K Jun 29, 2024
3ffcd89
Create fair-brooms-drive.md
okinawaa Jun 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/_internal/hangul.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ export function isHangulAlphabet(character: string) {
return /^[ㄱ-ㅣ]$/.test(character);
}

/**
* @name isHangulText
* @description
* text를 받으면 해당 text가 한글 문장인지를 구분합니다.
*
*/
export function isHangulText(text: string): boolean {
KNU-K marked this conversation as resolved.
Show resolved Hide resolved
return /^[\가-\힣\s]+$/.test(text);
}
/**
* @name binaryAssembleHangulAlphabets
* @description
Expand Down
22 changes: 22 additions & 0 deletions src/getFirstHangulLetters.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { getFirstHangulLetters } from './getFirstHangulLetters';

describe('getFirstHangulLetters', () => {
it('한글 문장 단어중 첫 문자만 뽑은 리스트를 반환', () => {
expect(getFirstHangulLetters('치킨과 맥주')).toHaveLength(2);
expect(getFirstHangulLetters('치킨과 맥주').join('')).toBe('치맥');

expect(getFirstHangulLetters('버스 충전 카드')).toHaveLength(3);
expect(getFirstHangulLetters('버스 충전 카드').join('')).toBe('버충카');
});
it('한글이 아닌 문장 넣었을 때', () => {
expect(() => getFirstHangulLetters('test test')).toThrowError(
'Invalid Hangul text, please input Hangul text only.'
);
});

it('한글과 영어가 섞인 문장을 넣었을 때', () => {
expect(() => getFirstHangulLetters('고기와 Cheese')).toThrowError(
'Invalid Hangul text, please input Hangul text only.'
);
});
});
18 changes: 18 additions & 0 deletions src/getFirstHangulLetters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { isHangulText } from './_internal/hangul';

/**
*
* @param getFirstHangulLetters
* @description
* 한글 문장을 입력받아서, 해당 한글 문장의 초성을을 리턴해줍니다.
* 한글 문장이 아닌, 문장은 취급하지않습니다. 추가로 한글 문장 + 영어 문장의 경우에도 취급하지않습니다.
*/
export function getFirstHangulLetters(text: string) {
KNU-K marked this conversation as resolved.
Show resolved Hide resolved
if (!isHangulText(text)) throw new Error('Invalid Hangul text, please input Hangul text only.');

const words = text.split(' ');

const firstHangulLetters = words.map(word => word.charAt(0));

return firstHangulLetters;
}