UNPKG

wisdom-ui

Version:
1 lines 1.43 kB
function isObj(x) { let type = typeof x; return x !== null && (type === 'object' || type === 'function'); } let hasOwnProperty = Object.prototype.hasOwnProperty; let propIsEnumerable = Object.prototype.propertyIsEnumerable; function toObject(val) { if (val === null || val === undefined) throw new TypeError('Cannot convert undefined or null to object'); return Object(val); } function assignKey(to, from, key) { let val = from[key]; if (val === undefined || val === null) return; if (hasOwnProperty.call(to, key) && (to[key] === undefined || to[key] === null)) throw new TypeError('Cannot convert undefined or null to object (' + key + ')'); if (!hasOwnProperty.call(to, key) || !isObj(val)) to[key] = val; else to[key] = assign(Object(to[key]), from[key]); } function assign(to, from) { if (to === from) return to; from = Object(from); for (let key in from) if (hasOwnProperty.call(from, key)) assignKey(to, from, key); if (Object.getOwnPropertySymbols) { let symbols = Object.getOwnPropertySymbols(from); for (let i = 0; i < symbols.length; i++) if (propIsEnumerable.call(from, symbols[i])) assignKey(to, from, symbols[i]); } return to; } export function deepAssign(target) { target = toObject(target); for (let s = 1; s < arguments.length; s++) assign(target, arguments[s]); return target; } export default {deepAssign}