@@ -18,14 +18,14 @@ function ParseNumber(v: number | string, isInt = false): number {
18
18
return (isInt ? parseInt(v) : parseFloat(v)) || 0;
19
19
}
20
20
21
- function FromArray<T>(Ctor: { new(v: any): T }, data?: any[] | any, def = null): T[] | null {
21
+ function FromArray<T>(Ctor: { new (v: any): T }, data?: any[] | any, def = null): T[] | null {
22
22
if (!data || !Object.keys(data).length) return def;
23
23
const d = Array.isArray(data) ? data : [data];
24
24
return d.map((v: any) => new Ctor(v));
25
25
}
26
26
27
27
function ToObject(o: any, typeOrCfg: any = {}, child = false): any {
28
- if (!o ) return null;
28
+ if (o == null ) return null;
29
29
if (typeof o.toObject === 'function' && child) return o.toObject();
30
30
31
31
switch (typeof o) {
@@ -46,7 +46,8 @@ function ToObject(o: any, typeOrCfg: any = {}, child = false): any {
46
46
47
47
for (const k of Object.keys(o)) {
48
48
const v: any = o[k];
49
- if (!v) continue;
49
+ if (v === undefined) continue;
50
+ if (v === null) continue;
50
51
d[k] = ToObject(v, typeOrCfg[k] || {}, true);
51
52
}
52
53
@@ -80,7 +81,7 @@ function FromArray(Ctor, data, def = null) {
80
81
return d.map((v) => new Ctor(v));
81
82
}
82
83
function ToObject(o, typeOrCfg = {}, child = false) {
83
- if (!o )
84
+ if (o == null )
84
85
return null;
85
86
if (typeof o.toObject === 'function' && child)
86
87
return o.toObject();
@@ -99,7 +100,9 @@ function ToObject(o, typeOrCfg = {}, child = false) {
99
100
const d = {};
100
101
for (const k of Object.keys(o)) {
101
102
const v = o[k];
102
- if (!v)
103
+ if (v === undefined)
104
+ continue;
105
+ if (v === null)
103
106
continue;
104
107
d[k] = ToObject(v, typeOrCfg[k] || {}, true);
105
108
}
0 commit comments