Skip to content

Commit c7098dc

Browse files
committed
feat: add checkDomain util function (#14)
1 parent e6bb173 commit c7098dc

4 files changed

Lines changed: 23 additions & 0 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ const difference = numberUtil.subtract(10, 3); // 7
4747
// Validation utilities
4848
const isValid = validationUtil.checkEmail("user@example.com"); // true
4949
const isHttpUrl = validationUtil.checkHttpUrl("https://example.com"); // true
50+
const isDomain = validationUtil.checkDomain("example.com"); // true
5051

5152
// Common utilities
5253
const empty = commonUtil.isEmpty(""); // true
@@ -80,6 +81,7 @@ const theme = cookieUtil.getCookie("theme");
8081

8182
- `checkEmail(email: string): boolean` - Validates email format
8283
- `checkHttpUrl(url: string): boolean` - Validates HTTP/HTTPS URL format
84+
- `checkDomain(domain: string): boolean` - Validates domain name format
8385

8486
### CommonUtil
8587

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { describe, expect, test } from "vitest";
2+
import checkDomain from ".";
3+
4+
describe("checkDomain 유틸 함수 테스트", () => {
5+
test("유효한 도메인이 들어오는 경우 true를 반환한다.", () => {
6+
expect(checkDomain("example.com")).toBe(true);
7+
expect(checkDomain("sub.example.co.uk")).toBe(true);
8+
expect(checkDomain("www.my-site123.org")).toBe(true);
9+
expect(checkDomain("www.layerapp.io")).toBe(true);
10+
});
11+
test("유효하지 않은 도메인이 들어오는 경우 false를 반환한다.", () => {
12+
expect(checkDomain("")).toBe(false);
13+
expect(checkDomain("invalid_domain")).toBe(false);
14+
expect(checkDomain("https://layerapp.io")).toBe(false);
15+
});
16+
});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export default function checkDomain(domain: string): boolean {
2+
const domainRegex = /^(?!:\/\/)([a-z0-9-]+\.)+[a-z]{2,}$/;
3+
return domainRegex.test(domain);
4+
}

package/validationUtil/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export { default as checkEmail } from "./checkEmail";
22
export { default as checkHttpUrl } from "./checkHttpUrl";
3+
export { default as checkDomain } from "./checkDomain";

0 commit comments

Comments
 (0)