@naturalcycles/js-lib
Advanced tools
Comparing version 8.0.1 to 8.1.0
@@ -0,1 +1,8 @@ | ||
# [8.1.0](https://github.com/NaturalCycles/js-lib/compare/v8.0.1...v8.1.0) (2019-07-16) | ||
### Features | ||
* _merge with multiple sources ([e109b4f](https://github.com/NaturalCycles/js-lib/commit/e109b4f)) | ||
## [8.0.1](https://github.com/NaturalCycles/js-lib/compare/v8.0.0...v8.0.1) (2019-07-16) | ||
@@ -2,0 +9,0 @@ |
@@ -116,3 +116,3 @@ /** | ||
* @param target The destination object. | ||
* @param source The source object. | ||
* @param sources The source objects. | ||
* @returns Returns `object`. | ||
@@ -134,15 +134,19 @@ * @example | ||
*/ | ||
export function _merge(target, source) { | ||
if (isObject(target) && isObject(source)) { | ||
Object.keys(source).forEach(key => { | ||
if (isObject(source[key])) { | ||
if (!target[key]) | ||
Object.assign(target, { [key]: {} }); | ||
_merge(target[key], source[key]); | ||
} | ||
else { | ||
Object.assign(target, { [key]: source[key] }); | ||
} | ||
}); | ||
} | ||
export function _merge(target, ...sources) { | ||
if (!isObject(target)) | ||
return target; | ||
sources.forEach(source => { | ||
if (isObject(source)) { | ||
Object.keys(source).forEach(key => { | ||
if (isObject(source[key])) { | ||
if (!target[key]) | ||
Object.assign(target, { [key]: {} }); | ||
_merge(target[key], source[key]); | ||
} | ||
else { | ||
Object.assign(target, { [key]: source[key] }); | ||
} | ||
}); | ||
} | ||
}); | ||
return target; | ||
@@ -149,0 +153,0 @@ } |
@@ -57,3 +57,3 @@ import { Except } from 'type-fest'; | ||
* @param target The destination object. | ||
* @param source The source object. | ||
* @param sources The source objects. | ||
* @returns Returns `object`. | ||
@@ -75,3 +75,3 @@ * @example | ||
*/ | ||
export declare function _merge<TARGET, SOURCE>(target: TARGET, source: SOURCE): TARGET & SOURCE; | ||
export declare function _merge<T>(target: T, ...sources: any[]): T; | ||
/** | ||
@@ -78,0 +78,0 @@ * Mutates |
@@ -132,3 +132,3 @@ "use strict"; | ||
* @param target The destination object. | ||
* @param source The source object. | ||
* @param sources The source objects. | ||
* @returns Returns `object`. | ||
@@ -150,15 +150,19 @@ * @example | ||
*/ | ||
function _merge(target, source) { | ||
if (isObject(target) && isObject(source)) { | ||
Object.keys(source).forEach(key => { | ||
if (isObject(source[key])) { | ||
if (!target[key]) | ||
Object.assign(target, { [key]: {} }); | ||
_merge(target[key], source[key]); | ||
} | ||
else { | ||
Object.assign(target, { [key]: source[key] }); | ||
} | ||
}); | ||
} | ||
function _merge(target, ...sources) { | ||
if (!isObject(target)) | ||
return target; | ||
sources.forEach(source => { | ||
if (isObject(source)) { | ||
Object.keys(source).forEach(key => { | ||
if (isObject(source[key])) { | ||
if (!target[key]) | ||
Object.assign(target, { [key]: {} }); | ||
_merge(target[key], source[key]); | ||
} | ||
else { | ||
Object.assign(target, { [key]: source[key] }); | ||
} | ||
}); | ||
} | ||
}); | ||
return target; | ||
@@ -165,0 +169,0 @@ } |
{ | ||
"name": "@naturalcycles/js-lib", | ||
"version": "8.0.1", | ||
"version": "8.1.0", | ||
"scripts": { | ||
@@ -5,0 +5,0 @@ "build": "del ./dist && tsc", |
@@ -160,3 +160,3 @@ import { Except } from 'type-fest' | ||
* @param target The destination object. | ||
* @param source The source object. | ||
* @param sources The source objects. | ||
* @returns Returns `object`. | ||
@@ -178,14 +178,19 @@ * @example | ||
*/ | ||
export function _merge<TARGET, SOURCE> (target: TARGET, source: SOURCE): TARGET & SOURCE { | ||
if (isObject(target) && isObject(source)) { | ||
Object.keys(source).forEach(key => { | ||
if (isObject(source[key])) { | ||
if (!target[key]) Object.assign(target, { [key]: {} }) | ||
_merge(target[key], source[key]) | ||
} else { | ||
Object.assign(target, { [key]: source[key] }) | ||
} | ||
}) | ||
} | ||
return target as TARGET & SOURCE | ||
export function _merge<T> (target: T, ...sources: any[]): T { | ||
if (!isObject(target)) return target | ||
sources.forEach(source => { | ||
if (isObject(source)) { | ||
Object.keys(source).forEach(key => { | ||
if (isObject(source[key])) { | ||
if (!target[key]) Object.assign(target, { [key]: {} }) | ||
_merge(target[key], source[key]) | ||
} else { | ||
Object.assign(target, { [key]: source[key] }) | ||
} | ||
}) | ||
} | ||
}) | ||
return target | ||
} | ||
@@ -192,0 +197,0 @@ |
Sorry, the diff of this file is not supported yet
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
212258
4110