@contrail/util
Advanced tools
Comparing version 1.0.9 to 1.0.10
export declare class ObjectUtil { | ||
static getByPath(obj: any, path: string, def?: any): any; | ||
static setByPath(obj: any, path: string, value: any): void; | ||
static isObject(item: any): boolean; | ||
static mergeDeep(target: any, ...sources: any[]): any; | ||
} |
@@ -31,3 +31,24 @@ "use strict"; | ||
} | ||
static isObject(item) { | ||
return (item && typeof item === 'object' && !Array.isArray(item)); | ||
} | ||
static mergeDeep(target, ...sources) { | ||
if (!sources.length) | ||
return target; | ||
const source = sources.shift(); | ||
if (this.isObject(target) && this.isObject(source)) { | ||
for (const key in source) { | ||
if (this.isObject(source[key])) { | ||
if (!target[key]) | ||
Object.assign(target, { [key]: {} }); | ||
this.mergeDeep(target[key], source[key]); | ||
} | ||
else { | ||
Object.assign(target, { [key]: source[key] }); | ||
} | ||
} | ||
} | ||
return this.mergeDeep(target, ...sources); | ||
} | ||
} | ||
exports.ObjectUtil = ObjectUtil; |
{ | ||
"name": "@contrail/util", | ||
"version": "1.0.9", | ||
"version": "1.0.10", | ||
"description": "General javascript utilities", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
8289
14
220