Skip to content

Commit e6bb173

Browse files
committed
feat: add isNull util function (#16)
1 parent d03940d commit e6bb173

4 files changed

Lines changed: 27 additions & 0 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ const isHttpUrl = validationUtil.checkHttpUrl("https://example.com"); // true
5151
// Common utilities
5252
const empty = commonUtil.isEmpty(""); // true
5353
const notEmpty = commonUtil.isEmpty("hello"); // false
54+
const nullCheck = commonUtil.isNull(null); // true
55+
const notNull = commonUtil.isNull("hello"); // false
5456

5557
// Cookie utilities
5658
cookieUtil.setCookie("theme", "dark");
@@ -82,6 +84,7 @@ const theme = cookieUtil.getCookie("theme");
8284
### CommonUtil
8385

8486
- `isEmpty(value: unknown): boolean` - Checks if a value is empty (null, undefined, "", 0, [], {}, empty Set/Map, NaN, or invalid Date)
87+
- `isNull(value: unknown): value is null` - Type guard that checks if a value is null and narrows the type
8588

8689
### CookieUtil
8790

package/commonUtil/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export { default as isEmpty } from "./isEmpty";
2+
export { default as isNull } from "./isNull";
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { describe, expect, test } from "vitest";
2+
import isNull from ".";
3+
4+
describe("isNull 유틸 함수 테스트", () => {
5+
test("null이 들어오는 경우 true를 반환한다.", () => {
6+
expect(isNull(null)).toBe(true);
7+
});
8+
test("undefined이 들어오는 경우 false를 반환한다.", () => {
9+
expect(isNull(undefined)).toBe(false);
10+
});
11+
test("빈 문자열이 들어오는 경우 false를 반환한다.", () => {
12+
expect(isNull("")).toBe(false);
13+
});
14+
test("공백 문자열이 들어오는 경우 false를 반환한다.", () => {
15+
expect(isNull(" ")).toBe(false);
16+
});
17+
test("0이 들어오는 경우 false를 반환한다.", () => {
18+
expect(isNull(0)).toBe(false);
19+
});
20+
});

package/commonUtil/isNull/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function isNull(value: unknown): value is null {
2+
return value === null;
3+
}

0 commit comments

Comments
 (0)