devextreme
Version:
JavaScript/TypeScript Component Suite for Responsive Web Development
60 lines (59 loc) • 2.14 kB
JavaScript
/**
* DevExtreme (esm/__internal/core/utils/m_extend.js)
* Version: 26.1.6
* Build date: Fri Oct 16 2026
*
* Copyright (c) 2012 - 2026 Developer Express Inc. ALL RIGHTS RESERVED
* Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
*/
import {
isPlainObject
} from "../../../core/utils/type";
export const extendFromObject = function(target, source, overrideExistingValues) {
const result = target || {};
for (const prop in source) {
if (Object.prototype.hasOwnProperty.call(source, prop)) {
const value = source[prop];
if (!(prop in result) || overrideExistingValues) {
result[prop] = value
}
}
}
return result
};
export const extend = function extend() {
let target = (arguments.length <= 0 ? void 0 : arguments[0]) || {};
let i = 1;
let deep = false;
if ("boolean" === typeof target) {
deep = target;
target = (arguments.length <= 1 ? void 0 : arguments[1]) || {};
i += 1
}
for (; i < arguments.length; i += 1) {
const source = i < 0 || arguments.length <= i ? void 0 : arguments[i];
if (null == source) {
continue
}
for (const key in source) {
const targetValue = target[key];
const sourceValue = source[key];
let sourceValueIsArray = false;
let clone;
if ("__proto__" === key || "constructor" === key || target === sourceValue) {
continue
}
if (deep && sourceValue && (isPlainObject(sourceValue) || (sourceValueIsArray = Array.isArray(sourceValue)))) {
if (sourceValueIsArray) {
clone = targetValue && Array.isArray(targetValue) ? targetValue : []
} else {
clone = targetValue && isPlainObject(targetValue) ? targetValue : {}
}
target[key] = extend(deep, clone, sourceValue)
} else if (void 0 !== sourceValue) {
target[key] = sourceValue
}
}
}
return target
};