-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* hasOnlyNumberAndEnglish, hasOnlyNumberAndEnglishAndHangul 추가 * fix: 문자열 닫기 추가 * fix: hasOnlyNumberAndEnglishAndHangul.ko.md 오작성된 함수 이름 수정 * feat: 테스트 코드 작성 및 hasOnlyNumberAndEnglishAndHangul 함수 수정
- Loading branch information
Showing
7 changed files
with
146 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,21 @@ | ||
# hasOnlyNumberAndEnglish | ||
|
||
주어진 문자열이 오직 숫자와 영어 알파벳(대소문자)으로만 구성되어 있는지 확인하는 함수입니다. | ||
|
||
## 매개변수 | ||
|
||
- `value`: 검사할 문자열입니다. | ||
|
||
## 반환값 | ||
|
||
문자열이 오직 숫자와 영어 알파벳으로만 구성되어 있으면 `true`를 반환하고, 그렇지 않으면 `false`를 반환합니다. | ||
|
||
## Example | ||
|
||
```typescript | ||
console.log(hasOnlyNumberAndEnglish('Hello123')); // true | ||
console.log(hasOnlyNumberAndEnglish('123')); // true | ||
console.log(hasOnlyNumberAndEnglish('Hello')); // true | ||
console.log(hasOnlyNumberAndEnglish('Hello123!')); // false | ||
console.log(hasOnlyNumberAndEnglish('@#$%')); // false | ||
``` |
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,37 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
|
||
import { hasOnlyNumberAndEnglish } from './hasOnlyNumberAndEnglish'; | ||
|
||
describe('hasOnlyNumberAndEnglish', () => { | ||
it('should return true for a string with only numbers', () => { | ||
expect(hasOnlyNumberAndEnglish('123456')).toBe(true); | ||
}); | ||
|
||
it('should return true for a string with only uppercase English letters', () => { | ||
expect(hasOnlyNumberAndEnglish('ABCDEF')).toBe(true); | ||
}); | ||
|
||
it('should return true for a string with only lowercase English letters', () => { | ||
expect(hasOnlyNumberAndEnglish('abcdef')).toBe(true); | ||
}); | ||
|
||
it('should return true for a string with mixed numbers and English letters', () => { | ||
expect(hasOnlyNumberAndEnglish('abc123DEF')).toBe(true); | ||
}); | ||
|
||
it('should return false for a string with special characters', () => { | ||
expect(hasOnlyNumberAndEnglish('abc123!@#')).toBe(false); | ||
}); | ||
|
||
it('should return false for a string with spaces', () => { | ||
expect(hasOnlyNumberAndEnglish('abc 123')).toBe(false); | ||
}); | ||
|
||
it('should return false for a string with non-English letters', () => { | ||
expect(hasOnlyNumberAndEnglish('abc123한글')).toBe(false); | ||
}); | ||
|
||
it('should return true for an empty string', () => { | ||
expect(hasOnlyNumberAndEnglish('')).toBe(true); | ||
}); | ||
}); |
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,7 @@ | ||
/** | ||
* 주어진 문자열이 오직 숫자와 영어 알파벳(대소문자)으로만 구성되어 있는지 확인하는 함수입니다. | ||
* | ||
* @param value - 검사할 문자열입니다. | ||
* @returns 문자열이 오직 숫자와 영어 알파벳으로만 구성되어 있으면 true를 반환하고, 그렇지 않으면 false를 반환합니다. | ||
*/ | ||
export const hasOnlyNumberAndEnglish = (value: string) => /^[a-zA-Z0-9]*$/.test(value); |
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,21 @@ | ||
# hasOnlyNumberAndEnglishAndHangul | ||
|
||
주어진 문자열이 오직 영어 알파벳(대문자 및 소문자), 한글(자모 및 음절), 숫자로만 구성되어 있는지 확인하는 함수입니다. | ||
|
||
## 매개변수 | ||
|
||
- `value`: 검사할 문자열입니다. | ||
|
||
## 반환값 | ||
|
||
문자열이 오직 영어 알파벳, 한글, 숫자로만 구성되어 있으면 `true`를 반환하고, 그렇지 않으면 `false`를 반환합니다. | ||
|
||
## Example | ||
|
||
```typescript | ||
console.log(hasOnlyNumberAndEnglishAndHangul('Hello123')); // true | ||
console.log(hasOnlyNumberAndEnglishAndHangul('안녕하세요')); // true | ||
console.log(hasOnlyNumberAndEnglishAndHangul('123')); // true | ||
console.log(hasOnlyNumberAndEnglishAndHangul('Hello123안녕하세요')); // true | ||
console.log(hasOnlyNumberAndEnglishAndHangul('@#$%')); // false | ||
``` |
49 changes: 49 additions & 0 deletions
49
packages/utils/src/hasOnlyNumberAndEnglishAndHangul.test.ts
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,49 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
|
||
import { hasOnlyNumberAndEnglishAndHangul } from './hasOnlyNumberAndEnglishAndHangul'; | ||
|
||
describe('hasOnlyNumberAndEnglishAndHangul', () => { | ||
it('should return true for a string with only numbers', () => { | ||
expect(hasOnlyNumberAndEnglishAndHangul('123456')).toBe(true); | ||
}); | ||
|
||
it('should return true for a string with only uppercase English letters', () => { | ||
expect(hasOnlyNumberAndEnglishAndHangul('ABCDEF')).toBe(true); | ||
}); | ||
|
||
it('should return true for a string with only lowercase English letters', () => { | ||
expect(hasOnlyNumberAndEnglishAndHangul('abcdef')).toBe(true); | ||
}); | ||
|
||
it('should return true for a string with mixed numbers and English letters', () => { | ||
expect(hasOnlyNumberAndEnglishAndHangul('abc123DEF')).toBe(true); | ||
}); | ||
|
||
it('should return true for a string with only Hangul syllables', () => { | ||
expect(hasOnlyNumberAndEnglishAndHangul('한글테스트')).toBe(true); | ||
}); | ||
|
||
it('should return true for a string with mixed Hangul and numbers', () => { | ||
expect(hasOnlyNumberAndEnglishAndHangul('한글123')).toBe(true); | ||
}); | ||
|
||
it('should return true for a string with mixed Hangul and English letters', () => { | ||
expect(hasOnlyNumberAndEnglishAndHangul('한글abcDEF')).toBe(true); | ||
}); | ||
|
||
it('should return false for a string with special characters', () => { | ||
expect(hasOnlyNumberAndEnglishAndHangul('abc123!@#')).toBe(false); | ||
}); | ||
|
||
it('should return false for a string with spaces', () => { | ||
expect(hasOnlyNumberAndEnglishAndHangul('한글 abc 123')).toBe(false); | ||
}); | ||
|
||
it('should return false for a string with non-Hangul, non-English letters', () => { | ||
expect(hasOnlyNumberAndEnglishAndHangul('abc123漢字')).toBe(false); | ||
}); | ||
|
||
it('should return true for an empty string', () => { | ||
expect(hasOnlyNumberAndEnglishAndHangul('')).toBe(true); | ||
}); | ||
}); |
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,9 @@ | ||
/** | ||
* 주어진 문자열이 오직 영어 알파벳(대문자 및 소문자), 한글(자모 및 음절), 숫자로만 구성되어 있는지 확인하는 함수입니다. | ||
* | ||
* @param value - 검사할 문자열입니다. | ||
* @returns 문자열이 오직 영어 알파벳, 한글, 숫자로만 구성되어 있으면 true를 반환하고, | ||
* 그렇지 않으면 false를 반환합니다. | ||
*/ | ||
export const hasOnlyNumberAndEnglishAndHangul = (value: string) => | ||
/^[ㄱ-ㅎ가-힣a-zA-Z0-9]*$/.test(value); |
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,2 @@ | ||
export { hasOnlyNumberAndEnglish } from './hasOnlyNumberAndEnglish'; | ||
export { hasOnlyNumberAndEnglishAndHangul } from './hasOnlyNumberAndEnglishAndHangul.ts'; |