File tree 1 file changed +12
-10
lines changed
1 file changed +12
-10
lines changed Original file line number Diff line number Diff line change @@ -40,16 +40,18 @@ export function isPlainObject(obj: any): obj is Record<string, any> {
40
40
return false ;
41
41
}
42
42
43
- export function definedKeys < TObject extends object > ( obj : TObject ) {
44
- // Remember that the second argument to Array.prototype.filter will be
45
- // used as `this` within the callback function.
46
- return Object . keys ( obj ) . filter ( isDefinedKey , obj ) ;
47
- }
48
- function isDefinedKey < TObject extends object > (
49
- this : TObject ,
50
- key : keyof TObject ,
51
- ) {
52
- return this [ key ] !== void 0 ;
43
+ export function definedKeys < TObject extends Record < string , any > > ( obj : TObject ) {
44
+ const keys = Object . keys ( obj ) ;
45
+ const { length } = keys ;
46
+ let definedCount = 0 ;
47
+ for ( let k = 0 ; k < length ; ++ k ) {
48
+ const key = keys [ k ] ;
49
+ if ( obj [ key ] !== void 0 ) {
50
+ keys [ definedCount ++ ] = key ;
51
+ }
52
+ }
53
+ keys . length = definedCount ;
54
+ return keys ;
53
55
}
54
56
55
57
const nativeCodeSuffix = "{ [native code] }" ;
You can’t perform that action at this time.
0 commit comments