Skip to content
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
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,13 @@ const difference = numberUtil.subtract(10, 3); // 7
// Validation utilities
const isValid = validationUtil.checkEmail("user@example.com"); // true
const isHttpUrl = validationUtil.checkHttpUrl("https://example.com"); // true
const isDomain = validationUtil.checkDomain("example.com"); // true

// Common utilities
const empty = commonUtil.isEmpty(""); // true
const notEmpty = commonUtil.isEmpty("hello"); // false
const nullCheck = commonUtil.isNull(null); // true
const notNull = commonUtil.isNull("hello"); // false

// Cookie utilities
cookieUtil.setCookie("theme", "dark");
Expand Down Expand Up @@ -78,10 +81,12 @@ const theme = cookieUtil.getCookie("theme");

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

### CommonUtil

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

### CookieUtil

Expand Down
1 change: 1 addition & 0 deletions package/commonUtil/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { default as isEmpty } from "./isEmpty";
export { default as isNull } from "./isNull";
20 changes: 20 additions & 0 deletions package/commonUtil/isNull/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { describe, expect, test } from "vitest";
import isNull from ".";

describe("isNull 유틸 함수 테스트", () => {
test("null이 들어오는 경우 true를 반환한다.", () => {
expect(isNull(null)).toBe(true);
});
test("undefined이 들어오는 경우 false를 반환한다.", () => {
expect(isNull(undefined)).toBe(false);
});
test("빈 문자열이 들어오는 경우 false를 반환한다.", () => {
expect(isNull("")).toBe(false);
});
test("공백 문자열이 들어오는 경우 false를 반환한다.", () => {
expect(isNull(" ")).toBe(false);
});
test("0이 들어오는 경우 false를 반환한다.", () => {
expect(isNull(0)).toBe(false);
});
});
3 changes: 3 additions & 0 deletions package/commonUtil/isNull/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function isNull(value: unknown): value is null {
return value === null;
}
16 changes: 16 additions & 0 deletions package/validationUtil/checkDomain/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { describe, expect, test } from "vitest";
import checkDomain from ".";

describe("checkDomain 유틸 함수 테스트", () => {
test("유효한 도메인이 들어오는 경우 true를 반환한다.", () => {
expect(checkDomain("example.com")).toBe(true);
expect(checkDomain("sub.example.co.uk")).toBe(true);
expect(checkDomain("www.my-site123.org")).toBe(true);
expect(checkDomain("www.layerapp.io")).toBe(true);
});
test("유효하지 않은 도메인이 들어오는 경우 false를 반환한다.", () => {
expect(checkDomain("")).toBe(false);
expect(checkDomain("invalid_domain")).toBe(false);
expect(checkDomain("https://layerapp.io")).toBe(false);
});
});
4 changes: 4 additions & 0 deletions package/validationUtil/checkDomain/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export default function checkDomain(domain: string): boolean {
const domainRegex = /^(?!:\/\/)([a-z0-9-]+\.)+[a-z]{2,}$/;
return domainRegex.test(domain);
}
1 change: 1 addition & 0 deletions package/validationUtil/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { default as checkEmail } from "./checkEmail";
export { default as checkHttpUrl } from "./checkHttpUrl";
export { default as checkDomain } from "./checkDomain";