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) • 787 B
JavaScript
var l={};function s(e){return T(e)}function T(e){return e instanceof Map}function u(e){return j(e)}function j(e){return e instanceof Set}function o(e){return!!e&&e.constructor===Object}function b(e){return Object.keys(e)}function M(e,y,...f){let i=l;for(let c of[e,y,...f]){if(!o(c))throw new TypeError("Expected all arguments to be object literals.");let r={...i},p=b(c);for(let a of p){let n=r[a],t=c[a];if(n!==t){if(o(n)&&o(t)){r[a]=M(n,t);continue}if(Array.isArray(n)&&Array.isArray(t)){r[a]=[...new Set([...n,...t])];continue}if(s(n)&&s(t)){r[a]=new Map([...n,...t]);continue}if(u(n)&&u(t)){r[a]=new Set([...n,...t]);continue}r[a]=t}}i=r}return i}export{l as initialValue,s as isMap,T as isMapInstance,o as isObjectLiteral,u as isSet,j as isSetInstance,M as merge,b as objectKeys};