amos-tool
Version:
amos ui tool
22 lines (20 loc) • 1.11 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"), _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof")), arrayToObject = require("./_tools").arrayToObject, has = Object.prototype.hasOwnProperty, _merge = function(e, r, t) {
if (!r) return e;
if ("object" !== (0, _typeof2.default)(r)) {
if (Array.isArray(e)) e.push(r); else {
if ("object" !== (0, _typeof2.default)(e)) return [ e, r ];
(t.plainObjects || t.allowPrototypes || !has.call(Object.prototype, r)) && (e[r] = !0);
}
return e;
}
if ("object" !== (0, _typeof2.default)(e)) return [ e ].concat(r);
var a = e;
return Array.isArray(e) && !Array.isArray(r) && (a = arrayToObject(e, t)), Array.isArray(e) && Array.isArray(r) ? (r.forEach(function(r, a) {
has.call(e, a) ? e[a] && "object" === (0, _typeof2.default)(e[a]) ? e[a] = _merge(e[a], r, t) : e.push(r) : e[a] = r;
}), e) : Object.keys(r).reduce(function(e, a) {
var o = r[a];
return has.call(e, a) ? e[a] = _merge(e[a], o, t) : e[a] = o, e;
}, a);
};
module.exports = _merge;