Skip to content

Commit fcdcb18

Browse files
authored
Merge pull request #27 from klmhyeonwoo/feature/util-workspace
feat: Add checkBase64 util function
2 parents 1775b56 + adfb5ab commit fcdcb18

4 files changed

Lines changed: 28 additions & 0 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ const product = numberUtil.multiply(2, 3, 4); // 24
4949
const isValid = validationUtil.checkEmail("user@example.com"); // true
5050
const isHttpUrl = validationUtil.checkHttpUrl("https://example.com"); // true
5151
const isDomain = validationUtil.checkDomain("example.com"); // true
52+
const isBase64 = validationUtil.checkBase64("U29tZSB2YWxpZCBiYXNlNjQgc3RyaW5n"); // true
5253

5354
// Common utilities
5455
const empty = commonUtil.isEmpty(""); // true
@@ -85,6 +86,7 @@ const theme = cookieUtil.getCookie("theme");
8586
- `checkEmail(email: string): boolean` - Validates email format
8687
- `checkHttpUrl(url: string): boolean` - Validates HTTP/HTTPS URL format
8788
- `checkDomain(domain: string): boolean` - Validates domain name format
89+
- `checkBase64(value: string): boolean` - Validates whether a string is a valid base64 encoded value
8890

8991
### CommonUtil
9092

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { describe, expect, it } from "vitest";
2+
import checkBase64 from ".";
3+
4+
describe("checkBase64 유틸 함수 테스트", () => {
5+
it("유효한 base64 문자열에 대해 true를 반환해야 합니다.", () => {
6+
expect(checkBase64("U29tZSB2YWxpZCBiYXNlNjQgc3RyaW5n")).toBe(true);
7+
expect(checkBase64("SGVsbG8gd29ybGQ=")).toBe(true);
8+
});
9+
10+
it("유효하지 않은 base64 문자열에 대해 false를 반환해야 합니다.", () => {
11+
expect(checkBase64("bfdbfdbsba")).toBe(false);
12+
expect(checkBase64("U29tZSB2YWxpZCBiYXNlNjQgc3RyaW5n===")).toBe(false);
13+
});
14+
15+
it("만약 빈 문자열로 함수를 호출할 경우 false를 반환해야 합니다.", () => {
16+
expect(checkBase64("")).toBe(false);
17+
expect(checkBase64(" ")).toBe(false);
18+
});
19+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export default function checkBase64(value: string): boolean {
2+
if (value.trim() === "") return false;
3+
const base64Regex =
4+
/^(?:[A-Z0-9+\/]{4})*(?:[A-Z0-9+\/]{2}==|[A-Z0-9+\/]{3}=)?$/i;
5+
return base64Regex.test(value);
6+
}

package/validationUtil/index.ts

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

0 commit comments

Comments
 (0)