1
1
import { isEmpty } from './isEmpty' ;
2
2
3
3
// Type of object shape
4
- export type Obj = { [ key : string ] : any } ;
4
+ export type Object = { [ key : string ] : any } ;
5
5
// Type of ignored type
6
6
export type IgnoredTypes = null | undefined ;
7
7
// Util to extract type from <T> value
@@ -15,7 +15,7 @@ export type OxReturn<ObjectType> = RemoveIgnoredKey<ObjectType>;
15
15
16
16
const toStr = Object . prototype . toString ;
17
17
18
- function cleanObject < T extends Obj > ( obj : T , strict : boolean ) : OxReturn < T > {
18
+ function cleanObject < T extends Object > ( obj : T , strict : boolean ) : OxReturn < T > {
19
19
let k : string ;
20
20
for ( k in obj ) {
21
21
cleanProperty ( k , obj [ k ] , obj ) ;
@@ -29,7 +29,7 @@ function cleanObject<T extends Obj>(obj: T, strict: boolean): OxReturn<T> {
29
29
return null ;
30
30
}
31
31
32
- function cleanProperty ( key : string , value : any , ref : Obj ) {
32
+ function cleanProperty ( key : string , value : any , ref : Object ) {
33
33
if ( ! shouldCleanProperty ( value ) ) {
34
34
delete ref [ key ] ;
35
35
return ;
@@ -60,12 +60,18 @@ function cleanObject<T extends Obj>(obj: T, strict: boolean): OxReturn<T> {
60
60
export default function ox < T , U extends boolean > (
61
61
obj ?: T ,
62
62
strict ?: U
63
- ) : T extends Obj ? ( U extends false ? T : OxReturn < T > ) : T {
63
+ ) : T extends boolean
64
+ ? Object
65
+ : T extends Object
66
+ ? U extends false
67
+ ? T
68
+ : OxReturn < T >
69
+ : T {
64
70
if ( typeof strict === 'undefined' ) {
65
71
strict = true as U ;
66
72
}
67
73
if ( ! obj || typeof obj === 'boolean' ) return { } as any ;
68
- return cleanObject ( obj as Obj , strict as boolean ) ?? ( { } as any ) ;
74
+ return cleanObject ( obj as Object , strict as boolean ) ?? ( { } as any ) ;
69
75
}
70
76
71
77
export { isEmpty } ;
0 commit comments