Comparing version 1.0.3 to 1.1.0
/*! | ||
* mergician | ||
* v1.0.3 | ||
* v1.1.0 | ||
* https://jhildenbiddle.github.io/mergician/ | ||
* (c) 2022 John Hildenbiddle | ||
* (c) 2022-2023 John Hildenbiddle | ||
* MIT license | ||
*/ | ||
var mergician=(()=>{var E=(r,s)=>()=>(s||r((s={exports:{}}).exports,s),s.exports);var I=E((_,w)=>{function m(...r){let s={};return r.forEach(e=>{e.forEach(u=>{s[u]=u in s?++s[u]:1})}),s}function C(...r){let s=m(...r);return Object.keys(s).filter(e=>s[e]>1)}function D(...r){return r.reduce((s,e)=>s.filter(Set.prototype.has,new Set(e)))}function F(...r){let s=m(...r);return Object.keys(s).filter(e=>s[e]===1)}function N(...r){let s=m(...r);return Object.keys(s).filter(e=>s[e]<r.length)}function P(r){return Boolean(r&&r.constructor.name==="Object")}w.exports={countOccurrences:m,getInMultiple:C,getInAll:D,getNotInMultiple:F,getNotInAll:N,isObject:P}});var B=E((z,O)=>{var{getInMultiple:S,getInAll:U,getNotInMultiple:x,getNotInAll:q,isObject:k}=I(),p={onlyKeys:[],skipKeys:[],onlyCommonKeys:!1,onlyUniversalKeys:!1,skipCommonKeys:!1,skipUniversalKeys:!1,appendArrays:!1,prependArrays:!1,dedupArrays:!1,sortArrays:!1,filter:Function.prototype,beforeEach:Function.prototype,afterEach:Function.prototype};function M(r){return k(r)?"get"in r&&typeof r.get=="function"||"set"in r&&typeof r.set=="function"||"value"in r&&("writable"in r||"enumerable"in r||"configurable"in r):!1}function V(...r){let s=arguments.length===1?arguments[0]:{},e={...p,...s},u=new Map,A=new Map,K=typeof e.sortArrays=="function"?e.sortArrays:void 0,d=0;function g(...a){let l;a.length>1&&(e.onlyCommonKeys?l=S(...a.map(t=>Object.keys(t))):e.onlyUniversalKeys?l=U(...a.map(t=>Object.keys(t))):e.skipCommonKeys?l=x(...a.map(t=>Object.keys(t))):e.skipUniversalKeys&&(l=q(...a.map(t=>Object.keys(t))))),!l&&e.onlyKeys.length&&(l=e.onlyKeys),l&&l!==e.onlyKeys&&e.onlyKeys.length&&(l=l.filter(t=>e.onlyKeys.includes(t)));let b=a.reduce((t,f)=>{let c=l||Object.keys(f);e.skipKeys.length&&(c=c.filter(h=>e.skipKeys.indexOf(h)===-1));for(let h=0;h<c.length;h++){let o=c[h];if(!(o in f))continue;let v=f[o],y=t[o],n=v;if(e.filter!==p.filter){let i=e.filter({depth:d,key:o,srcObj:f,srcVal:n,targetObj:t,targetVal:y});if(i!==void 0&&!i)continue}if(e.beforeEach!==p.beforeEach){let i=e.beforeEach({depth:d,key:o,srcObj:f,srcVal:n,targetObj:t,targetVal:y});n=i!==void 0?i:n}if(Array.isArray(n)){if(n=[...n],Array.isArray(y)&&(e.appendArrays?n=[...y,...n]:e.prependArrays&&(n=[...n,...y])),e.dedupArrays)if(e.afterEach!==p.afterEach)n=[...new Set(n)];else{let i=u.get(t);i&&!i.includes(o)?i.push(o):u.set(t,[o])}if(e.sortArrays)if(e.afterEach!==p.afterEach)n=n.sort(K);else{let i=A.get(t);i&&!i.includes(o)?i.push(o):A.set(t,[o])}}else k(n)&&!M(n)&&(d++,k(y)?n=g(y,n):n=g(n),d--);if(e.afterEach!==p.afterEach){let i=e.afterEach({depth:d,key:o,mergeVal:n,srcObj:f,targetObj:t});n=i!==void 0?i:n}if(M(n))n.configurable="configurable"in n?n.configurable:!0,n.enumerable="enumerable"in n?n.enumerable:!0,"value"in n&&!("writable"in n)&&(n.writable=!0),Object.defineProperty(t,o,n);else{let i=Object.getOwnPropertyDescriptor(f,o);"get"in i?Object.defineProperty(t,o,i):t[o]=n}}return t},{});for(let[t,f]of u.entries())for(let c of f)t[c]=[...new Set(t[c])];for(let[t,f]of A.entries())for(let c of f)t[c].sort(K);return b}return arguments.length===1?function(...a){return arguments.length===1?V({...e,...a[0]}):g(...a)}:g(...arguments)}O.exports=V});return B();})(); | ||
var mergician=(()=>{var V=(r,s)=>()=>(s||r((s={exports:{}}).exports,s),s.exports);var D=V((Q,S)=>{function M(...r){let s={};return r.forEach(e=>{e.forEach(l=>{s[l]=l in s?++s[l]:1})}),s}function U(...r){let s=M(...r);return Object.keys(s).filter(e=>s[e]>1)}function b(...r){return r.reduce((s,e)=>s.filter(Set.prototype.has,new Set(e)))}function x(...r){let s=M(...r);return Object.keys(s).filter(e=>s[e]===1)}function G(...r){let s=M(...r);return Object.keys(s).filter(e=>s[e]<r.length)}function R(r,s=!1){if(s){let e=[];for(let l in r)e.push(l);return e}else return Object.keys(r)}function P(r){return typeof r=="object"&&r!==null&&!Array.isArray(r)}function _(r){if(!P(r))return!1;let s=["writable","enumerable","configurable"].some(a=>a in r),e=["get","set"].some(a=>typeof r[a]=="function"),l=["get","set"].every(a=>a in r),h="value"in r&&s||e&&(l||s);if(h){let a=["configurable","get","set","enumerable","value","writable"];h=Object.keys(r).some(m=>!(m in a))}return h}S.exports={countOccurrences:M,getInMultiple:U,getInAll:b,getNotInMultiple:x,getNotInAll:G,getObjectKeys:R,isObject:P,isPropDescriptor:_}});var H=V((T,F)=>{var{getInMultiple:q,getInAll:L,getNotInMultiple:W,getNotInAll:z,getObjectKeys:B,isObject:I,isPropDescriptor:v}=D(),g={onlyKeys:[],skipKeys:[],onlyCommonKeys:!1,onlyUniversalKeys:!1,skipCommonKeys:!1,skipUniversalKeys:!1,invokeGetters:!1,skipSetters:!1,appendArrays:!1,prependArrays:!1,dedupArrays:!1,sortArrays:!1,hoistProto:!1,filter:Function.prototype,beforeEach:Function.prototype,afterEach:Function.prototype,onCircular:Function.prototype};function C(...r){let s=arguments.length===1?arguments[0]:{},e={...g,...s},l=new Map,h=new Map,a=typeof e.sortArrays=="function"?e.sortArrays:void 0,m=new WeakMap,d=0;function k(c){return B(c,e.hoistProto)}function w(...c){let u;c.length>1&&(e.onlyCommonKeys?u=q(...c.map(n=>k(n))):e.onlyUniversalKeys?u=L(...c.map(n=>k(n))):e.skipCommonKeys?u=W(...c.map(n=>k(n))):e.skipUniversalKeys&&(u=z(...c.map(n=>k(n))))),!u&&e.onlyKeys.length&&(u=e.onlyKeys),u&&u!==e.onlyKeys&&e.onlyKeys.length&&(u=u.filter(n=>e.onlyKeys.includes(n)));let N=c.reduce((n,f)=>{m.set(f,n);let y=u||k(f);e.skipKeys.length&&(y=y.filter(A=>e.skipKeys.indexOf(A)===-1));for(let A=0;A<y.length;A++){let o=y[A],p=n[o],K=!1,t;if(!(o in f))continue;try{t=f[o]}catch(i){console.error(i);continue}let E=Object.getOwnPropertyDescriptor(f,o);if(E&&typeof E.set=="function"&&typeof E.get!="function"){e.skipSetters||(E.configurable=!0,Object.defineProperty(n,o,E));continue}if(e.filter!==g.filter){let i=e.filter({depth:d,key:o,srcObj:f,srcVal:t,targetObj:n,targetVal:p});if(i!==void 0&&!i)continue}if(e.beforeEach!==g.beforeEach){let i=e.beforeEach({depth:d,key:o,srcObj:f,srcVal:t,targetObj:n,targetVal:p});i!==void 0&&(K=!0,t=i)}if(typeof t=="object"&&t!==null&&m.has(f[o])){let i=e.onCircular({depth:d,key:o,srcObj:f,srcVal:f[o],targetObj:n,targetVal:p});if(i===void 0){t=m.get(f[o]),n[o]=t;continue}K=!0,t=i}if(Array.isArray(t)){if(t=[...t],Array.isArray(p)&&(e.appendArrays?t=[...p,...t]:e.prependArrays&&(t=[...t,...p])),e.dedupArrays)if(e.afterEach!==g.afterEach)t=[...new Set(t)];else{let i=l.get(n);i&&!i.includes(o)?i.push(o):l.set(n,[o])}if(e.sortArrays)if(e.afterEach!==g.afterEach)t=t.sort(a);else{let i=h.get(n);i&&!i.includes(o)?i.push(o):h.set(n,[o])}}else I(t)&&(!K||!v(t))&&(d++,I(p)?t=w(p,t):t=w(t),d--);if(e.afterEach!==g.afterEach){let i=e.afterEach({depth:d,key:o,mergeVal:t,srcObj:f,targetObj:n});i!==void 0&&(K=!0,t=i)}if(K)v(t)?(t.configurable=!0,t.enumerable="enumerable"in t?t.enumerable:!0,"value"in t&&!("writable"in t)&&(t.writable=!0),Object.defineProperty(n,o,t)):n[o]=t;else{let i=Object.getOwnPropertyDescriptor(f,o);i&&typeof i.get=="function"&&!e.invokeGetters?(e.skipSetters&&(i.set=void 0),i.configurable=!0,Object.defineProperty(n,o,i)):n[o]=t}}return n},{});for(let[n,f]of l.entries())for(let y of f)n[y]=[...new Set(n[y])];for(let[n,f]of h.entries())for(let y of f)n[y].sort(a);return N}return arguments.length===1?function(...c){return arguments.length===1?C({...e,...c[0]}):w(...c)}:w(...arguments)}F.exports=C});return H();})(); | ||
//# sourceMappingURL=mergician.min.js.map |
{ | ||
"name": "mergician", | ||
"version": "1.0.3", | ||
"description": "Mergician is a uniquely flexible and light-weight utility for deep (recursive) merging/cloning of JavaScript objects. Includes options to filter, inspect, and modify properties as well as merge, sort, and remove duplicate items from arrays. Properly handles property accessors (getters/setters) and descriptors. Returns new object without modifying sources (immutable).", | ||
"version": "1.1.0", | ||
"description": "Uniquely flexible and light-weight utility for deep (recursive) merging/cloning of JavaScript objects. Provides advanced options for customizing the merge/clone process: inspect, filter, and modify keys and properties; merge or skip unique, common, and universal keys (i.e., intersections, unions, and differences); and merge, sort, and remove duplicates from arrays. Handles property accessors and descriptors, ensuring that getter/setter functions are retained and descriptor values are defined properly on new merged/cloned objects.", | ||
"author": "John Hildenbiddle", | ||
@@ -32,2 +32,5 @@ "license": "MIT", | ||
"sort", | ||
"intersection", | ||
"union", | ||
"difference", | ||
"get", | ||
@@ -76,10 +79,10 @@ "getter", | ||
"es-check": "^7.0.0", | ||
"esbuild": "^0.14.47", | ||
"esbuild": "^0.16.17", | ||
"eslint": "^8.18.0", | ||
"eslint-plugin-jest": "^26.5.3", | ||
"jest": "^28.1.1", | ||
"markdownlint-cli": "^0.32.1", | ||
"eslint-plugin-jest": "^27.2.1", | ||
"jest": "^29.4.3", | ||
"markdownlint-cli": "^0.33.0", | ||
"npm-run-all": "^4.1.5", | ||
"rimraf": "^3.0.2" | ||
"rimraf": "^4.1.2" | ||
} | ||
} |
# Mergician | ||
[](https://www.npmjs.com/package/mergician) | ||
[](https://github.com/jhildenbiddle/mergician/actions?query=branch%3Amain+) | ||
[](https://github.com/jhildenbiddle/mergician/actions?query=branch%3Amain+) | ||
[](https://app.codacy.com/gh/jhildenbiddle/mergician/dashboard?branch=main) | ||
[](https://github.com/jhildenbiddle/mergician/blob/main/LICENSE) | ||
[](https://www.jsdelivr.com/package/npm/mergician) | ||
[](https://twitter.com/intent/tweet?url=https%3A%2F%2Fgithub.com%2Fjhildenbiddle%2Fmergician&hashtags=developers,frontend,javascript) | ||
[](https://github.com/sponsors/jhildenbiddle) | ||
Mergician is a uniquely flexible and light-weight utility for deep (recursive) merging/cloning of JavaScript objects. | ||
Unlike native methods and other merge/clone utilities, Mergician provides advanced options for customizing the merge/clone process. These options make it easy to filter properties, inspect and modify properties before/after merging, merge and sort arrays, and remove duplicate array items. Property [accessors](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_accessors) and [descriptors](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor) are also handled properly, ensuring that getter/setter functions are retained and descriptor values are defined on the newly merged object. | ||
Unlike native methods and other merge/clone utilities, Mergician provides advanced options for customizing the merge/clone process. These options make it easy to inspect, filter, and modify keys and properties; merge or skip unique, common, and universal keys (i.e., intersections, unions, and differences); and merge, sort, and remove duplicates from arrays. Property [accessors](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_accessors) and [descriptors](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor) are also handled properly, ensuring that getter/setter functions are retained and descriptor values are defined on new merged/cloned objects. | ||
@@ -51,3 +51,2 @@ - [Documentation & Demos](https://jhildenbiddle.github.io/mergician/) | ||
targetObj['hello'] = 'world'; | ||
console.log(targetObj); | ||
return false; | ||
@@ -58,3 +57,3 @@ } | ||
// Results | ||
// Result | ||
console.log(mergedObj); // { a: [1, 2], b: { c: 2 }, hello: 'world' } | ||
@@ -65,9 +64,7 @@ ``` | ||
- Deep merge/clone JavaScript objects | ||
- Filter properties | ||
- Inspect and modify properties | ||
- Merge arrays | ||
- Sort arrays | ||
- Remove duplicate array items ("dedup") | ||
- Properly handle property [accessors](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_accessors) (getters/setters) and [descriptors](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor) | ||
- Deep merge or clone JavaScript objects | ||
- Inspect, filter, and modify keys and properties | ||
- Merge or skip unique, common, and universal keys (i.e., key unions and differences) | ||
- Merge, sort, and remove duplicates from arrays | ||
- Copy property [accessors](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_accessors) (getters/setters) and [descriptors](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor) | ||
- Returns new object without modifying source objects (immutable) | ||
@@ -117,3 +114,3 @@ - Lightweight (1.5k min+gzip) and dependency-free | ||
<!-- Global "mergician" @ latest v1.x.x (see @ version in URL) --> | ||
<script src="https://cdn.jsdelivr.net/npm/mergician@1/dist/mergician.min.js"> | ||
<script src="https://cdn.jsdelivr.net/npm/mergician@1/dist/mergician.min.js"></script> | ||
``` | ||
@@ -127,7 +124,16 @@ | ||
## Sponsorship | ||
A [sponsorship](https://github.com/sponsors/jhildenbiddle) is more than just a way to show appreciation for the open-source authors and projects we rely on; it can be the spark that ignites the next big idea, the inspiration to create something new, and the motivation to share so that others may benefit. | ||
If you benefit from this project, please consider lending your support and encouraging future efforts by [becoming a sponsor](https://github.com/sponsors/jhildenbiddle). | ||
Thank you! 🙏🏻 | ||
## Contact & Support | ||
- Create a [Github issue](https://github.com/jhildenbiddle/mergician/issues) for bug reports, feature requests, or questions | ||
- Follow [@jhildenbiddle](https://twitter.com/jhildenbiddle) for announcements | ||
- Add a ⭐️ [star on GitHub](https://github.com/jhildenbiddle/mergician) or 🐦 [tweet](https://twitter.com/intent/tweet?url=https%3A%2F%2Fgithub.com%2Fjhildenbiddle%2Fmergician&hashtags=developers,frontend,javascript) to spread the word and support the project! | ||
- Follow 👨🏻💻 **@jhildenbiddle** on [Twitter](https://twitter.com/jhildenbiddle) and [GitHub](https://github.com/jhildenbiddle) for announcements | ||
- Create a 💬 [GitHub issue](https://github.com/jhildenbiddle/mergician/issues) for bug reports, feature requests, or questions | ||
- Add a ⭐️ [star on GitHub](https://github.com/jhildenbiddle/mergician) and 🐦 [tweet](https://twitter.com/intent/tweet?url=https%3A%2F%2Fgithub.com%2Fjhildenbiddle%2Fmergician&hashtags=developers,frontend,javascript) to promote the project | ||
- Become a 💖 [sponsor](https://github.com/sponsors/jhildenbiddle) to support the project and future efforts | ||
@@ -134,0 +140,0 @@ ## License |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
119539
10
1296
140