-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Added a new utility function typeUtil & fix: Fix bug in clearNullProperties utility function #47
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
feat: Added a new utility function typeUtil & fix: Fix bug in clearNullProperties utility function #47
Changes from all commits
Commits
Show all changes
5 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 80d80cf
Merge branch 'main' into bugfix/42
klmhyeonwoo e257573
Update package/typeUtil/index.ts
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 |
|---|---|---|
| @@ -1,7 +1,19 @@ | ||
| // 네임스페이스에 대한 익스포트 진행 | ||
| export * as stringUtil from "./stringUtil"; | ||
| export * as objectUtil from "./objectUtil"; | ||
| export * as cookieUtil from "./cookieUtil"; | ||
| export * as numberUtil from "./numberUtil"; | ||
| export * as validationUtil from "./validationUtil"; | ||
| export * as commonUtil from "./commonUtil"; | ||
| export * as searchQueryUtil from "./searchQueryUtil"; | ||
| export * as typeUtil from "./typeUtil"; | ||
|
|
||
| // 개별 함수에 대한 익스포트 진행 | ||
| export * from "./stringUtil"; | ||
| export * from "./objectUtil"; | ||
| export * from "./cookieUtil"; | ||
| export * from "./numberUtil"; | ||
| export * from "./validationUtil"; | ||
| export * from "./commonUtil"; | ||
| export * from "./searchQueryUtil"; | ||
| export * from "./typeUtil"; |
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 |
|---|---|---|
| @@ -1,11 +1,18 @@ | ||
| import isPlainObject from "../../typeUtil/isPlainObject"; | ||
|
|
||
| export default function clearNullProperties<T>(obj: T): T { | ||
| const result = { ...obj }; | ||
| Object.keys(result as Record<string, any>).forEach((el) => { | ||
| if (!(result as Record<string, any>)[el]) { | ||
| delete (result as Record<string, any>)[el]; | ||
| } else if (typeof (result as Record<string, any>)[el] === "object") { | ||
| (result as Record<string, any>)[el] = clearNullProperties((result as Record<string, any>)[el]); | ||
| } | ||
| }) | ||
| return result; | ||
| const result = { ...obj }; | ||
| Object.keys(result as Record<string, any>).forEach((el) => { | ||
| if ( | ||
| (result as Record<string, any>)[el] === null || | ||
| (result as Record<string, any>)[el] === undefined | ||
| ) { | ||
| delete (result as Record<string, any>)[el]; | ||
| } else if (isPlainObject((result as Record<string, any>)[el])) { | ||
| (result as Record<string, any>)[el] = clearNullProperties( | ||
| (result as Record<string, any>)[el] | ||
| ); | ||
| } | ||
| }); | ||
| return result; | ||
| } |
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 @@ | ||
| export { default as isPlainObject } from "./isPlainObject"; |
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,28 @@ | ||
| import { describe, expect, test } from "vitest"; | ||
| import isPlainObject from "."; | ||
|
|
||
| describe("isPlainObject 유틸 함수 테스트", () => { | ||
| test("일반 객체는 true를 반환한다", () => { | ||
| const obj = { a: 1, b: 2 }; | ||
| expect(isPlainObject(obj)).toBe(true); | ||
| }); | ||
|
|
||
| test("배열은 false를 반환한다", () => { | ||
| const arr = [1, 2, 3]; | ||
| expect(isPlainObject(arr)).toBe(false); | ||
| }); | ||
|
|
||
| test("null은 false를 반환한다", () => { | ||
| expect(isPlainObject(null)).toBe(false); | ||
| }); | ||
|
|
||
| test("날짜 객체는 false를 반환한다", () => { | ||
| const date = new Date(); | ||
| expect(isPlainObject(date)).toBe(false); | ||
| }); | ||
|
|
||
| test("커스텀 프로토타입을 가진 객체는 false를 반환한다", () => { | ||
| const obj = Object.create({ a: 1 }); | ||
| expect(isPlainObject(obj)).toBe(false); | ||
| }); | ||
| }); |
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,10 @@ | ||
| export default function isPlainObject(value: unknown): boolean { | ||
| if (typeof value !== "object" || value === null) { | ||
| return false; | ||
| } | ||
|
|
||
| return ( | ||
| Object.getPrototypeOf(value) === Object.prototype || | ||
| Object.getPrototypeOf(value) === null | ||
| ); | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오.. 이것도 객체를 의미하는 줄 몰랐습니다..!! 👍