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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const difference = numberUtil.subtract(10, 3); // 7
const isValid = validationUtil.checkEmail("user@example.com"); // true
const isHttpUrl = validationUtil.checkHttpUrl("https://example.com"); // true
const isDomain = validationUtil.checkDomain("example.com"); // true
const isBase64 = validationUtil.checkBase64("U29tZSB2YWxpZCBiYXNlNjQgc3RyaW5n"); // true

// Common utilities
const empty = commonUtil.isEmpty(""); // true
Expand Down Expand Up @@ -83,6 +84,7 @@ 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
- `checkBase64(value: string): boolean` - Validates whether a string is a valid base64 encoded value

### CommonUtil

Expand Down
19 changes: 19 additions & 0 deletions package/validationUtil/checkBase64/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { describe, expect, it } from "vitest";
import checkBase64 from ".";

describe("checkBase64 유틸 함수 테스트", () => {
it("유효한 base64 문자열에 대해 true를 반환해야 합니다.", () => {
expect(checkBase64("U29tZSB2YWxpZCBiYXNlNjQgc3RyaW5n")).toBe(true);
expect(checkBase64("SGVsbG8gd29ybGQ=")).toBe(true);
});

it("유효하지 않은 base64 문자열에 대해 false를 반환해야 합니다.", () => {
expect(checkBase64("bfdbfdbsba")).toBe(false);
expect(checkBase64("U29tZSB2YWxpZCBiYXNlNjQgc3RyaW5n===")).toBe(false);
});

it("만약 빈 문자열로 함수를 호출할 경우 false를 반환해야 합니다.", () => {
expect(checkBase64("")).toBe(false);
expect(checkBase64(" ")).toBe(false);
});
});
6 changes: 6 additions & 0 deletions package/validationUtil/checkBase64/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default function checkBase64(value: string): boolean {
if (value.trim() === "") return false;
const base64Regex =
/^(?:[A-Z0-9+\/]{4})*(?:[A-Z0-9+\/]{2}==|[A-Z0-9+\/]{3}=)?$/i;
return base64Regex.test(value);
}
1 change: 1 addition & 0 deletions package/validationUtil/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { default as checkEmail } from "./checkEmail";
export { default as checkHttpUrl } from "./checkHttpUrl";
export { default as checkDomain } from "./checkDomain";
export { default as checkBase64 } from "./checkBase64";