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 @@ -39,6 +39,7 @@ const unescaped = stringUtil.unescapeHtml("<div>Hello</div>");
// Object utilities
const cleaned = objectUtil.clearNullProperties({ a: 1, b: null, c: 3 });
const frozen = objectUtil.deepFreeze({ a: { b: 1 } });
const withoutKey = objectUtil.removeKey("b", { a: 1, b: 2, c: 3 }); // { a: 1, c: 3 }

// Number utilities
const total = numberUtil.sum(1, 2, 3, 4, 5); // 15
Expand Down Expand Up @@ -81,6 +82,7 @@ const theme = cookieUtil.getCookie("theme");

- `clearNullProperties(obj: object): object` - Removes null/undefined properties
- `deepFreeze(obj: object): object` - Deep freezes an object recursively
- `removeKey(key: string, obj: Record<string, any>): object` - Returns a new object with the specified key removed

### NumberUtil

Expand Down
5 changes: 3 additions & 2 deletions package/objectUtil/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { default as clearNullProperties } from './clearNullProperties';
export { default as deepFreeze } from './deepFreeze';
export { default as clearNullProperties } from "./clearNullProperties";
export { default as deepFreeze } from "./deepFreeze";
export { default as removeKey } from "./removeKey";
14 changes: 14 additions & 0 deletions package/objectUtil/removeKey/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { describe, expect, test } from "vitest";
import removeKey from ".";

describe("removeKey 유틸 함수 테스트", () => {
test("객체와 키를 입력했을 때, 정상적으로 객체에서 속성이 제거되어야한다.", () => {
expect(removeKey("b", { a: 1, b: 2, c: 3 })).toEqual({ a: 1, c: 3 });
});
test("객체와 키를 입력했을 때, 제거할 키가 객체에 없으면 원본 객체가 반환되어야한다.", () => {
expect(removeKey("d", { a: 1, b: 2, c: 3 })).toEqual({ a: 1, b: 2, c: 3 });
});
test("빈 객체와 키를 입력했을 때, 빈 객체가 반환되어야한다.", () => {
expect(removeKey("d", {})).toEqual({});
});
});
4 changes: 4 additions & 0 deletions package/objectUtil/removeKey/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export default function removeKey(key: string, obj: Record<string, any>) {
const { [key]: _, ...rest } = obj;
return rest;
}