Skip to content

Commit af356d7

Browse files
authored
Merge pull request #21 from klmhyeonwoo/feature/util-workspace
feat: add (isNull, checkDomain) util function
2 parents 98c80ad + c7098dc commit af356d7

7 files changed

Lines changed: 50 additions & 0 deletions

File tree

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,13 @@ 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
5354
const notEmpty = commonUtil.isEmpty("hello"); // false
55+
const nullCheck = commonUtil.isNull(null); // true
56+
const notNull = commonUtil.isNull("hello"); // false
5457

5558
// Cookie utilities
5659
cookieUtil.setCookie("theme", "dark");
@@ -78,10 +81,12 @@ const theme = cookieUtil.getCookie("theme");
7881

7982
- `checkEmail(email: string): boolean` - Validates email format
8083
- `checkHttpUrl(url: string): boolean` - Validates HTTP/HTTPS URL format
84+
- `checkDomain(domain: string): boolean` - Validates domain name format
8185

8286
### CommonUtil
8387

8488
- `isEmpty(value: unknown): boolean` - Checks if a value is empty (null, undefined, "", 0, [], {}, empty Set/Map, NaN, or invalid Date)
89+
- `isNull(value: unknown): value is null` - Type guard that checks if a value is null and narrows the type
8590

8691
### CookieUtil
8792

package/commonUtil/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export { default as isEmpty } from "./isEmpty";
2+
export { default as isNull } from "./isNull";
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { describe, expect, test } from "vitest";
2+
import isNull from ".";
3+
4+
describe("isNull 유틸 함수 테스트", () => {
5+
test("null이 들어오는 경우 true를 반환한다.", () => {
6+
expect(isNull(null)).toBe(true);
7+
});
8+
test("undefined이 들어오는 경우 false를 반환한다.", () => {
9+
expect(isNull(undefined)).toBe(false);
10+
});
11+
test("빈 문자열이 들어오는 경우 false를 반환한다.", () => {
12+
expect(isNull("")).toBe(false);
13+
});
14+
test("공백 문자열이 들어오는 경우 false를 반환한다.", () => {
15+
expect(isNull(" ")).toBe(false);
16+
});
17+
test("0이 들어오는 경우 false를 반환한다.", () => {
18+
expect(isNull(0)).toBe(false);
19+
});
20+
});

package/commonUtil/isNull/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function isNull(value: unknown): value is null {
2+
return value === null;
3+
}
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)