appolo-utils
Advanced tools
Comparing version 0.0.34 to 0.0.35
@@ -5,4 +5,18 @@ "use strict"; | ||
static isPlain(obj) { | ||
return Object.prototype.toString.call(obj) === '[object Object]'; | ||
if (!Objects.isObject(obj)) { | ||
return false; | ||
} | ||
let ctor = obj.constructor; | ||
if (typeof ctor !== 'function') { | ||
return false; | ||
} | ||
let proto = ctor.prototype; | ||
if (!Objects.isObject(proto) || !proto.hasOwnProperty('isPrototypeOf')) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
static isObject(val) { | ||
return val != null && typeof val === 'object' && Object.prototype.toString.call(val) === '[object Object]'; | ||
} | ||
static isEmpty(obj) { | ||
@@ -33,3 +47,5 @@ return Object.keys(obj).length === 0; | ||
let key = keys[i], value = obj[key]; | ||
output[key] = (value == null || typeof value != "object") ? value : Objects.cloneDeep(value); | ||
output[key] = (value !== null && value !== undefined && (Array.isArray(value) || Objects.isPlain(value))) | ||
? Objects.cloneDeep(value) | ||
: value; | ||
} | ||
@@ -36,0 +52,0 @@ return output; |
export class Objects { | ||
public static isPlain(obj: { [index: string]: string | number | boolean }): boolean { | ||
return Object.prototype.toString.call(obj) === '[object Object]'; | ||
public static isPlain(obj: any): boolean { | ||
if (!Objects.isObject(obj)) { | ||
return false; | ||
} | ||
let ctor = obj.constructor; | ||
if (typeof ctor !== 'function') { | ||
return false; | ||
} | ||
let proto = ctor.prototype; | ||
if (!Objects.isObject(proto) || !proto.hasOwnProperty('isPrototypeOf')) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
public static isObject(val: any): boolean { | ||
return val != null && typeof val === 'object' && Object.prototype.toString.call(val) === '[object Object]'; | ||
} | ||
public static isEmpty(obj: { [index: string]: any }): boolean { | ||
@@ -39,3 +59,5 @@ return Object.keys(obj).length === 0 | ||
let key = keys[i], value = obj[key]; | ||
output[key] = (value == null || typeof value != "object") ? value : Objects.cloneDeep(value) | ||
output[key] = (value !== null && value !== undefined && (Array.isArray(value) || Objects.isPlain(value))) | ||
? Objects.cloneDeep(value) | ||
: value | ||
} | ||
@@ -42,0 +64,0 @@ |
@@ -17,3 +17,3 @@ { | ||
"main": "./index.js", | ||
"version": "0.0.34", | ||
"version": "0.0.35", | ||
"license": "MIT", | ||
@@ -20,0 +20,0 @@ "repository": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
80114
1435