-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Added Base64 related utility functions #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
75d24f8
feat: Added a new utility function typeUtil
klmhyeonwoo 1bedee8
feat: Added individual package export method
klmhyeonwoo a8f9d0e
fix: Fix bug in clearNullProperties utility function
klmhyeonwoo 5bf699f
feat: Added Base64 related utility functions
klmhyeonwoo 7752508
Merge branch 'main' into feature/50
klmhyeonwoo 0d51bb0
fix: wrong test file name
klmhyeonwoo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import { describe, expect, test } from "vitest"; | ||
| import decodeBase64 from "."; | ||
|
|
||
| describe("decodeBase64 유틸 함수 테스트", () => { | ||
| test("정상적인 Base64 문자열을 디코딩해야 한다", () => { | ||
| const result = decodeBase64("SGVsbG8sJTIwV29ybGQh"); | ||
| expect(result).toBe("Hello, World!"); | ||
| }); | ||
| test("빈 문자열을 디코딩하면 빈 문자열을 반환해야 한다", () => { | ||
| const result = decodeBase64(""); | ||
| expect(result).toBe(""); | ||
| }); | ||
| test("특수 문자가 포함된 Base64 문자열을 올바르게 디코딩해야 한다", () => { | ||
| const result = decodeBase64( | ||
| "ISU0MCUyMyUyNCUyNSU1RSUyNiooKV8lMkIlMkYlM0IlMkMlM0YlM0ElNDAlMjY=" | ||
| ); | ||
| expect(result).toBe("!@#$%^&*()_+/;,?:@&"); | ||
| }); | ||
| test("유니코드 문자가 포함된 Base64 문자열을 올바르게 디코딩해야 한다", () => { | ||
| const result = decodeBase64( | ||
| "JUUzJTgxJTkzJUUzJTgyJTkzJUUzJTgxJUFCJUUzJTgxJUExJUUzJTgxJUFG" | ||
| ); | ||
| expect(result).toBe("こんにちは"); | ||
| }); | ||
| test("null 또는 undefined를 디코딩하면 그대로 반환해야 한다", () => { | ||
| // @ts-ignore | ||
| expect(decodeBase64(null)).toBe(null); | ||
| // @ts-ignore | ||
| expect(decodeBase64(undefined)).toBe(undefined); | ||
| }); | ||
| test("한글이 들어오면 올바르게 디코딩해야 한다", () => { | ||
| const result = decodeBase64( | ||
| "JUVDJTk1JTg4JUVCJTg1JTk1JUVEJTk1JTk4JUVDJTg0JUI4JUVDJTlBJTk0" | ||
| ); | ||
| expect(result).toBe("안녕하세요"); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| interface decodeBase64Options { | ||
| convertSpecialChars?: boolean; | ||
| } | ||
|
|
||
| export default function decodeBase64( | ||
| str: string, | ||
| { convertSpecialChars = true }: decodeBase64Options = {} | ||
| ): string { | ||
| if (str == null) return str; | ||
|
|
||
| if (convertSpecialChars) { | ||
| return decodeURIComponent(atob(str)); | ||
| } | ||
| return decodeURI(atob(str)); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import { describe, expect, test } from "vitest"; | ||
| import encodeBase64 from "."; | ||
|
|
||
| describe("encodeBase64 유틸 함수 테스트", () => { | ||
| test("정상적인 문자열을 Base64로 인코딩해야 한다", () => { | ||
| const result = encodeBase64("Hello, World!"); | ||
| expect(result).toBe("SGVsbG8lMkMlMjBXb3JsZCE="); | ||
| }); | ||
| test("빈 문자열을 인코딩하면 빈 문자열을 반환해야 한다", () => { | ||
| const result = encodeBase64(""); | ||
| expect(result).toBe(""); | ||
| }); | ||
| test("특수 문자가 포함된 문자열을 올바르게 인코딩해야 한다", () => { | ||
| const result = encodeBase64("!@#$%^&*()_+"); | ||
| expect(result).toBe("ISU0MCUyMyUyNCUyNSU1RSUyNiooKV8lMkI="); | ||
| }); | ||
| test("유니코드 문자가 포함된 문자열을 올바르게 인코딩해야 한다", () => { | ||
| const result = encodeBase64("こんにちは"); | ||
| expect(result).toBe( | ||
| "JUUzJTgxJTkzJUUzJTgyJTkzJUUzJTgxJUFCJUUzJTgxJUExJUUzJTgxJUFG" | ||
| ); | ||
| }); | ||
| test("null 또는 undefined를 인코딩하면 그대로 반환해야 한다", () => { | ||
| // @ts-ignore | ||
| expect(encodeBase64(null)).toBe(null); | ||
| // @ts-ignore | ||
| expect(encodeBase64(undefined)).toBe(undefined); | ||
| }); | ||
| test("한글이 들어오면 올바르게 인코딩해야 한다", () => { | ||
| const result = encodeBase64("안녕하세요"); | ||
| expect(result).toBe( | ||
| "JUVDJTk1JTg4JUVCJTg1JTk1JUVEJTk1JTk4JUVDJTg0JUI4JUVDJTlBJTk0" | ||
| ); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| interface encodeBase64Options { | ||
| convertSpecialChars?: boolean; | ||
| } | ||
|
|
||
| export default function encodeBase64( | ||
| str: string, | ||
| { convertSpecialChars = true }: encodeBase64Options = {} | ||
| ): string { | ||
| if (str == null) return str; | ||
|
|
||
| if (convertSpecialChars) { | ||
| return btoa(encodeURIComponent(str)); | ||
| } | ||
| return btoa(encodeURI(str)); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.