object-deep-merge
Version:
Strongly-typed deep and recursive object merging. Considers all nested levels of objects, arrays, sets and maps.
2 lines (1 loc) • 1.36 kB
JavaScript
;var y=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var k=Object.prototype.hasOwnProperty;var w=(e,t)=>{for(var c in t)y(e,c,{get:t[c],enumerable:!0})},x=(e,t,c,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of m(t))!k.call(e,r)&&r!==c&&y(e,r,{get:()=>t[r],enumerable:!(s=g(t,r))||s.enumerable});return e};var A=e=>x(y({},"__esModule",{value:!0}),e);var S={};w(S,{initialValue:()=>f,isMap:()=>l,isMapInstance:()=>T,isObjectLiteral:()=>u,isSet:()=>b,isSetInstance:()=>j,merge:()=>M,objectKeys:()=>p});module.exports=A(S);var f={};function l(e){return T(e)}function T(e){return e instanceof Map}function b(e){return j(e)}function j(e){return e instanceof Set}function u(e){return!!e&&e.constructor===Object}function p(e){return Object.keys(e)}function M(e,t,...c){let s=f;for(let r of[e,t,...c]){if(!u(r))throw new TypeError("Expected all arguments to be object literals.");let o={...s},O=p(r);for(let i of O){let a=o[i],n=r[i];if(a!==n){if(u(a)&&u(n)){o[i]=M(a,n);continue}if(Array.isArray(a)&&Array.isArray(n)){o[i]=[...new Set([...a,...n])];continue}if(l(a)&&l(n)){o[i]=new Map([...a,...n]);continue}if(b(a)&&b(n)){o[i]=new Set([...a,...n]);continue}o[i]=n}}s=o}return s}0&&(module.exports={initialValue,isMap,isMapInstance,isObjectLiteral,isSet,isSetInstance,merge,objectKeys});