Skip to content

Commit 3a3c7bd

Browse files
committed
Optimize
1 parent 98b0056 commit 3a3c7bd

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

packages/util/src/obj.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,12 @@ export function isNonNullObject(obj: unknown): obj is object {
7777
}
7878

7979
export function isEmpty(obj: object): obj is {} {
80-
return Object.keys(obj).length === 0;
80+
for (const key in obj) {
81+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
82+
return false;
83+
}
84+
}
85+
return true;
8186
}
8287

8388
export function getCount(obj: object): number {
@@ -119,12 +124,12 @@ export function findValue<T extends object>(
119124
}
120125

121126
export function getAnyKey<T extends object>(obj: T): keyof T | undefined {
122-
const keys = Object.keys(obj);
123-
if (keys.length > 0) {
124-
return keys[0] as keyof T;
125-
} else {
126-
return undefined;
127+
for (const key in obj) {
128+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
129+
return key;
130+
}
127131
}
132+
return undefined;
128133
}
129134

130135
/**

0 commit comments

Comments
 (0)