@@ -18,14 +18,14 @@ function ParseNumber(v: number | string, isInt = false): number {
1818 return (isInt ? parseInt(v) : parseFloat(v)) || 0;
1919}
2020
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 {
2222 if (!data || !Object.keys(data).length) return def;
2323 const d = Array.isArray(data) ? data : [data];
2424 return d.map((v: any) => new Ctor(v));
2525}
2626
2727function ToObject(o: any, typeOrCfg: any = {}, child = false): any {
28- if (!o ) return null;
28+ if (o == null ) return null;
2929 if (typeof o.toObject === 'function' && child) return o.toObject();
3030
3131 switch (typeof o) {
@@ -46,7 +46,8 @@ function ToObject(o: any, typeOrCfg: any = {}, child = false): any {
4646
4747 for (const k of Object.keys(o)) {
4848 const v: any = o[k];
49- if (!v) continue;
49+ if (v === undefined) continue;
50+ if (v === null) continue;
5051 d[k] = ToObject(v, typeOrCfg[k] || {}, true);
5152 }
5253
@@ -80,7 +81,7 @@ function FromArray(Ctor, data, def = null) {
8081 return d.map((v) => new Ctor(v));
8182}
8283function ToObject(o, typeOrCfg = {}, child = false) {
83- if (!o )
84+ if (o == null )
8485 return null;
8586 if (typeof o.toObject === 'function' && child)
8687 return o.toObject();
@@ -99,7 +100,9 @@ function ToObject(o, typeOrCfg = {}, child = false) {
99100 const d = {};
100101 for (const k of Object.keys(o)) {
101102 const v = o[k];
102- if (!v)
103+ if (v === undefined)
104+ continue;
105+ if (v === null)
103106 continue;
104107 d[k] = ToObject(v, typeOrCfg[k] || {}, true);
105108 }
0 commit comments