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: add utils package #7

Merged
merged 5 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
21 changes: 21 additions & 0 deletions packages/utils/src/hasOnlyNumberAndEnglish.ko.md
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
```
37 changes: 37 additions & 0 deletions packages/utils/src/hasOnlyNumberAndEnglish.test.ts
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);
});
});
7 changes: 7 additions & 0 deletions packages/utils/src/hasOnlyNumberAndEnglish.ts
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);
21 changes: 21 additions & 0 deletions packages/utils/src/hasOnlyNumberAndEnglishAndHangul.ko.md
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 packages/utils/src/hasOnlyNumberAndEnglishAndHangul.test.ts
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);
});
});
9 changes: 9 additions & 0 deletions packages/utils/src/hasOnlyNumberAndEnglishAndHangul.ts
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);
2 changes: 2 additions & 0 deletions packages/utils/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { hasOnlyNumberAndEnglish } from './hasOnlyNumberAndEnglish';
export { hasOnlyNumberAndEnglishAndHangul } from './hasOnlyNumberAndEnglishAndHangul.ts';