@fluixi/utils 1.0.0-alpha.83 → 1.0.0-alpha.84
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +2858 -1
- package/dist/index.mjs +2838 -1
- package/dist/lib/array/advanced.cjs +2227 -1
- package/dist/lib/array/advanced.mjs +2204 -1
- package/dist/lib/array/array.cjs +57 -1
- package/dist/lib/array/array.mjs +36 -1
- package/dist/lib/array/index.cjs +2344 -1
- package/dist/lib/array/index.mjs +2322 -1
- package/dist/lib/array/utils.cjs +103 -1
- package/dist/lib/array/utils.mjs +82 -1
- package/dist/lib/color/color.cjs +2190 -1
- package/dist/lib/color/color.mjs +2167 -1
- package/dist/lib/color/constants.cjs +380 -1
- package/dist/lib/color/constants.mjs +359 -1
- package/dist/lib/color/conversions.cjs +629 -1
- package/dist/lib/color/conversions.mjs +608 -1
- package/dist/lib/color/helpers.cjs +2534 -1
- package/dist/lib/color/helpers.mjs +2511 -1
- package/dist/lib/color/index.cjs +2641 -1
- package/dist/lib/color/index.mjs +2619 -1
- package/dist/lib/color/types.cjs +18 -1
- package/dist/lib/color/utils.cjs +962 -1
- package/dist/lib/color/utils.mjs +939 -1
- package/dist/lib/compare/comparators.cjs +171 -1
- package/dist/lib/compare/comparators.mjs +150 -1
- package/dist/lib/compare/index.cjs +172 -1
- package/dist/lib/compare/index.mjs +152 -1
- package/dist/lib/crypto/hash.cjs +83 -1
- package/dist/lib/crypto/hash.mjs +62 -1
- package/dist/lib/crypto/index.cjs +85 -1
- package/dist/lib/crypto/index.mjs +62 -1
- package/dist/lib/dom/events.cjs +40 -1
- package/dist/lib/dom/events.mjs +19 -1
- package/dist/lib/dom/index.cjs +78 -1
- package/dist/lib/dom/index.mjs +56 -1
- package/dist/lib/dom/utils.cjs +57 -1
- package/dist/lib/dom/utils.mjs +36 -1
- package/dist/lib/functions/functions.cjs +366 -1
- package/dist/lib/functions/functions.mjs +345 -1
- package/dist/lib/functions/index.cjs +369 -1
- package/dist/lib/functions/index.mjs +347 -1
- package/dist/lib/functions/types.cjs +18 -1
- package/dist/lib/helpers.cjs +78 -1
- package/dist/lib/helpers.mjs +59 -1
- package/dist/lib/index.cjs +2857 -1
- package/dist/lib/index.mjs +2836 -1
- package/dist/lib/maths/constants.cjs +70 -1
- package/dist/lib/maths/constants.mjs +50 -1
- package/dist/lib/maths/fn/advanced.cjs +231 -1
- package/dist/lib/maths/fn/advanced.mjs +208 -1
- package/dist/lib/maths/fn/basic.cjs +212 -1
- package/dist/lib/maths/fn/basic.mjs +191 -1
- package/dist/lib/maths/fn/complex.cjs +268 -1
- package/dist/lib/maths/fn/complex.mjs +247 -1
- package/dist/lib/maths/fn/index.cjs +877 -1
- package/dist/lib/maths/fn/index.mjs +855 -1
- package/dist/lib/maths/fn/trigo.cjs +179 -1
- package/dist/lib/maths/fn/trigo.mjs +156 -1
- package/dist/lib/maths/fn/vector.cjs +728 -1
- package/dist/lib/maths/fn/vector.mjs +707 -1
- package/dist/lib/maths/formatter.cjs +61 -1
- package/dist/lib/maths/formatter.mjs +40 -1
- package/dist/lib/maths/guards.cjs +164 -1
- package/dist/lib/maths/guards.mjs +144 -1
- package/dist/lib/maths/index.cjs +1152 -1
- package/dist/lib/maths/index.mjs +1130 -1
- package/dist/lib/maths/parser.cjs +75 -1
- package/dist/lib/maths/parser.mjs +54 -1
- package/dist/lib/maths/random.cjs +49 -1
- package/dist/lib/maths/random.mjs +28 -1
- package/dist/lib/maths/types/advanced.cjs +18 -1
- package/dist/lib/maths/types/basic.cjs +18 -1
- package/dist/lib/maths/types/index.cjs +19 -1
- package/dist/lib/maths/types/index.mjs +1 -0
- package/dist/lib/maths/types/negative.cjs +18 -1
- package/dist/lib/maths/types/operations.cjs +18 -1
- package/dist/lib/object/clone.cjs +88 -1
- package/dist/lib/object/clone.mjs +65 -1
- package/dist/lib/object/diff.cjs +573 -1
- package/dist/lib/object/diff.mjs +550 -1
- package/dist/lib/object/getter-setter.cjs +2351 -1
- package/dist/lib/object/getter-setter.mjs +2330 -1
- package/dist/lib/object/index.cjs +3956 -6
- package/dist/lib/object/index.mjs +3936 -6
- package/dist/lib/object/merge.cjs +1029 -1
- package/dist/lib/object/merge.mjs +1006 -1
- package/dist/lib/object/object.cjs +280 -1
- package/dist/lib/object/object.mjs +257 -1
- package/dist/lib/object/omit.cjs +2022 -1
- package/dist/lib/object/omit.mjs +1999 -1
- package/dist/lib/object/reconcile.cjs +126 -1
- package/dist/lib/object/reconcile.mjs +105 -1
- package/dist/lib/object/selector.cjs +303 -1
- package/dist/lib/object/selector.mjs +282 -1
- package/dist/lib/object/sort.cjs +209 -1
- package/dist/lib/object/sort.mjs +186 -1
- package/dist/lib/object/transform.cjs +2211 -1
- package/dist/lib/object/transform.mjs +2190 -1
- package/dist/lib/object/types.cjs +18 -1
- package/dist/lib/object/utils.cjs +326 -6
- package/dist/lib/object/utils.mjs +305 -6
- package/dist/lib/primitive/boolean/boolean.cjs +407 -1
- package/dist/lib/primitive/boolean/boolean.mjs +386 -1
- package/dist/lib/primitive/boolean/index.cjs +382 -1
- package/dist/lib/primitive/boolean/index.mjs +359 -1
- package/dist/lib/primitive/boolean/types.cjs +18 -1
- package/dist/lib/primitive/date/date.cjs +1126 -1
- package/dist/lib/primitive/date/date.mjs +1105 -1
- package/dist/lib/primitive/date/index.cjs +1128 -1
- package/dist/lib/primitive/date/index.mjs +1105 -1
- package/dist/lib/primitive/date/types.cjs +18 -1
- package/dist/lib/primitive/index.cjs +2338 -5
- package/dist/lib/primitive/index.mjs +2316 -5
- package/dist/lib/primitive/string/index.cjs +875 -5
- package/dist/lib/primitive/string/index.mjs +852 -5
- package/dist/lib/primitive/string/parser-2.cjs +543 -8
- package/dist/lib/primitive/string/parser-2.mjs +522 -8
- package/dist/lib/primitive/string/parser.cjs +236 -3
- package/dist/lib/primitive/string/parser.mjs +215 -3
- package/dist/lib/primitive/string/string.cjs +926 -5
- package/dist/lib/primitive/string/string.mjs +903 -5
- package/dist/lib/primitive/string/types.cjs +18 -1
- package/dist/lib/primitive/types.cjs +18 -1
- package/dist/lib/url/index.cjs +327 -1
- package/dist/lib/url/index.mjs +304 -1
- package/dist/lib/url/parser.cjs +325 -1
- package/dist/lib/url/parser.mjs +304 -1
- package/dist/lib/url/types.cjs +18 -1
- package/package.json +5 -5
|
@@ -1 +1,1029 @@
|
|
|
1
|
-
"use strict";var E=Object.defineProperty;var F=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var W=Object.prototype.hasOwnProperty;var q=(e,r)=>{for(var i in r)E(e,i,{get:r[i],enumerable:!0})},U=(e,r,i,f)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of N(r))!W.call(e,t)&&t!==i&&E(e,t,{get:()=>r[t],enumerable:!(f=F(r,t))||f.enumerable});return e};var L=e=>U(E({},"__esModule",{value:!0}),e);var G={};q(G,{deepMerge:()=>K,deepMergeKeepReference:()=>K,deepMergeStrict:()=>Q,deepMergeWithOptions:()=>R,merge:()=>D,mergeArrays:()=>B,mergeIntoStructure:()=>Z,mergeStrict:()=>Q,mergeWithOptions:()=>R});module.exports=L(G);var b=e=>e==null||Array.isArray(e)||typeof e=="function"||e instanceof Date||e instanceof RegExp||e instanceof Map||e instanceof Set||e instanceof Error?!1:typeof e=="object";function $(e){if(typeof e!="object"||e===null)return!1;let r=Object.getPrototypeOf(e);return r===Object.prototype||r===null}var w=(e,r)=>{if(e==null||typeof e!="object")return e;if(e instanceof Date)return new Date(e.getTime());if(e instanceof RegExp)return new RegExp(e.source,e.flags);if(e instanceof Map){let i=new Map;return e.forEach((f,t)=>{(!r||!r.some(s=>s.toString()===t.toString()))&&i.set(t,w(f))}),i}if(e instanceof Set){let i=new Set;return e.forEach(f=>{i.add(w(f))}),i}if(Array.isArray(e))return Array.from(e).map(i=>w(i));if(b(e)){let i={};for(let t in e)Object.prototype.hasOwnProperty.call(e,t)&&(!r||!r.some(s=>s.toString()===t.toString()))&&(i[t]=w(e[t]));let f=Object.getOwnPropertySymbols(e);for(let t of f)(!r||!r.some(s=>s.toString()===t.toString()))&&(i[t]=w(e[t]));return i}return e};var P=(e,r)=>e===r,O=(e,r)=>{if(e.length!==r.length)return!1;for(let i=0;i<e.length;i++)if(Array.isArray(e[i])&&Array.isArray(r[i])){if(!O(e[i],r[i]))return!1}else if(b(e[i])&&b(r[i])){if(!j(e[i],r[i]))return!1}else if(e[i]!==r[i])return!1;return!0},j=(e,r)=>{let i=Object.keys(e),f=Object.keys(r);if(i.length!==f.length)return!1;for(let t of i){if(!(t in r))return!1;let s=e[t],d=r[t];if(Array.isArray(s)&&Array.isArray(d)){if(!O(s,d))return!1}else if(b(s)&&b(d)){if(!j(s,d))return!1}else if(s!==d)return!1}return!0},M=(e,r,i={})=>{let{includeDeleted:f=!1,includeAdded:t=!0,deepArrayComparison:s=!0,equalityFn:d=P,preserveStructure:m=!1}=i;if(e==null&&r==null)return{};if(e==null)return t?{...r}:{};if(r==null){if(f){let c={};for(let A in e)c[A]=void 0;return c}return{}}if(!b(e)||!b(r))return d(e,r)?{}:r;let u={},l=new Set;for(let c in r){l.add(c);let A=e[c],S=r[c];if(!(c in e)){t&&(u[c]=S);continue}if(Array.isArray(A)&&Array.isArray(S)){s?O(A,S)?m&&(u[c]=void 0):u[c]=S:A!==S?u[c]=S:m&&(u[c]=void 0);continue}if(b(A)&&b(S)){let h=M(A,S,i);Object.keys(h).length>0?u[c]=h:m&&(u[c]=void 0);continue}d(A,S)?m&&(u[c]=void 0):u[c]=S}if(f)for(let c in e)l.has(c)||(u[c]=void 0);return u},C=(e,r,i={})=>{let f=[],t=[],s=[],d={},{includeDeleted:m=!1,includeAdded:u=!0,deepArrayComparison:l=!0,equalityFn:c=P}=i;if(Array.isArray(e)&&Array.isArray(r)){let h=Math.max(e.length,r.length),o=[],a=!1;for(let n=0;n<h;n++){let y=`[${n}]`;if(n>=e.length)f.push(y),o[n]=r[n],a=!0;else if(n>=r.length)t.push(y),a=!0;else{let p=e[n],g=r[n];b(p)&&b(g)||Array.isArray(p)&&Array.isArray(g)?C(p,g,i).hasChanges?(s.push(y),o[n]=g,a=!0):o[n]=p:c(p,g)?o[n]=p:(s.push(y),o[n]=g,a=!0)}}return{changes:a?o:{},added:f,deleted:t,modified:s,hasChanges:a||t.length>0}}let A=(h,o,a="")=>{let n={added:[],deleted:[],modified:[]};if(Array.isArray(h)&&Array.isArray(o)){let y=Math.max(h.length,o.length);for(let p=0;p<y;p++){let g=a?`${a}[${p}]`:`[${p}]`;if(p>=h.length)n.added.push(g);else if(p>=o.length)n.deleted.push(g);else{let T=h[p],x=o[p];if(b(T)&&b(x)){let k=A(T,x,g);n.added.push(...k.added),n.deleted.push(...k.deleted),n.modified.push(...k.modified)}else if(Array.isArray(T)&&Array.isArray(x)){let k=A(T,x,g);n.added.push(...k.added),n.deleted.push(...k.deleted),n.modified.push(...k.modified)}else T!==x&&n.modified.push(g)}}return n}if(b(h)&&b(o)){let y=new Set([...Object.keys(h||{}),...Object.keys(o||{})]);for(let p of y){let g=h?.[p],T=o?.[p],x=a?`${a}.${p}`:p;if(!(p in(h||{})))n.added.push(x);else if(!(p in(o||{})))n.deleted.push(x);else if(Array.isArray(g)&&Array.isArray(T)){if(!O(g,T)){let k=A(g,T,x);n.added.push(...k.added),n.deleted.push(...k.deleted),n.modified.push(...k.modified)}}else if(b(g)&&b(T)){let k=A(g,T,x);n.added.push(...k.added),n.deleted.push(...k.deleted),n.modified.push(...k.modified)}else g!==T&&n.modified.push(x)}}return n};if(e==null&&r==null)return{changes:{},added:f,deleted:t,modified:s,hasChanges:!1};if(e==null){if(u&&r)for(let h in r)f.push(h),d[h]=r[h];return{changes:d,added:f,deleted:t,modified:s,hasChanges:f.length>0}}if(r==null){if(m)for(let h in e)t.push(h),d[h]=void 0;return{changes:d,added:f,deleted:t,modified:s,hasChanges:t.length>0}}let S=new Set;for(let h in r){S.add(h);let o=e[h],a=r[h];if(!(h in e)){u&&(f.push(h),d[h]=a);continue}let n=!1;if(Array.isArray(o)&&Array.isArray(a)){if(n=l?!O(o,a):o!==a,n){let y=A(o,a,h);f.push(...y.added),t.push(...y.deleted),s.push(...y.modified),d[h]=a}}else if(b(o)&&b(a)){let y=M(o,a,i);if(n=Object.keys(y).length>0,n){let p=A(o,a,h);f.push(...p.added),t.push(...p.deleted),s.push(...p.modified),d[h]=y}}else n=!c(o,a),n&&(s.push(h),d[h]=a)}for(let h in e)S.has(h)||(t.push(h),d[h]=void 0);return{changes:d,added:f,deleted:t,modified:s,hasChanges:f.length>0||t.length>0||s.length>0}};function _(e){return!!(e&&(e.diff||e.changes)&&(e.modified||e.deleted||e.hasChanges))}var v=(e,r,i)=>{if(!_(r)){let n=r,y=i||!1;if(Array.isArray(e)&&Array.isArray(n)){let g=y?e:[...e];n.length<g.length&&(g.length=n.length);for(let T=0;T<n.length;T++){let x=n[T];x!==void 0&&(b(g[T])&&b(x)||Array.isArray(g[T])&&Array.isArray(x)?g[T]=v(g[T],x,y):g[T]=x)}return g}if(!b(e))return n;if(!b(n))return e;let p=y?e:{...e};for(let g in n){let T=n[g];T===void 0?delete p[g]:Array.isArray(p[g])&&Array.isArray(T)||b(p[g])&&b(T)?p[g]=v(p[g],T,y):p[g]=T}return p}let{diff:f,added:t=[],deleted:s=[],modified:d=[],changes:m,keepRef:u}=r,l=i!==void 0?i:u,c=m||f;if(!c)return e;let A=new Set(t),S=new Set(s),h=new Set(d),o=n=>{if(t.length===0&&s.length===0&&d.length===0)return!0;let y=n.split(/[.\[\]]+/).filter(Boolean);for(let p=0;p<=y.length;p++){let g=y.slice(0,p).join("."),T=y.slice(0,p).map((x,k)=>/^\d+$/.test(x)?`[${x}]`:k>0?`.${x}`:x).join("");if(A.has(g)||A.has(T)||S.has(g)||S.has(T)||h.has(g)||h.has(T))return!0}return!1};if(Array.isArray(e)&&Array.isArray(c)){let n=l?e:[...e];n.length=c.length;for(let y=0;y<c.length;y++){let p=`[${y}]`,g=c[y];g!==void 0&&o(p)&&(b(n[y])&&b(g)||Array.isArray(n[y])&&Array.isArray(g)?n[y]=v(n[y],g,l):n[y]=g)}return n}if(!b(e))return c;if(!b(c))return e;let a=l?e:{...e};for(let n of s)n.includes(".")||n.includes("[")||o(n)&&delete a[n];for(let n in c){let y=c[n];o(n)&&(y===void 0?delete a[n]:Array.isArray(a[n])&&Array.isArray(y)||b(a[n])&&b(y)?a[n]=v(a[n],y,l):a[n]=y)}return a};var I=(e,r={})=>{let{type:i="auto",throwOnError:f=!1}=r;if(!e||typeof e!="string")return[];let t=[],s="",d=!1,m=!1,u="",l="",c=0,S=i==="auto"?(o=>o.includes("..")?"descendant":o.includes("[?(")?"filter":o.includes("[:")||o.includes("[0:")?"slice":o.includes("[,")||o.includes("[0,1]")?"union":o.includes("[*]")||o.includes(".*.")?"wildcard":o.includes("[]")?"array-wildcard":o.includes("[")&&o.includes("]")?"bracket":"dot")(e):i,h=o=>{let a=o.trim();if(a==="*"||a==="")return{type:"wildcard",value:a===""?"[]":"*",raw:a===""?"[]":o};if(a==="[]")return{type:"wildcard",value:"[]",raw:o};if(/^-?\d+$/.test(a))return{type:"index",value:parseInt(a,10),raw:o};if(a.includes(":")){let n=a.split(":").map(g=>g.trim()),y=n[0]===""?0:parseInt(n[0],10),p=n[1]===""?1/0:parseInt(n[1],10);if(isNaN(y)||isNaN(p)){if(f)throw new Error(`Invalid slice notation: ${o}`);return{type:"wildcard",value:"*",raw:o}}return{type:"slice",value:[y,p],raw:o}}if(a.includes(",")){let n=a.split(",").map(y=>{let p=parseInt(y.trim(),10);return isNaN(p)?-1:p}).filter(y=>y>=0);if(n.length===0){if(f)throw new Error(`Invalid union notation: ${o}`);return{type:"wildcard",value:"*",raw:o}}return{type:"union",value:n,raw:o}}if(a.startsWith("?(")&&a.endsWith(")")){let n=a.slice(2,-1);try{return{type:"filter",value:z(n),raw:o}}catch(y){if(f)throw y;return{type:"wildcard",value:"*",raw:o}}}return a.startsWith('"')&&a.endsWith('"')||a.startsWith("'")&&a.endsWith("'")?{type:"property",value:a.slice(1,-1),raw:o}:{type:"property",value:a,raw:o}};for(let o=0;o<e.length;o++){let a=e[o],n=e[o+1];if((a==='"'||a==="'")&&!m){m=!0,u=a;continue}else if(a===u&&m){m=!1,u="",a==='"'||a==="'"||(d?l+=a:s+=a);continue}if(m){d?l+=a:s+=a;continue}if(a==="["&&!d){s&&(t.push({type:"property",value:s,raw:s}),s=""),d=!0,l="";continue}if(a==="]"&&d&&!m){d=!1;let p=h(l);t.push(p);continue}let y=t.length>0?t[t.length-1]:null;if(a==="."&&!d&&!m){if(n==="."){let p=e.split("..")[0];t.push({type:"property",value:p,raw:p}),t.push({type:"descendant",value:"..",raw:".."}),o++}else s&&(s==="*"?t.push({type:"wildcard",value:s,raw:s}):t.push({type:"property",value:s,raw:s}),s="");continue}if(d)l+=a;else if(y&&y.type!=="descendant")s+=a;else{let p=e.split(y?.raw)[1];p!==void 0?s=p:s+=a}}return s&&t.push({type:"property",value:s,raw:s}),t.map(o=>{if(o.type==="property"&&typeof o.value=="string"&&/^-?\d+$/.test(o.value)){let a=parseInt(o.value,10);if(!isNaN(a))return{...o,type:"index",value:a}}return o})},z=e=>{let r=e.replace(/@\.([a-zA-Z_$][\w$]*)/g,(i,f)=>`item.${f}`).replace(/@/g,"item");try{return new Function("item",`return ${r}`)}catch{throw new Error(`Invalid filter expression: ${e}`)}};function D(...e){if(e.length===0)return{};let r=e[0],i=Array.isArray(r);for(let t of e)if(t&&Array.isArray(t)!==i)throw new Error("Cannot mix arrays and objects in deepMerge");let f=i?[]:{};for(let t of e)if(t!=null)if(i){let s=f,d=t;for(let m of d)s.push(w(m))}else{if(!$(t))continue;let s=f,d=t;for(let u in d)if(Object.prototype.hasOwnProperty.call(d,u)){let l=d[u],c=s[u];c===void 0?s[u]=w(l):Array.isArray(l)&&Array.isArray(c)?s[u]=[...c,...l.map(A=>w(A))]:$(l)&&$(c)?s[u]=D(c,l):s[u]=w(l)}let m=Object.getOwnPropertySymbols(d);for(let u of m){let l=d[u],c=s[u];c===void 0?s[u]=w(l):Array.isArray(l)&&Array.isArray(c)?s[u]=[...c,...l.map(A=>w(A))]:$(l)&&$(c)?s[u]=D(c,l):s[u]=w(l)}}return f}function B(e,r,i){let{key:f,override:t=!0}=i||{};if(!f)return Array.from(new Set([...e,...r]));let s=new Map;for(let d of e)s.set(d[f],d);for(let d of r){let m=s.get(d[f]);m?s.set(d[f],t?{...m,...d}:{...d,...m}):s.set(d[f],d)}return Array.from(s.values())}function J(e,r){for(let i in r){let f=e[i],t=r[i],s=C(f,t);Array.isArray(f)&&Array.isArray(t)?(f.length=0,f.push(...t)):typeof f=="object"&&typeof t=="object"&&f&&t&&s.hasChanges?v(f,t):e[i]=t}}function R(e,...r){if(r.length===0)return w(e);let i={preserveTarget:!1,strict:!1},f=r,t=r[r.length-1];t&&typeof t=="object"&&("preserveTarget"in t||"strict"in t)&&(i={...i,...t},f=r.slice(0,-1));let s=i.preserveTarget?e:w(e),d=Array.isArray(s);for(let m of f)if(m&&Array.isArray(m)!==d)throw new Error("Cannot mix arrays and objects in deepMergeWithOptions");for(let m of f)if(m!=null)if(d){let u=s,l=m;if(i.strict)for(let c=0;c<u.length&&c<l.length;c++)$(u[c])&&$(l[c])?u[c]=R(u[c],l[c],i):typeof u[c]==typeof l[c]&&(u[c]=w(l[c]));else J(u,l)}else{if(!$(m))continue;let u=s,l=m;for(let A in l){if(!Object.prototype.hasOwnProperty.call(l,A))continue;let S=l[A];if(i.strict&&!(A in u))continue;let h=u[A];h===void 0?u[A]=w(S):Array.isArray(S)&&Array.isArray(h)?i.strict?u[A]=R(h,S,i):u[A]=[...h,...S.map(o=>w(o))]:$(S)&&$(h)?u[A]=R(h,S,i):u[A]=w(S)}let c=Object.getOwnPropertySymbols(l);for(let A of c){if(i.strict&&!(A in u))continue;let S=l[A],h=u[A];h===void 0?u[A]=w(S):Array.isArray(S)&&Array.isArray(h)?i.strict?u[A]=R(h,S,i):u[A]=[...h,...S.map(o=>w(o))]:$(S)&&$(h)?u[A]=R(h,S,i):u[A]=w(S)}}return s}function K(e,...r){return R(e,...r,{preserveTarget:!0})}function Q(e,...r){let i=!1,f=r;return r.length>0&&typeof r[r.length-1]=="boolean"&&(i=r[r.length-1],f=r.slice(0,-1)),R(e,...f,{preserveTarget:i,strict:!0})}var Z=(e,r,i)=>{let f=I(r),t=e;for(let s=0;s<f.length;s++){let d=f[s],m=s===f.length-1;switch(d.type){case"property":if(m)t[String(d.value)]=i;else{if(!t[String(d.value)]){let l=f[s+1];t[String(d.value)]=l.type==="index"||l.type==="slice"||l.type==="union"||l.type==="wildcard"?[]:{}}t=t[String(d.value)]}break;case"index":Array.isArray(t)||(t=[]);let u=d.value;if(m){if(u>=t.length)for(let l=t.length;l<=u;l++)t.push(void 0);t[u]=i}else{if(!t[u]){let l=f[s+1];t[u]=l.type==="index"||l.type==="slice"||l.type==="union"||l.type==="wildcard"?[]:{}}t=t[u]}break;case"wildcard":if(Array.isArray(t))if(m)for(let l=0;l<t.length;l++)t[l]=i;else{let l=f[s+1];for(let c=0;c<t.length;c++)t[c]||(t[c]=l.type==="index"||l.type==="slice"||l.type==="union"||l.type==="wildcard"?[]:{});t.length>0&&(t=t[0])}break}}};
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/lib/object/merge.ts
|
|
21
|
+
var merge_exports = {};
|
|
22
|
+
__export(merge_exports, {
|
|
23
|
+
deepMerge: () => deepMergeKeepReference,
|
|
24
|
+
deepMergeKeepReference: () => deepMergeKeepReference,
|
|
25
|
+
deepMergeStrict: () => deepMergeStrict,
|
|
26
|
+
deepMergeWithOptions: () => deepMergeWithOptions,
|
|
27
|
+
merge: () => merge,
|
|
28
|
+
mergeArrays: () => mergeArrays,
|
|
29
|
+
mergeIntoStructure: () => mergeIntoStructure,
|
|
30
|
+
mergeStrict: () => deepMergeStrict,
|
|
31
|
+
mergeWithOptions: () => deepMergeWithOptions
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(merge_exports);
|
|
34
|
+
|
|
35
|
+
// src/lib/object/utils.ts
|
|
36
|
+
var isObject = (value) => {
|
|
37
|
+
if (value == null) return false;
|
|
38
|
+
if (Array.isArray(value)) return false;
|
|
39
|
+
if (typeof value === "function") return false;
|
|
40
|
+
if (value instanceof Date) return false;
|
|
41
|
+
if (value instanceof RegExp) return false;
|
|
42
|
+
if (value instanceof Map) return false;
|
|
43
|
+
if (value instanceof Set) return false;
|
|
44
|
+
if (value instanceof Error) return false;
|
|
45
|
+
return typeof value === "object";
|
|
46
|
+
};
|
|
47
|
+
function isPlainObject(v) {
|
|
48
|
+
if (typeof v !== "object" || v === null) return false;
|
|
49
|
+
const proto = Object.getPrototypeOf(v);
|
|
50
|
+
return proto === Object.prototype || proto === null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// src/lib/object/clone.ts
|
|
54
|
+
var deepClone = (obj, skipKeys) => {
|
|
55
|
+
if (obj == null || typeof obj !== "object") {
|
|
56
|
+
return obj;
|
|
57
|
+
}
|
|
58
|
+
if (obj instanceof Date) {
|
|
59
|
+
return new Date(obj.getTime());
|
|
60
|
+
}
|
|
61
|
+
if (obj instanceof RegExp) {
|
|
62
|
+
return new RegExp(obj.source, obj.flags);
|
|
63
|
+
}
|
|
64
|
+
if (obj instanceof Map) {
|
|
65
|
+
const clone = /* @__PURE__ */ new Map();
|
|
66
|
+
obj.forEach((value, key) => {
|
|
67
|
+
if (!skipKeys || !skipKeys.some((k) => k.toString() === key.toString())) {
|
|
68
|
+
clone.set(key, deepClone(value));
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
return clone;
|
|
72
|
+
}
|
|
73
|
+
if (obj instanceof Set) {
|
|
74
|
+
const clone = /* @__PURE__ */ new Set();
|
|
75
|
+
obj.forEach((value) => {
|
|
76
|
+
clone.add(deepClone(value));
|
|
77
|
+
});
|
|
78
|
+
return clone;
|
|
79
|
+
}
|
|
80
|
+
if (Array.isArray(obj)) {
|
|
81
|
+
return Array.from(obj).map((item) => deepClone(item));
|
|
82
|
+
}
|
|
83
|
+
if (isObject(obj)) {
|
|
84
|
+
const clone = {};
|
|
85
|
+
for (const key in obj) {
|
|
86
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
87
|
+
if (!skipKeys || !skipKeys.some((k) => k.toString() === key.toString())) {
|
|
88
|
+
clone[key] = deepClone(obj[key]);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
const symbols = Object.getOwnPropertySymbols(obj);
|
|
93
|
+
for (const symbol of symbols) {
|
|
94
|
+
if (!skipKeys || !skipKeys.some((s) => s.toString() === symbol.toString())) {
|
|
95
|
+
clone[symbol] = deepClone(obj[symbol]);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return clone;
|
|
99
|
+
}
|
|
100
|
+
return obj;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
// src/lib/object/diff.ts
|
|
104
|
+
var defaultEqualityFn = (a, b) => a === b;
|
|
105
|
+
var deepArrayEqual = (arr1, arr2) => {
|
|
106
|
+
if (arr1.length !== arr2.length) return false;
|
|
107
|
+
for (let i = 0; i < arr1.length; i++) {
|
|
108
|
+
if (Array.isArray(arr1[i]) && Array.isArray(arr2[i])) {
|
|
109
|
+
if (!deepArrayEqual(arr1[i], arr2[i])) return false;
|
|
110
|
+
} else if (isObject(arr1[i]) && isObject(arr2[i])) {
|
|
111
|
+
if (!deepObjectEqual(arr1[i], arr2[i])) return false;
|
|
112
|
+
} else if (arr1[i] !== arr2[i]) {
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return true;
|
|
117
|
+
};
|
|
118
|
+
var deepObjectEqual = (obj1, obj2) => {
|
|
119
|
+
const keys1 = Object.keys(obj1);
|
|
120
|
+
const keys2 = Object.keys(obj2);
|
|
121
|
+
if (keys1.length !== keys2.length) return false;
|
|
122
|
+
for (const key of keys1) {
|
|
123
|
+
if (!(key in obj2)) return false;
|
|
124
|
+
const val1 = obj1[key];
|
|
125
|
+
const val2 = obj2[key];
|
|
126
|
+
if (Array.isArray(val1) && Array.isArray(val2)) {
|
|
127
|
+
if (!deepArrayEqual(val1, val2)) return false;
|
|
128
|
+
} else if (isObject(val1) && isObject(val2)) {
|
|
129
|
+
if (!deepObjectEqual(val1, val2)) return false;
|
|
130
|
+
} else if (val1 !== val2) {
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return true;
|
|
135
|
+
};
|
|
136
|
+
var diffObject = (oldObj, newObj, options = {}) => {
|
|
137
|
+
const {
|
|
138
|
+
includeDeleted = false,
|
|
139
|
+
includeAdded = true,
|
|
140
|
+
deepArrayComparison = true,
|
|
141
|
+
equalityFn = defaultEqualityFn,
|
|
142
|
+
preserveStructure = false
|
|
143
|
+
} = options;
|
|
144
|
+
if (oldObj == null && newObj == null) {
|
|
145
|
+
return {};
|
|
146
|
+
}
|
|
147
|
+
if (oldObj == null) {
|
|
148
|
+
return includeAdded ? { ...newObj } : {};
|
|
149
|
+
}
|
|
150
|
+
if (newObj == null) {
|
|
151
|
+
if (includeDeleted) {
|
|
152
|
+
const result2 = {};
|
|
153
|
+
for (const key in oldObj) {
|
|
154
|
+
result2[key] = void 0;
|
|
155
|
+
}
|
|
156
|
+
return result2;
|
|
157
|
+
}
|
|
158
|
+
return {};
|
|
159
|
+
}
|
|
160
|
+
if (!isObject(oldObj) || !isObject(newObj)) {
|
|
161
|
+
return equalityFn(oldObj, newObj) ? {} : newObj;
|
|
162
|
+
}
|
|
163
|
+
const result = {};
|
|
164
|
+
const processedKeys = /* @__PURE__ */ new Set();
|
|
165
|
+
for (const key in newObj) {
|
|
166
|
+
processedKeys.add(key);
|
|
167
|
+
const oldValue = oldObj[key];
|
|
168
|
+
const newValue = newObj[key];
|
|
169
|
+
if (!(key in oldObj)) {
|
|
170
|
+
if (includeAdded) {
|
|
171
|
+
result[key] = newValue;
|
|
172
|
+
}
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
if (Array.isArray(oldValue) && Array.isArray(newValue)) {
|
|
176
|
+
if (deepArrayComparison) {
|
|
177
|
+
if (!deepArrayEqual(oldValue, newValue)) {
|
|
178
|
+
result[key] = newValue;
|
|
179
|
+
} else if (preserveStructure) {
|
|
180
|
+
result[key] = void 0;
|
|
181
|
+
}
|
|
182
|
+
} else {
|
|
183
|
+
if (oldValue !== newValue) {
|
|
184
|
+
result[key] = newValue;
|
|
185
|
+
} else if (preserveStructure) {
|
|
186
|
+
result[key] = void 0;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
if (isObject(oldValue) && isObject(newValue)) {
|
|
192
|
+
const nestedDiff = diffObject(oldValue, newValue, options);
|
|
193
|
+
if (Object.keys(nestedDiff).length > 0) {
|
|
194
|
+
result[key] = nestedDiff;
|
|
195
|
+
} else if (preserveStructure) {
|
|
196
|
+
result[key] = void 0;
|
|
197
|
+
}
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
if (!equalityFn(oldValue, newValue)) {
|
|
201
|
+
result[key] = newValue;
|
|
202
|
+
} else if (preserveStructure) {
|
|
203
|
+
result[key] = void 0;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
if (includeDeleted) {
|
|
207
|
+
for (const key in oldObj) {
|
|
208
|
+
if (!processedKeys.has(key)) {
|
|
209
|
+
result[key] = void 0;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
return result;
|
|
214
|
+
};
|
|
215
|
+
var diffObjectDetailed = (oldObj, newObj, options = {}) => {
|
|
216
|
+
const added = [];
|
|
217
|
+
const deleted = [];
|
|
218
|
+
const modified = [];
|
|
219
|
+
const changes = {};
|
|
220
|
+
const {
|
|
221
|
+
includeDeleted = false,
|
|
222
|
+
includeAdded = true,
|
|
223
|
+
deepArrayComparison = true,
|
|
224
|
+
equalityFn = defaultEqualityFn
|
|
225
|
+
} = options;
|
|
226
|
+
if (Array.isArray(oldObj) && Array.isArray(newObj)) {
|
|
227
|
+
const maxLength = Math.max(oldObj.length, newObj.length);
|
|
228
|
+
const arrayChanges = [];
|
|
229
|
+
let hasArrayChanges = false;
|
|
230
|
+
for (let i = 0; i < maxLength; i++) {
|
|
231
|
+
const indexPath = `[${i}]`;
|
|
232
|
+
if (i >= oldObj.length) {
|
|
233
|
+
added.push(indexPath);
|
|
234
|
+
arrayChanges[i] = newObj[i];
|
|
235
|
+
hasArrayChanges = true;
|
|
236
|
+
} else if (i >= newObj.length) {
|
|
237
|
+
deleted.push(indexPath);
|
|
238
|
+
hasArrayChanges = true;
|
|
239
|
+
} else {
|
|
240
|
+
const oldElement = oldObj[i];
|
|
241
|
+
const newElement = newObj[i];
|
|
242
|
+
if (isObject(oldElement) && isObject(newElement)) {
|
|
243
|
+
const nestedDiff = diffObjectDetailed(
|
|
244
|
+
oldElement,
|
|
245
|
+
newElement,
|
|
246
|
+
options
|
|
247
|
+
);
|
|
248
|
+
if (nestedDiff.hasChanges) {
|
|
249
|
+
modified.push(indexPath);
|
|
250
|
+
arrayChanges[i] = newElement;
|
|
251
|
+
hasArrayChanges = true;
|
|
252
|
+
} else {
|
|
253
|
+
arrayChanges[i] = oldElement;
|
|
254
|
+
}
|
|
255
|
+
} else if (Array.isArray(oldElement) && Array.isArray(newElement)) {
|
|
256
|
+
const nestedDiff = diffObjectDetailed(
|
|
257
|
+
oldElement,
|
|
258
|
+
newElement,
|
|
259
|
+
options
|
|
260
|
+
);
|
|
261
|
+
if (nestedDiff.hasChanges) {
|
|
262
|
+
modified.push(indexPath);
|
|
263
|
+
arrayChanges[i] = newElement;
|
|
264
|
+
hasArrayChanges = true;
|
|
265
|
+
} else {
|
|
266
|
+
arrayChanges[i] = oldElement;
|
|
267
|
+
}
|
|
268
|
+
} else if (!equalityFn(oldElement, newElement)) {
|
|
269
|
+
modified.push(indexPath);
|
|
270
|
+
arrayChanges[i] = newElement;
|
|
271
|
+
hasArrayChanges = true;
|
|
272
|
+
} else {
|
|
273
|
+
arrayChanges[i] = oldElement;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return {
|
|
278
|
+
changes: hasArrayChanges ? arrayChanges : {},
|
|
279
|
+
added,
|
|
280
|
+
deleted,
|
|
281
|
+
modified,
|
|
282
|
+
hasChanges: hasArrayChanges || deleted.length > 0
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
const collectDetailedPaths = (old, newVal, currentPath = "") => {
|
|
286
|
+
const result = {
|
|
287
|
+
added: [],
|
|
288
|
+
deleted: [],
|
|
289
|
+
modified: []
|
|
290
|
+
};
|
|
291
|
+
if (Array.isArray(old) && Array.isArray(newVal)) {
|
|
292
|
+
const maxLength = Math.max(old.length, newVal.length);
|
|
293
|
+
for (let i = 0; i < maxLength; i++) {
|
|
294
|
+
const indexPath = currentPath ? `${currentPath}[${i}]` : `[${i}]`;
|
|
295
|
+
if (i >= old.length) {
|
|
296
|
+
result.added.push(indexPath);
|
|
297
|
+
} else if (i >= newVal.length) {
|
|
298
|
+
result.deleted.push(indexPath);
|
|
299
|
+
} else {
|
|
300
|
+
const oldElement = old[i];
|
|
301
|
+
const newElement = newVal[i];
|
|
302
|
+
if (isObject(oldElement) && isObject(newElement)) {
|
|
303
|
+
const nested = collectDetailedPaths(
|
|
304
|
+
oldElement,
|
|
305
|
+
newElement,
|
|
306
|
+
indexPath
|
|
307
|
+
);
|
|
308
|
+
result.added.push(...nested.added);
|
|
309
|
+
result.deleted.push(...nested.deleted);
|
|
310
|
+
result.modified.push(...nested.modified);
|
|
311
|
+
} else if (Array.isArray(oldElement) && Array.isArray(newElement)) {
|
|
312
|
+
const nested = collectDetailedPaths(
|
|
313
|
+
oldElement,
|
|
314
|
+
newElement,
|
|
315
|
+
indexPath
|
|
316
|
+
);
|
|
317
|
+
result.added.push(...nested.added);
|
|
318
|
+
result.deleted.push(...nested.deleted);
|
|
319
|
+
result.modified.push(...nested.modified);
|
|
320
|
+
} else if (oldElement !== newElement) {
|
|
321
|
+
result.modified.push(indexPath);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
return result;
|
|
326
|
+
}
|
|
327
|
+
if (isObject(old) && isObject(newVal)) {
|
|
328
|
+
const allKeys = /* @__PURE__ */ new Set([
|
|
329
|
+
...Object.keys(old || {}),
|
|
330
|
+
...Object.keys(newVal || {})
|
|
331
|
+
]);
|
|
332
|
+
for (const key of allKeys) {
|
|
333
|
+
const oldValue = old?.[key];
|
|
334
|
+
const newValue = newVal?.[key];
|
|
335
|
+
const path = currentPath ? `${currentPath}.${key}` : key;
|
|
336
|
+
if (!(key in (old || {}))) {
|
|
337
|
+
result.added.push(path);
|
|
338
|
+
} else if (!(key in (newVal || {}))) {
|
|
339
|
+
result.deleted.push(path);
|
|
340
|
+
} else if (Array.isArray(oldValue) && Array.isArray(newValue)) {
|
|
341
|
+
if (!deepArrayEqual(oldValue, newValue)) {
|
|
342
|
+
const nested = collectDetailedPaths(oldValue, newValue, path);
|
|
343
|
+
result.added.push(...nested.added);
|
|
344
|
+
result.deleted.push(...nested.deleted);
|
|
345
|
+
result.modified.push(...nested.modified);
|
|
346
|
+
}
|
|
347
|
+
} else if (isObject(oldValue) && isObject(newValue)) {
|
|
348
|
+
const nested = collectDetailedPaths(oldValue, newValue, path);
|
|
349
|
+
result.added.push(...nested.added);
|
|
350
|
+
result.deleted.push(...nested.deleted);
|
|
351
|
+
result.modified.push(...nested.modified);
|
|
352
|
+
} else if (oldValue !== newValue) {
|
|
353
|
+
result.modified.push(path);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
return result;
|
|
358
|
+
};
|
|
359
|
+
if (oldObj == null && newObj == null) {
|
|
360
|
+
return { changes: {}, added, deleted, modified, hasChanges: false };
|
|
361
|
+
}
|
|
362
|
+
if (oldObj == null) {
|
|
363
|
+
if (includeAdded && newObj) {
|
|
364
|
+
for (const key in newObj) {
|
|
365
|
+
added.push(key);
|
|
366
|
+
changes[key] = newObj[key];
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
return {
|
|
370
|
+
changes,
|
|
371
|
+
added,
|
|
372
|
+
deleted,
|
|
373
|
+
modified,
|
|
374
|
+
hasChanges: added.length > 0
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
if (newObj == null) {
|
|
378
|
+
if (includeDeleted) {
|
|
379
|
+
for (const key in oldObj) {
|
|
380
|
+
deleted.push(key);
|
|
381
|
+
changes[key] = void 0;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
return {
|
|
385
|
+
changes,
|
|
386
|
+
added,
|
|
387
|
+
deleted,
|
|
388
|
+
modified,
|
|
389
|
+
hasChanges: deleted.length > 0
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
const processedKeys = /* @__PURE__ */ new Set();
|
|
393
|
+
for (const key in newObj) {
|
|
394
|
+
processedKeys.add(key);
|
|
395
|
+
const oldValue = oldObj[key];
|
|
396
|
+
const newValue = newObj[key];
|
|
397
|
+
if (!(key in oldObj)) {
|
|
398
|
+
if (includeAdded) {
|
|
399
|
+
added.push(key);
|
|
400
|
+
changes[key] = newValue;
|
|
401
|
+
}
|
|
402
|
+
continue;
|
|
403
|
+
}
|
|
404
|
+
let isDifferent = false;
|
|
405
|
+
if (Array.isArray(oldValue) && Array.isArray(newValue)) {
|
|
406
|
+
isDifferent = deepArrayComparison ? !deepArrayEqual(oldValue, newValue) : oldValue !== newValue;
|
|
407
|
+
if (isDifferent) {
|
|
408
|
+
const paths = collectDetailedPaths(oldValue, newValue, key);
|
|
409
|
+
added.push(...paths.added);
|
|
410
|
+
deleted.push(...paths.deleted);
|
|
411
|
+
modified.push(...paths.modified);
|
|
412
|
+
changes[key] = newValue;
|
|
413
|
+
}
|
|
414
|
+
} else if (isObject(oldValue) && isObject(newValue)) {
|
|
415
|
+
const nestedDiff = diffObject(oldValue, newValue, options);
|
|
416
|
+
isDifferent = Object.keys(nestedDiff).length > 0;
|
|
417
|
+
if (isDifferent) {
|
|
418
|
+
const paths = collectDetailedPaths(oldValue, newValue, key);
|
|
419
|
+
added.push(...paths.added);
|
|
420
|
+
deleted.push(...paths.deleted);
|
|
421
|
+
modified.push(...paths.modified);
|
|
422
|
+
changes[key] = nestedDiff;
|
|
423
|
+
}
|
|
424
|
+
} else {
|
|
425
|
+
isDifferent = !equalityFn(oldValue, newValue);
|
|
426
|
+
if (isDifferent) {
|
|
427
|
+
modified.push(key);
|
|
428
|
+
changes[key] = newValue;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
for (const key in oldObj) {
|
|
433
|
+
if (!processedKeys.has(key)) {
|
|
434
|
+
deleted.push(key);
|
|
435
|
+
changes[key] = void 0;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
return {
|
|
439
|
+
changes,
|
|
440
|
+
added,
|
|
441
|
+
deleted,
|
|
442
|
+
modified,
|
|
443
|
+
hasChanges: added.length > 0 || deleted.length > 0 || modified.length > 0
|
|
444
|
+
};
|
|
445
|
+
};
|
|
446
|
+
function isApplyDiff(value) {
|
|
447
|
+
if (value && (value.diff || value.changes) && (value.modified || value.deleted || value.hasChanges)) {
|
|
448
|
+
return true;
|
|
449
|
+
}
|
|
450
|
+
return false;
|
|
451
|
+
}
|
|
452
|
+
var applyDiff = (baseObj, option, keepRefParam) => {
|
|
453
|
+
if (!isApplyDiff(option)) {
|
|
454
|
+
const diff2 = option;
|
|
455
|
+
const shouldKeepRef2 = keepRefParam || false;
|
|
456
|
+
if (Array.isArray(baseObj) && Array.isArray(diff2)) {
|
|
457
|
+
const result3 = shouldKeepRef2 ? baseObj : [...baseObj];
|
|
458
|
+
if (diff2.length < result3.length) {
|
|
459
|
+
result3.length = diff2.length;
|
|
460
|
+
}
|
|
461
|
+
for (let i = 0; i < diff2.length; i++) {
|
|
462
|
+
const diffValue = diff2[i];
|
|
463
|
+
if (diffValue === void 0) {
|
|
464
|
+
continue;
|
|
465
|
+
}
|
|
466
|
+
if (isObject(result3[i]) && isObject(diffValue)) {
|
|
467
|
+
result3[i] = applyDiff(result3[i], diffValue, shouldKeepRef2);
|
|
468
|
+
} else if (Array.isArray(result3[i]) && Array.isArray(diffValue)) {
|
|
469
|
+
result3[i] = applyDiff(
|
|
470
|
+
result3[i],
|
|
471
|
+
diffValue,
|
|
472
|
+
shouldKeepRef2
|
|
473
|
+
);
|
|
474
|
+
} else {
|
|
475
|
+
result3[i] = diffValue;
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
return result3;
|
|
479
|
+
}
|
|
480
|
+
if (!isObject(baseObj)) return diff2;
|
|
481
|
+
if (!isObject(diff2)) return baseObj;
|
|
482
|
+
const result2 = shouldKeepRef2 ? baseObj : { ...baseObj };
|
|
483
|
+
for (const key in diff2) {
|
|
484
|
+
const diffValue = diff2[key];
|
|
485
|
+
if (diffValue === void 0) {
|
|
486
|
+
delete result2[key];
|
|
487
|
+
} else if (Array.isArray(result2[key]) && Array.isArray(diffValue)) {
|
|
488
|
+
result2[key] = applyDiff(result2[key], diffValue, shouldKeepRef2);
|
|
489
|
+
} else if (isObject(result2[key]) && isObject(diffValue)) {
|
|
490
|
+
result2[key] = applyDiff(result2[key], diffValue, shouldKeepRef2);
|
|
491
|
+
} else {
|
|
492
|
+
result2[key] = diffValue;
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
return result2;
|
|
496
|
+
}
|
|
497
|
+
const {
|
|
498
|
+
diff,
|
|
499
|
+
added = [],
|
|
500
|
+
deleted = [],
|
|
501
|
+
modified = [],
|
|
502
|
+
changes,
|
|
503
|
+
keepRef: keepRefOption
|
|
504
|
+
} = option;
|
|
505
|
+
const shouldKeepRef = keepRefParam !== void 0 ? keepRefParam : keepRefOption;
|
|
506
|
+
const diffToApply = changes || diff;
|
|
507
|
+
if (!diffToApply) return baseObj;
|
|
508
|
+
const addedSet = new Set(added);
|
|
509
|
+
const deletedSet = new Set(deleted);
|
|
510
|
+
const modifiedSet = new Set(modified);
|
|
511
|
+
const shouldApplyPath = (path) => {
|
|
512
|
+
if (added.length === 0 && deleted.length === 0 && modified.length === 0) {
|
|
513
|
+
return true;
|
|
514
|
+
}
|
|
515
|
+
const pathParts = path.split(/[.\[\]]+/).filter(Boolean);
|
|
516
|
+
for (let i = 0; i <= pathParts.length; i++) {
|
|
517
|
+
const partialPath = pathParts.slice(0, i).join(".");
|
|
518
|
+
const bracketPath = pathParts.slice(0, i).map((p, idx) => /^\d+$/.test(p) ? `[${p}]` : idx > 0 ? `.${p}` : p).join("");
|
|
519
|
+
if (addedSet.has(partialPath) || addedSet.has(bracketPath) || deletedSet.has(partialPath) || deletedSet.has(bracketPath) || modifiedSet.has(partialPath) || modifiedSet.has(bracketPath)) {
|
|
520
|
+
return true;
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
return false;
|
|
524
|
+
};
|
|
525
|
+
if (Array.isArray(baseObj) && Array.isArray(diffToApply)) {
|
|
526
|
+
const result2 = shouldKeepRef ? baseObj : [...baseObj];
|
|
527
|
+
result2.length = diffToApply.length;
|
|
528
|
+
for (let i = 0; i < diffToApply.length; i++) {
|
|
529
|
+
const indexPath = `[${i}]`;
|
|
530
|
+
const diffValue = diffToApply[i];
|
|
531
|
+
if (diffValue === void 0) {
|
|
532
|
+
continue;
|
|
533
|
+
}
|
|
534
|
+
if (!shouldApplyPath(indexPath)) {
|
|
535
|
+
continue;
|
|
536
|
+
}
|
|
537
|
+
if (isObject(result2[i]) && isObject(diffValue)) {
|
|
538
|
+
result2[i] = applyDiff(result2[i], diffValue, shouldKeepRef);
|
|
539
|
+
} else if (Array.isArray(result2[i]) && Array.isArray(diffValue)) {
|
|
540
|
+
result2[i] = applyDiff(
|
|
541
|
+
result2[i],
|
|
542
|
+
diffValue,
|
|
543
|
+
shouldKeepRef
|
|
544
|
+
);
|
|
545
|
+
} else {
|
|
546
|
+
result2[i] = diffValue;
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
return result2;
|
|
550
|
+
}
|
|
551
|
+
if (!isObject(baseObj)) return diffToApply;
|
|
552
|
+
if (!isObject(diffToApply)) return baseObj;
|
|
553
|
+
const result = shouldKeepRef ? baseObj : { ...baseObj };
|
|
554
|
+
for (const path of deleted) {
|
|
555
|
+
if (path.includes(".") || path.includes("[")) continue;
|
|
556
|
+
if (shouldApplyPath(path)) {
|
|
557
|
+
delete result[path];
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
for (const key in diffToApply) {
|
|
561
|
+
const diffValue = diffToApply[key];
|
|
562
|
+
if (!shouldApplyPath(key)) {
|
|
563
|
+
continue;
|
|
564
|
+
}
|
|
565
|
+
if (diffValue === void 0) {
|
|
566
|
+
delete result[key];
|
|
567
|
+
} else if (Array.isArray(result[key]) && Array.isArray(diffValue)) {
|
|
568
|
+
result[key] = applyDiff(result[key], diffValue, shouldKeepRef);
|
|
569
|
+
} else if (isObject(result[key]) && isObject(diffValue)) {
|
|
570
|
+
result[key] = applyDiff(result[key], diffValue, shouldKeepRef);
|
|
571
|
+
} else {
|
|
572
|
+
result[key] = diffValue;
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
return result;
|
|
576
|
+
};
|
|
577
|
+
|
|
578
|
+
// src/lib/object/selector.ts
|
|
579
|
+
var parseSelector = (selector, options = {}) => {
|
|
580
|
+
const { type = "auto", throwOnError = false } = options;
|
|
581
|
+
if (!selector || typeof selector !== "string") {
|
|
582
|
+
return [];
|
|
583
|
+
}
|
|
584
|
+
const segments = [];
|
|
585
|
+
let current = "";
|
|
586
|
+
let inBrackets = false;
|
|
587
|
+
let inQuotes = false;
|
|
588
|
+
let quoteChar = "";
|
|
589
|
+
let bracketContent = "";
|
|
590
|
+
let bracketDepth = 0;
|
|
591
|
+
const detectType = (str) => {
|
|
592
|
+
if (str.includes("..")) return "descendant";
|
|
593
|
+
if (str.includes("[?(")) return "filter";
|
|
594
|
+
if (str.includes("[:") || str.includes("[0:")) return "slice";
|
|
595
|
+
if (str.includes("[,") || str.includes("[0,1]")) return "union";
|
|
596
|
+
if (str.includes("[*]") || str.includes(".*.")) return "wildcard";
|
|
597
|
+
if (str.includes("[]")) return "array-wildcard";
|
|
598
|
+
if (str.includes("[") && str.includes("]")) return "bracket";
|
|
599
|
+
return "dot";
|
|
600
|
+
};
|
|
601
|
+
const actualType = type === "auto" ? detectType(selector) : type;
|
|
602
|
+
const parseBracketContent = (content) => {
|
|
603
|
+
const trimmed = content.trim();
|
|
604
|
+
if (trimmed === "*" || trimmed === "") {
|
|
605
|
+
return {
|
|
606
|
+
type: "wildcard",
|
|
607
|
+
value: trimmed === "" ? "[]" : "*",
|
|
608
|
+
raw: trimmed === "" ? "[]" : content
|
|
609
|
+
};
|
|
610
|
+
}
|
|
611
|
+
if (trimmed === "[]") {
|
|
612
|
+
return { type: "wildcard", value: "[]", raw: content };
|
|
613
|
+
}
|
|
614
|
+
if (/^-?\d+$/.test(trimmed)) {
|
|
615
|
+
return { type: "index", value: parseInt(trimmed, 10), raw: content };
|
|
616
|
+
}
|
|
617
|
+
if (trimmed.includes(":")) {
|
|
618
|
+
const parts = trimmed.split(":").map((p) => p.trim());
|
|
619
|
+
const start = parts[0] === "" ? 0 : parseInt(parts[0], 10);
|
|
620
|
+
const end = parts[1] === "" ? Infinity : parseInt(parts[1], 10);
|
|
621
|
+
if (isNaN(start) || isNaN(end)) {
|
|
622
|
+
if (throwOnError) throw new Error(`Invalid slice notation: ${content}`);
|
|
623
|
+
return { type: "wildcard", value: "*", raw: content };
|
|
624
|
+
}
|
|
625
|
+
return { type: "slice", value: [start, end], raw: content };
|
|
626
|
+
}
|
|
627
|
+
if (trimmed.includes(",")) {
|
|
628
|
+
const indices = trimmed.split(",").map((p) => {
|
|
629
|
+
const num = parseInt(p.trim(), 10);
|
|
630
|
+
return isNaN(num) ? -1 : num;
|
|
631
|
+
}).filter((n) => n >= 0);
|
|
632
|
+
if (indices.length === 0) {
|
|
633
|
+
if (throwOnError) throw new Error(`Invalid union notation: ${content}`);
|
|
634
|
+
return { type: "wildcard", value: "*", raw: content };
|
|
635
|
+
}
|
|
636
|
+
return { type: "union", value: indices, raw: content };
|
|
637
|
+
}
|
|
638
|
+
if (trimmed.startsWith("?(") && trimmed.endsWith(")")) {
|
|
639
|
+
const expr = trimmed.slice(2, -1);
|
|
640
|
+
try {
|
|
641
|
+
const filterFn = createFilterFunction(expr);
|
|
642
|
+
return { type: "filter", value: filterFn, raw: content };
|
|
643
|
+
} catch (error) {
|
|
644
|
+
if (throwOnError) throw error;
|
|
645
|
+
return { type: "wildcard", value: "*", raw: content };
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
if (trimmed.startsWith('"') && trimmed.endsWith('"') || trimmed.startsWith("'") && trimmed.endsWith("'")) {
|
|
649
|
+
return { type: "property", value: trimmed.slice(1, -1), raw: content };
|
|
650
|
+
}
|
|
651
|
+
return { type: "property", value: trimmed, raw: content };
|
|
652
|
+
};
|
|
653
|
+
for (let i = 0; i < selector.length; i++) {
|
|
654
|
+
const char = selector[i];
|
|
655
|
+
const nextChar = selector[i + 1];
|
|
656
|
+
if ((char === '"' || char === "'") && !inQuotes) {
|
|
657
|
+
inQuotes = true;
|
|
658
|
+
quoteChar = char;
|
|
659
|
+
continue;
|
|
660
|
+
} else if (char === quoteChar && inQuotes) {
|
|
661
|
+
inQuotes = false;
|
|
662
|
+
quoteChar = "";
|
|
663
|
+
if (!(char === '"' || char === "'")) {
|
|
664
|
+
if (inBrackets) {
|
|
665
|
+
bracketContent += char;
|
|
666
|
+
} else {
|
|
667
|
+
current += char;
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
continue;
|
|
671
|
+
}
|
|
672
|
+
if (inQuotes) {
|
|
673
|
+
if (inBrackets) {
|
|
674
|
+
bracketContent += char;
|
|
675
|
+
} else {
|
|
676
|
+
current += char;
|
|
677
|
+
}
|
|
678
|
+
continue;
|
|
679
|
+
}
|
|
680
|
+
if (char === "[" && !inBrackets) {
|
|
681
|
+
if (current) {
|
|
682
|
+
segments.push({ type: "property", value: current, raw: current });
|
|
683
|
+
current = "";
|
|
684
|
+
}
|
|
685
|
+
inBrackets = true;
|
|
686
|
+
bracketContent = "";
|
|
687
|
+
continue;
|
|
688
|
+
}
|
|
689
|
+
if (char === "]" && inBrackets && !inQuotes) {
|
|
690
|
+
inBrackets = false;
|
|
691
|
+
const segment = parseBracketContent(bracketContent);
|
|
692
|
+
segments.push(segment);
|
|
693
|
+
continue;
|
|
694
|
+
}
|
|
695
|
+
let lastDot = segments.length > 0 ? segments[segments.length - 1] : null;
|
|
696
|
+
if (char === "." && !inBrackets && !inQuotes) {
|
|
697
|
+
if (nextChar === ".") {
|
|
698
|
+
const l = selector.split("..")[0];
|
|
699
|
+
segments.push({ type: "property", value: l, raw: l });
|
|
700
|
+
segments.push({ type: "descendant", value: "..", raw: ".." });
|
|
701
|
+
i++;
|
|
702
|
+
} else if (current) {
|
|
703
|
+
if (current === "*") {
|
|
704
|
+
segments.push({ type: "wildcard", value: current, raw: current });
|
|
705
|
+
} else {
|
|
706
|
+
segments.push({ type: "property", value: current, raw: current });
|
|
707
|
+
}
|
|
708
|
+
current = "";
|
|
709
|
+
}
|
|
710
|
+
continue;
|
|
711
|
+
}
|
|
712
|
+
if (inBrackets) {
|
|
713
|
+
bracketContent += char;
|
|
714
|
+
} else {
|
|
715
|
+
if (lastDot && lastDot.type !== "descendant") {
|
|
716
|
+
current += char;
|
|
717
|
+
} else {
|
|
718
|
+
const l = selector.split(lastDot?.raw)[1];
|
|
719
|
+
if (l !== void 0) {
|
|
720
|
+
current = l;
|
|
721
|
+
} else {
|
|
722
|
+
current += char;
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
if (current) {
|
|
728
|
+
segments.push({ type: "property", value: current, raw: current });
|
|
729
|
+
}
|
|
730
|
+
return segments.map((segment) => {
|
|
731
|
+
if (segment.type === "property" && typeof segment.value === "string") {
|
|
732
|
+
if (/^-?\d+$/.test(segment.value)) {
|
|
733
|
+
const num = parseInt(segment.value, 10);
|
|
734
|
+
if (!isNaN(num)) {
|
|
735
|
+
return { ...segment, type: "index", value: num };
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
return segment;
|
|
740
|
+
});
|
|
741
|
+
};
|
|
742
|
+
var createFilterFunction = (expr) => {
|
|
743
|
+
const safeExpr = expr.replace(/@\.([a-zA-Z_$][\w$]*)/g, (_, prop) => `item.${prop}`).replace(/@/g, "item");
|
|
744
|
+
try {
|
|
745
|
+
return new Function("item", `return ${safeExpr}`);
|
|
746
|
+
} catch (error) {
|
|
747
|
+
throw new Error(`Invalid filter expression: ${expr}`);
|
|
748
|
+
}
|
|
749
|
+
};
|
|
750
|
+
|
|
751
|
+
// src/lib/object/merge.ts
|
|
752
|
+
function merge(...sources) {
|
|
753
|
+
if (sources.length === 0) return {};
|
|
754
|
+
const firstItem = sources[0];
|
|
755
|
+
const isArrayMerge = Array.isArray(firstItem);
|
|
756
|
+
for (const source of sources) {
|
|
757
|
+
if (source && Array.isArray(source) !== isArrayMerge) {
|
|
758
|
+
throw new Error("Cannot mix arrays and objects in deepMerge");
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
let result = isArrayMerge ? [] : {};
|
|
762
|
+
for (const source of sources) {
|
|
763
|
+
if (source == null) continue;
|
|
764
|
+
if (isArrayMerge) {
|
|
765
|
+
const resultArray = result;
|
|
766
|
+
const sourceArray = source;
|
|
767
|
+
for (const item of sourceArray) {
|
|
768
|
+
resultArray.push(deepClone(item));
|
|
769
|
+
}
|
|
770
|
+
} else {
|
|
771
|
+
if (!isPlainObject(source)) continue;
|
|
772
|
+
const resultObj = result;
|
|
773
|
+
const sourceObj = source;
|
|
774
|
+
for (const key in sourceObj) {
|
|
775
|
+
if (Object.prototype.hasOwnProperty.call(sourceObj, key)) {
|
|
776
|
+
const value = sourceObj[key];
|
|
777
|
+
const existing = resultObj[key];
|
|
778
|
+
if (existing === void 0) {
|
|
779
|
+
resultObj[key] = deepClone(value);
|
|
780
|
+
} else if (Array.isArray(value) && Array.isArray(existing)) {
|
|
781
|
+
resultObj[key] = [
|
|
782
|
+
...existing,
|
|
783
|
+
...value.map((item) => deepClone(item))
|
|
784
|
+
];
|
|
785
|
+
} else if (isPlainObject(value) && isPlainObject(existing)) {
|
|
786
|
+
resultObj[key] = merge(existing, value);
|
|
787
|
+
} else {
|
|
788
|
+
resultObj[key] = deepClone(value);
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
const symbols = Object.getOwnPropertySymbols(sourceObj);
|
|
793
|
+
for (const symbol of symbols) {
|
|
794
|
+
const value = sourceObj[symbol];
|
|
795
|
+
const existing = resultObj[symbol];
|
|
796
|
+
if (existing === void 0) {
|
|
797
|
+
resultObj[symbol] = deepClone(value);
|
|
798
|
+
} else if (Array.isArray(value) && Array.isArray(existing)) {
|
|
799
|
+
resultObj[symbol] = [
|
|
800
|
+
...existing,
|
|
801
|
+
...value.map((item) => deepClone(item))
|
|
802
|
+
];
|
|
803
|
+
} else if (isPlainObject(value) && isPlainObject(existing)) {
|
|
804
|
+
resultObj[symbol] = merge(existing, value);
|
|
805
|
+
} else {
|
|
806
|
+
resultObj[symbol] = deepClone(value);
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
return result;
|
|
812
|
+
}
|
|
813
|
+
function mergeArrays(arr1, arr2, options) {
|
|
814
|
+
const { key, override = true } = options || {};
|
|
815
|
+
if (!key) {
|
|
816
|
+
return Array.from(/* @__PURE__ */ new Set([...arr1, ...arr2]));
|
|
817
|
+
}
|
|
818
|
+
const map = /* @__PURE__ */ new Map();
|
|
819
|
+
for (const item of arr1) {
|
|
820
|
+
map.set(item[key], item);
|
|
821
|
+
}
|
|
822
|
+
for (const item of arr2) {
|
|
823
|
+
const existing = map.get(item[key]);
|
|
824
|
+
if (!existing) {
|
|
825
|
+
map.set(item[key], item);
|
|
826
|
+
} else {
|
|
827
|
+
map.set(
|
|
828
|
+
item[key],
|
|
829
|
+
override ? { ...existing, ...item } : { ...item, ...existing }
|
|
830
|
+
// keep original
|
|
831
|
+
);
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
return Array.from(map.values());
|
|
835
|
+
}
|
|
836
|
+
function mergeInPlace(target, source) {
|
|
837
|
+
for (const key in source) {
|
|
838
|
+
const tVal = target[key];
|
|
839
|
+
const sVal = source[key];
|
|
840
|
+
const diff = diffObjectDetailed(tVal, sVal);
|
|
841
|
+
if (Array.isArray(tVal) && Array.isArray(sVal)) {
|
|
842
|
+
tVal.length = 0;
|
|
843
|
+
tVal.push(...sVal);
|
|
844
|
+
} else if (typeof tVal === "object" && typeof sVal === "object" && tVal && sVal && diff.hasChanges) {
|
|
845
|
+
applyDiff(tVal, sVal);
|
|
846
|
+
} else {
|
|
847
|
+
target[key] = sVal;
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
function deepMergeWithOptions(target, ...args) {
|
|
852
|
+
if (args.length === 0) return deepClone(target);
|
|
853
|
+
let options = { preserveTarget: false, strict: false };
|
|
854
|
+
let sources = args;
|
|
855
|
+
const lastArg = args[args.length - 1];
|
|
856
|
+
if (lastArg && typeof lastArg === "object" && ("preserveTarget" in lastArg || "strict" in lastArg)) {
|
|
857
|
+
options = { ...options, ...lastArg };
|
|
858
|
+
sources = args.slice(0, -1);
|
|
859
|
+
}
|
|
860
|
+
const result = options.preserveTarget ? target : deepClone(target);
|
|
861
|
+
const isArrayMerge = Array.isArray(result);
|
|
862
|
+
for (const source of sources) {
|
|
863
|
+
if (source && Array.isArray(source) !== isArrayMerge) {
|
|
864
|
+
throw new Error("Cannot mix arrays and objects in deepMergeWithOptions");
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
for (const source of sources) {
|
|
868
|
+
if (source == null) continue;
|
|
869
|
+
if (isArrayMerge) {
|
|
870
|
+
const resultArray = result;
|
|
871
|
+
const sourceArray = source;
|
|
872
|
+
if (options.strict) {
|
|
873
|
+
for (let i = 0; i < resultArray.length && i < sourceArray.length; i++) {
|
|
874
|
+
if (isPlainObject(resultArray[i]) && isPlainObject(sourceArray[i])) {
|
|
875
|
+
resultArray[i] = deepMergeWithOptions(
|
|
876
|
+
resultArray[i],
|
|
877
|
+
sourceArray[i],
|
|
878
|
+
options
|
|
879
|
+
);
|
|
880
|
+
} else {
|
|
881
|
+
if (typeof resultArray[i] === typeof sourceArray[i]) {
|
|
882
|
+
resultArray[i] = deepClone(sourceArray[i]);
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
} else {
|
|
887
|
+
mergeInPlace(resultArray, sourceArray);
|
|
888
|
+
}
|
|
889
|
+
} else {
|
|
890
|
+
if (!isPlainObject(source)) continue;
|
|
891
|
+
const resultObj = result;
|
|
892
|
+
const sourceObj = source;
|
|
893
|
+
for (const key in sourceObj) {
|
|
894
|
+
if (!Object.prototype.hasOwnProperty.call(sourceObj, key)) continue;
|
|
895
|
+
const value = sourceObj[key];
|
|
896
|
+
if (options.strict && !(key in resultObj)) {
|
|
897
|
+
continue;
|
|
898
|
+
}
|
|
899
|
+
const existing = resultObj[key];
|
|
900
|
+
if (existing === void 0) {
|
|
901
|
+
resultObj[key] = deepClone(value);
|
|
902
|
+
} else if (Array.isArray(value) && Array.isArray(existing)) {
|
|
903
|
+
if (options.strict) {
|
|
904
|
+
resultObj[key] = deepMergeWithOptions(existing, value, options);
|
|
905
|
+
} else {
|
|
906
|
+
resultObj[key] = [
|
|
907
|
+
...existing,
|
|
908
|
+
...value.map((item) => deepClone(item))
|
|
909
|
+
];
|
|
910
|
+
}
|
|
911
|
+
} else if (isPlainObject(value) && isPlainObject(existing)) {
|
|
912
|
+
resultObj[key] = deepMergeWithOptions(existing, value, options);
|
|
913
|
+
} else {
|
|
914
|
+
resultObj[key] = deepClone(value);
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
const symbols = Object.getOwnPropertySymbols(sourceObj);
|
|
918
|
+
for (const symbol of symbols) {
|
|
919
|
+
if (options.strict && !(symbol in resultObj)) {
|
|
920
|
+
continue;
|
|
921
|
+
}
|
|
922
|
+
const value = sourceObj[symbol];
|
|
923
|
+
const existing = resultObj[symbol];
|
|
924
|
+
if (existing === void 0) {
|
|
925
|
+
resultObj[symbol] = deepClone(value);
|
|
926
|
+
} else if (Array.isArray(value) && Array.isArray(existing)) {
|
|
927
|
+
if (options.strict) {
|
|
928
|
+
resultObj[symbol] = deepMergeWithOptions(
|
|
929
|
+
existing,
|
|
930
|
+
value,
|
|
931
|
+
options
|
|
932
|
+
);
|
|
933
|
+
} else {
|
|
934
|
+
resultObj[symbol] = [
|
|
935
|
+
...existing,
|
|
936
|
+
...value.map((item) => deepClone(item))
|
|
937
|
+
];
|
|
938
|
+
}
|
|
939
|
+
} else if (isPlainObject(value) && isPlainObject(existing)) {
|
|
940
|
+
resultObj[symbol] = deepMergeWithOptions(
|
|
941
|
+
existing,
|
|
942
|
+
value,
|
|
943
|
+
options
|
|
944
|
+
);
|
|
945
|
+
} else {
|
|
946
|
+
resultObj[symbol] = deepClone(value);
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
return result;
|
|
952
|
+
}
|
|
953
|
+
function deepMergeKeepReference(target, ...sources) {
|
|
954
|
+
return deepMergeWithOptions(target, ...sources, {
|
|
955
|
+
preserveTarget: true
|
|
956
|
+
});
|
|
957
|
+
}
|
|
958
|
+
function deepMergeStrict(target, ...args) {
|
|
959
|
+
let preserveReference = false;
|
|
960
|
+
let sources = args;
|
|
961
|
+
if (args.length > 0 && typeof args[args.length - 1] === "boolean") {
|
|
962
|
+
preserveReference = args[args.length - 1];
|
|
963
|
+
sources = args.slice(0, -1);
|
|
964
|
+
}
|
|
965
|
+
return deepMergeWithOptions(target, ...sources, {
|
|
966
|
+
preserveTarget: preserveReference,
|
|
967
|
+
strict: true
|
|
968
|
+
});
|
|
969
|
+
}
|
|
970
|
+
var mergeIntoStructure = (target, selector, value) => {
|
|
971
|
+
const segments = parseSelector(selector);
|
|
972
|
+
let current = target;
|
|
973
|
+
for (let i = 0; i < segments.length; i++) {
|
|
974
|
+
const segment = segments[i];
|
|
975
|
+
const isLast = i === segments.length - 1;
|
|
976
|
+
switch (segment.type) {
|
|
977
|
+
case "property":
|
|
978
|
+
if (isLast) {
|
|
979
|
+
current[String(segment.value)] = value;
|
|
980
|
+
} else {
|
|
981
|
+
if (!current[String(segment.value)]) {
|
|
982
|
+
const nextSegment = segments[i + 1];
|
|
983
|
+
current[String(segment.value)] = nextSegment.type === "index" || nextSegment.type === "slice" || nextSegment.type === "union" || nextSegment.type === "wildcard" ? [] : {};
|
|
984
|
+
}
|
|
985
|
+
current = current[String(segment.value)];
|
|
986
|
+
}
|
|
987
|
+
break;
|
|
988
|
+
case "index":
|
|
989
|
+
if (!Array.isArray(current)) {
|
|
990
|
+
current = [];
|
|
991
|
+
}
|
|
992
|
+
const index = segment.value;
|
|
993
|
+
if (isLast) {
|
|
994
|
+
if (index >= current.length) {
|
|
995
|
+
for (let j = current.length; j <= index; j++) {
|
|
996
|
+
current.push(void 0);
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
current[index] = value;
|
|
1000
|
+
} else {
|
|
1001
|
+
if (!current[index]) {
|
|
1002
|
+
const nextSegment = segments[i + 1];
|
|
1003
|
+
current[index] = nextSegment.type === "index" || nextSegment.type === "slice" || nextSegment.type === "union" || nextSegment.type === "wildcard" ? [] : {};
|
|
1004
|
+
}
|
|
1005
|
+
current = current[index];
|
|
1006
|
+
}
|
|
1007
|
+
break;
|
|
1008
|
+
case "wildcard":
|
|
1009
|
+
if (Array.isArray(current)) {
|
|
1010
|
+
if (isLast) {
|
|
1011
|
+
for (let j = 0; j < current.length; j++) {
|
|
1012
|
+
current[j] = value;
|
|
1013
|
+
}
|
|
1014
|
+
} else {
|
|
1015
|
+
const nextSegment = segments[i + 1];
|
|
1016
|
+
for (let j = 0; j < current.length; j++) {
|
|
1017
|
+
if (!current[j]) {
|
|
1018
|
+
current[j] = nextSegment.type === "index" || nextSegment.type === "slice" || nextSegment.type === "union" || nextSegment.type === "wildcard" ? [] : {};
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
if (current.length > 0) {
|
|
1022
|
+
current = current[0];
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
break;
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
};
|