|
@ -118,11 +118,16 @@ exports.assignAllKeys = function (obj, value) { |
|
|
* @param obj |
|
|
* @param obj |
|
|
* @param value |
|
|
* @param value |
|
|
*/ |
|
|
*/ |
|
|
exports.fillIfDefined = function (parentObj, newObj) { |
|
|
|
|
|
for (var prop in parentObj) { |
|
|
|
|
|
if (newObj[prop] !== undefined) { |
|
|
|
|
|
if (typeof newObj[prop] !== 'object') { |
|
|
|
|
|
parentObj[prop] = newObj[prop]; |
|
|
|
|
|
|
|
|
exports.fillIfDefined = function (a, b, allowDeletion = false) { |
|
|
|
|
|
for (var prop in a) { |
|
|
|
|
|
if (b[prop] !== undefined) { |
|
|
|
|
|
if (typeof b[prop] !== 'object') { |
|
|
|
|
|
if ((b[prop] === undefined || b[prop] === null) && a[prop] !== undefined && allowDeletion === true) { |
|
|
|
|
|
a[prop] = b[prop]; |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
a[prop] = b[prop]; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -169,7 +174,7 @@ exports.extend = function (a, b) { |
|
|
* Only properties with defined values are copied |
|
|
* Only properties with defined values are copied |
|
|
* @param {Array.<String>} props |
|
|
* @param {Array.<String>} props |
|
|
* @param {Object} a |
|
|
* @param {Object} a |
|
|
* @param {... Object} b |
|
|
|
|
|
|
|
|
* @param {Object} b |
|
|
* @return {Object} a |
|
|
* @return {Object} a |
|
|
*/ |
|
|
*/ |
|
|
exports.selectiveExtend = function (props, a, b) { |
|
|
exports.selectiveExtend = function (props, a, b) { |
|
@ -195,10 +200,10 @@ exports.selectiveExtend = function (props, a, b) { |
|
|
* Only properties with defined values are copied |
|
|
* Only properties with defined values are copied |
|
|
* @param {Array.<String>} props |
|
|
* @param {Array.<String>} props |
|
|
* @param {Object} a |
|
|
* @param {Object} a |
|
|
* @param {... Object} b |
|
|
|
|
|
|
|
|
* @param {Object} b |
|
|
* @return {Object} a |
|
|
* @return {Object} a |
|
|
*/ |
|
|
*/ |
|
|
exports.selectiveDeepExtend = function (props, a, b) { |
|
|
|
|
|
|
|
|
exports.selectiveDeepExtend = function (props, a, b, allowDeletion = false) { |
|
|
// TODO: add support for Arrays to deepExtend
|
|
|
// TODO: add support for Arrays to deepExtend
|
|
|
if (Array.isArray(b)) { |
|
|
if (Array.isArray(b)) { |
|
|
throw new TypeError('Arrays are not supported by deepExtend'); |
|
|
throw new TypeError('Arrays are not supported by deepExtend'); |
|
@ -216,7 +221,12 @@ exports.selectiveDeepExtend = function (props, a, b) { |
|
|
exports.deepExtend(a[prop], b[prop]); |
|
|
exports.deepExtend(a[prop], b[prop]); |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
a[prop] = b[prop]; |
|
|
|
|
|
|
|
|
if ((b[prop] === undefined || b[prop] === null) && a[prop] !== undefined && allowDeletion === true) { |
|
|
|
|
|
delete a[prop]; |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
a[prop] = b[prop]; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} else if (Array.isArray(b[prop])) { |
|
|
} else if (Array.isArray(b[prop])) { |
|
|
throw new TypeError('Arrays are not supported by deepExtend'); |
|
|
throw new TypeError('Arrays are not supported by deepExtend'); |
|
@ -235,10 +245,10 @@ exports.selectiveDeepExtend = function (props, a, b) { |
|
|
* Only properties with defined values are copied |
|
|
* Only properties with defined values are copied |
|
|
* @param {Array.<String>} props |
|
|
* @param {Array.<String>} props |
|
|
* @param {Object} a |
|
|
* @param {Object} a |
|
|
* @param {... Object} b |
|
|
|
|
|
|
|
|
* @param {Object} b |
|
|
* @return {Object} a |
|
|
* @return {Object} a |
|
|
*/ |
|
|
*/ |
|
|
exports.selectiveNotDeepExtend = function (props, a, b) { |
|
|
|
|
|
|
|
|
exports.selectiveNotDeepExtend = function (props, a, b, allowDeletion = false) { |
|
|
// TODO: add support for Arrays to deepExtend
|
|
|
// TODO: add support for Arrays to deepExtend
|
|
|
if (Array.isArray(b)) { |
|
|
if (Array.isArray(b)) { |
|
|
throw new TypeError('Arrays are not supported by deepExtend'); |
|
|
throw new TypeError('Arrays are not supported by deepExtend'); |
|
@ -254,7 +264,12 @@ exports.selectiveNotDeepExtend = function (props, a, b) { |
|
|
exports.deepExtend(a[prop], b[prop]); |
|
|
exports.deepExtend(a[prop], b[prop]); |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
a[prop] = b[prop]; |
|
|
|
|
|
|
|
|
if ((b[prop] === undefined || b[prop] === null) && a[prop] !== undefined && allowDeletion === true) { |
|
|
|
|
|
delete a[prop]; |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
a[prop] = b[prop]; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} else if (Array.isArray(b[prop])) { |
|
|
} else if (Array.isArray(b[prop])) { |
|
|
throw new TypeError('Arrays are not supported by deepExtend'); |
|
|
throw new TypeError('Arrays are not supported by deepExtend'); |
|
@ -273,9 +288,10 @@ exports.selectiveNotDeepExtend = function (props, a, b) { |
|
|
* @param {Object} b |
|
|
* @param {Object} b |
|
|
* @param [Boolean] protoExtend --> optional parameter. If true, the prototype values will also be extended. |
|
|
* @param [Boolean] protoExtend --> optional parameter. If true, the prototype values will also be extended. |
|
|
* (ie. the options objects that inherit from others will also get the inherited options) |
|
|
* (ie. the options objects that inherit from others will also get the inherited options) |
|
|
|
|
|
* @param [Boolean] global --> optional parameter. If true, the values of fields that are undefined or null will not deleted |
|
|
* @returns {Object} |
|
|
* @returns {Object} |
|
|
*/ |
|
|
*/ |
|
|
exports.deepExtend = function(a, b, protoExtend) { |
|
|
|
|
|
|
|
|
exports.deepExtend = function(a, b, protoExtend, allowDeletion) { |
|
|
for (var prop in b) { |
|
|
for (var prop in b) { |
|
|
if (b.hasOwnProperty(prop) || protoExtend === true) { |
|
|
if (b.hasOwnProperty(prop) || protoExtend === true) { |
|
|
if (b[prop] && b[prop].constructor === Object) { |
|
|
if (b[prop] && b[prop].constructor === Object) { |
|
@ -286,7 +302,12 @@ exports.deepExtend = function(a, b, protoExtend) { |
|
|
exports.deepExtend(a[prop], b[prop], protoExtend); |
|
|
exports.deepExtend(a[prop], b[prop], protoExtend); |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
a[prop] = b[prop]; |
|
|
|
|
|
|
|
|
if ((b[prop] === undefined || b[prop] === null) && a[prop] !== undefined && allowDeletion === true) { |
|
|
|
|
|
delete a[prop]; |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
a[prop] = b[prop]; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} else if (Array.isArray(b[prop])) { |
|
|
} else if (Array.isArray(b[prop])) { |
|
|
a[prop] = []; |
|
|
a[prop] = []; |
|
|