GoScrobble/web/node_modules/@material-ui/utils/deepmerge.js

41 lines
1.1 KiB
JavaScript

"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.isPlainObject = isPlainObject;
exports.default = deepmerge;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
function isPlainObject(item) {
return item && (0, _typeof2.default)(item) === 'object' && item.constructor === Object;
}
function deepmerge(target, source) {
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
clone: true
};
var output = options.clone ? (0, _extends2.default)({}, target) : target;
if (isPlainObject(target) && isPlainObject(source)) {
Object.keys(source).forEach(function (key) {
// Avoid prototype pollution
if (key === '__proto__') {
return;
}
if (isPlainObject(source[key]) && key in target) {
output[key] = deepmerge(target[key], source[key], options);
} else {
output[key] = source[key];
}
});
}
return output;
}