@fluixi/utils 1.0.0-alpha.82 → 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.
Files changed (129) hide show
  1. package/dist/index.cjs +2858 -1
  2. package/dist/index.mjs +2838 -1
  3. package/dist/lib/array/advanced.cjs +2227 -1
  4. package/dist/lib/array/advanced.mjs +2204 -1
  5. package/dist/lib/array/array.cjs +57 -1
  6. package/dist/lib/array/array.mjs +36 -1
  7. package/dist/lib/array/index.cjs +2344 -1
  8. package/dist/lib/array/index.mjs +2322 -1
  9. package/dist/lib/array/utils.cjs +103 -1
  10. package/dist/lib/array/utils.mjs +82 -1
  11. package/dist/lib/color/color.cjs +2190 -1
  12. package/dist/lib/color/color.mjs +2167 -1
  13. package/dist/lib/color/constants.cjs +380 -1
  14. package/dist/lib/color/constants.mjs +359 -1
  15. package/dist/lib/color/conversions.cjs +629 -1
  16. package/dist/lib/color/conversions.mjs +608 -1
  17. package/dist/lib/color/helpers.cjs +2534 -1
  18. package/dist/lib/color/helpers.mjs +2511 -1
  19. package/dist/lib/color/index.cjs +2641 -1
  20. package/dist/lib/color/index.mjs +2619 -1
  21. package/dist/lib/color/types.cjs +18 -1
  22. package/dist/lib/color/utils.cjs +962 -1
  23. package/dist/lib/color/utils.mjs +939 -1
  24. package/dist/lib/compare/comparators.cjs +171 -1
  25. package/dist/lib/compare/comparators.mjs +150 -1
  26. package/dist/lib/compare/index.cjs +172 -1
  27. package/dist/lib/compare/index.mjs +152 -1
  28. package/dist/lib/crypto/hash.cjs +83 -1
  29. package/dist/lib/crypto/hash.mjs +62 -1
  30. package/dist/lib/crypto/index.cjs +85 -1
  31. package/dist/lib/crypto/index.mjs +62 -1
  32. package/dist/lib/dom/events.cjs +40 -1
  33. package/dist/lib/dom/events.mjs +19 -1
  34. package/dist/lib/dom/index.cjs +78 -1
  35. package/dist/lib/dom/index.mjs +56 -1
  36. package/dist/lib/dom/utils.cjs +57 -1
  37. package/dist/lib/dom/utils.mjs +36 -1
  38. package/dist/lib/functions/functions.cjs +366 -1
  39. package/dist/lib/functions/functions.mjs +345 -1
  40. package/dist/lib/functions/index.cjs +369 -1
  41. package/dist/lib/functions/index.mjs +347 -1
  42. package/dist/lib/functions/types.cjs +18 -1
  43. package/dist/lib/helpers.cjs +78 -1
  44. package/dist/lib/helpers.mjs +59 -1
  45. package/dist/lib/index.cjs +2857 -1
  46. package/dist/lib/index.mjs +2836 -1
  47. package/dist/lib/maths/constants.cjs +70 -1
  48. package/dist/lib/maths/constants.mjs +50 -1
  49. package/dist/lib/maths/fn/advanced.cjs +231 -1
  50. package/dist/lib/maths/fn/advanced.mjs +208 -1
  51. package/dist/lib/maths/fn/basic.cjs +212 -1
  52. package/dist/lib/maths/fn/basic.mjs +191 -1
  53. package/dist/lib/maths/fn/complex.cjs +268 -1
  54. package/dist/lib/maths/fn/complex.mjs +247 -1
  55. package/dist/lib/maths/fn/index.cjs +877 -1
  56. package/dist/lib/maths/fn/index.mjs +855 -1
  57. package/dist/lib/maths/fn/trigo.cjs +179 -1
  58. package/dist/lib/maths/fn/trigo.mjs +156 -1
  59. package/dist/lib/maths/fn/vector.cjs +728 -1
  60. package/dist/lib/maths/fn/vector.mjs +707 -1
  61. package/dist/lib/maths/formatter.cjs +61 -1
  62. package/dist/lib/maths/formatter.mjs +40 -1
  63. package/dist/lib/maths/guards.cjs +164 -1
  64. package/dist/lib/maths/guards.mjs +144 -1
  65. package/dist/lib/maths/index.cjs +1152 -1
  66. package/dist/lib/maths/index.mjs +1130 -1
  67. package/dist/lib/maths/parser.cjs +75 -1
  68. package/dist/lib/maths/parser.mjs +54 -1
  69. package/dist/lib/maths/random.cjs +49 -1
  70. package/dist/lib/maths/random.mjs +28 -1
  71. package/dist/lib/maths/types/advanced.cjs +18 -1
  72. package/dist/lib/maths/types/basic.cjs +18 -1
  73. package/dist/lib/maths/types/index.cjs +19 -1
  74. package/dist/lib/maths/types/index.mjs +1 -0
  75. package/dist/lib/maths/types/negative.cjs +18 -1
  76. package/dist/lib/maths/types/operations.cjs +18 -1
  77. package/dist/lib/object/clone.cjs +88 -1
  78. package/dist/lib/object/clone.mjs +65 -1
  79. package/dist/lib/object/diff.cjs +573 -1
  80. package/dist/lib/object/diff.mjs +550 -1
  81. package/dist/lib/object/getter-setter.cjs +2351 -1
  82. package/dist/lib/object/getter-setter.mjs +2330 -1
  83. package/dist/lib/object/index.cjs +3956 -6
  84. package/dist/lib/object/index.mjs +3936 -6
  85. package/dist/lib/object/merge.cjs +1029 -1
  86. package/dist/lib/object/merge.mjs +1006 -1
  87. package/dist/lib/object/object.cjs +280 -1
  88. package/dist/lib/object/object.mjs +257 -1
  89. package/dist/lib/object/omit.cjs +2022 -1
  90. package/dist/lib/object/omit.mjs +1999 -1
  91. package/dist/lib/object/reconcile.cjs +126 -1
  92. package/dist/lib/object/reconcile.mjs +105 -1
  93. package/dist/lib/object/selector.cjs +303 -1
  94. package/dist/lib/object/selector.mjs +282 -1
  95. package/dist/lib/object/sort.cjs +209 -1
  96. package/dist/lib/object/sort.mjs +186 -1
  97. package/dist/lib/object/transform.cjs +2211 -1
  98. package/dist/lib/object/transform.mjs +2190 -1
  99. package/dist/lib/object/types.cjs +18 -1
  100. package/dist/lib/object/utils.cjs +326 -6
  101. package/dist/lib/object/utils.mjs +305 -6
  102. package/dist/lib/primitive/boolean/boolean.cjs +407 -1
  103. package/dist/lib/primitive/boolean/boolean.mjs +386 -1
  104. package/dist/lib/primitive/boolean/index.cjs +382 -1
  105. package/dist/lib/primitive/boolean/index.mjs +359 -1
  106. package/dist/lib/primitive/boolean/types.cjs +18 -1
  107. package/dist/lib/primitive/date/date.cjs +1126 -1
  108. package/dist/lib/primitive/date/date.mjs +1105 -1
  109. package/dist/lib/primitive/date/index.cjs +1128 -1
  110. package/dist/lib/primitive/date/index.mjs +1105 -1
  111. package/dist/lib/primitive/date/types.cjs +18 -1
  112. package/dist/lib/primitive/index.cjs +2338 -5
  113. package/dist/lib/primitive/index.mjs +2316 -5
  114. package/dist/lib/primitive/string/index.cjs +875 -5
  115. package/dist/lib/primitive/string/index.mjs +852 -5
  116. package/dist/lib/primitive/string/parser-2.cjs +543 -8
  117. package/dist/lib/primitive/string/parser-2.mjs +522 -8
  118. package/dist/lib/primitive/string/parser.cjs +236 -3
  119. package/dist/lib/primitive/string/parser.mjs +215 -3
  120. package/dist/lib/primitive/string/string.cjs +926 -5
  121. package/dist/lib/primitive/string/string.mjs +903 -5
  122. package/dist/lib/primitive/string/types.cjs +18 -1
  123. package/dist/lib/primitive/types.cjs +18 -1
  124. package/dist/lib/url/index.cjs +327 -1
  125. package/dist/lib/url/index.mjs +304 -1
  126. package/dist/lib/url/parser.cjs +325 -1
  127. package/dist/lib/url/parser.mjs +304 -1
  128. package/dist/lib/url/types.cjs +18 -1
  129. package/package.json +5 -5
@@ -1 +1,2190 @@
1
- var m=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";var w=(e,r,n,a)=>{if(n>a)return;if(r.length===0)return e;let s=r[0],i=r.slice(1);if(s.type==="descendant"){let o=w(e,i,n+1,a);if(o!==void 0)return o;if(e&&typeof e=="object")if(Array.isArray(e)){let t=[];for(let f=0;f<e.length;f++){let l=w(e[f],r,n+1,a);l!==void 0&&(t[f]=l)}return t.length>0?t:void 0}else{let t={};for(let f in e)if(e.hasOwnProperty(f)){let l=w(e[f],r,n+1,a);l!==void 0&&(t[f]=l)}return Object.keys(t).length>0?t:void 0}return}switch(s.type){case"property":if(m(e)&&s.value&&String(s.value)in e){let o=e[String(s.value)],t=w(o,i,n+1,a);if(t!==void 0)return{[String(s.value)]:t}}break;case"index":if(Array.isArray(e)){let o=s.value;if(o>=0&&o<e.length){let t=w(e[o],i,n+1,a);if(t!==void 0){let f=new Array(e.length).filter(l=>l!==void 0);return f[o]=t,f}}}else if(e&&typeof e=="object"){let o=String(s.value);if(o in e){let t=w(e[o],i,n+1,a);if(t!==void 0)return{[o]:t}}}break;case"wildcard":if(e&&typeof e=="object")if(Array.isArray(e)){let o=[],t=!1;for(let f=0;f<e.length;f++){let l=w(e[f],i,n+1,a);l!==void 0&&(o[f]=l,t=!0)}return t?o:void 0}else{let o={},t=!1;for(let f in e)if(e.hasOwnProperty(f)){let l=w(e[f],i,n+1,a);l!==void 0&&(o[f]=l,t=!0)}return t?o:void 0}break;case"slice":if(Array.isArray(e)){let[o,t]=s.value,f=Math.max(0,o),l=Math.min(e.length,t===1/0?e.length:t),y=[],A=!1;for(let p=f;p<l;p++){let g=w(e[p],i,n+1,a);g!==void 0&&(y[p]=g,A=!0)}return A?y:void 0}break;case"union":if(Array.isArray(e)){let o=s.value,t=[],f=!1;for(let l of o)if(l>=0&&l<e.length){let y=w(e[l],i,n+1,a);y!==void 0&&(t[l]=y,f=!0)}return f?t:void 0}break;case"filter":if(Array.isArray(e)){let o=s.value,t=[],f=!1;for(let l=0;l<e.length;l++)if(o(e[l])){let y=w(e[l],i,n+1,a);y!==void 0&&(t[l]=y,f=!0)}return f?t:void 0}break}};import{isDate as X}from"@fluixi/utils/primitive";import{isClass as Te,isObject as xe}from"@fluixi/utils/object";import{isArray as me}from"@fluixi/utils/array";import{isFunction as Ke}from"@fluixi/utils/functions";function D(e){let r=typeof e;return e===null||r==="string"||r==="number"||r==="boolean"||r==="symbol"||r==="bigint"||r==="undefined"||X(e)}var I=(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 n=new Map;return e.forEach((a,s)=>{(!r||!r.some(i=>i.toString()===s.toString()))&&n.set(s,I(a))}),n}if(e instanceof Set){let n=new Set;return e.forEach(a=>{n.add(I(a))}),n}if(Array.isArray(e))return Array.from(e).map(n=>I(n));if(m(e)){let n={};for(let s in e)Object.prototype.hasOwnProperty.call(e,s)&&(!r||!r.some(i=>i.toString()===s.toString()))&&(n[s]=I(e[s]));let a=Object.getOwnPropertySymbols(e);for(let s of a)(!r||!r.some(i=>i.toString()===s.toString()))&&(n[s]=I(e[s]));return n}return e};var W=(e,r)=>e===r,V=(e,r)=>{if(e.length!==r.length)return!1;for(let n=0;n<e.length;n++)if(Array.isArray(e[n])&&Array.isArray(r[n])){if(!V(e[n],r[n]))return!1}else if(m(e[n])&&m(r[n])){if(!N(e[n],r[n]))return!1}else if(e[n]!==r[n])return!1;return!0},N=(e,r)=>{let n=Object.keys(e),a=Object.keys(r);if(n.length!==a.length)return!1;for(let s of n){if(!(s in r))return!1;let i=e[s],o=r[s];if(Array.isArray(i)&&Array.isArray(o)){if(!V(i,o))return!1}else if(m(i)&&m(o)){if(!N(i,o))return!1}else if(i!==o)return!1}return!0},_=(e,r,n={})=>{let{includeDeleted:a=!1,includeAdded:s=!0,deepArrayComparison:i=!0,equalityFn:o=W,preserveStructure:t=!1}=n;if(e==null&&r==null)return{};if(e==null)return s?{...r}:{};if(r==null){if(a){let y={};for(let A in e)y[A]=void 0;return y}return{}}if(!m(e)||!m(r))return o(e,r)?{}:r;let f={},l=new Set;for(let y in r){l.add(y);let A=e[y],p=r[y];if(!(y in e)){s&&(f[y]=p);continue}if(Array.isArray(A)&&Array.isArray(p)){i?V(A,p)?t&&(f[y]=void 0):f[y]=p:A!==p?f[y]=p:t&&(f[y]=void 0);continue}if(m(A)&&m(p)){let g=_(A,p,n);Object.keys(g).length>0?f[y]=g:t&&(f[y]=void 0);continue}o(A,p)?t&&(f[y]=void 0):f[y]=p}if(a)for(let y in e)l.has(y)||(f[y]=void 0);return f},C=(e,r,n={})=>{let a=[],s=[],i=[],o={},{includeDeleted:t=!1,includeAdded:f=!0,deepArrayComparison:l=!0,equalityFn:y=W}=n;if(Array.isArray(e)&&Array.isArray(r)){let g=Math.max(e.length,r.length),c=[],d=!1;for(let u=0;u<g;u++){let T=`[${u}]`;if(u>=e.length)a.push(T),c[u]=r[u],d=!0;else if(u>=r.length)s.push(T),d=!0;else{let x=e[u],h=r[u];m(x)&&m(h)||Array.isArray(x)&&Array.isArray(h)?C(x,h,n).hasChanges?(i.push(T),c[u]=h,d=!0):c[u]=x:y(x,h)?c[u]=x:(i.push(T),c[u]=h,d=!0)}}return{changes:d?c:{},added:a,deleted:s,modified:i,hasChanges:d||s.length>0}}let A=(g,c,d="")=>{let u={added:[],deleted:[],modified:[]};if(Array.isArray(g)&&Array.isArray(c)){let T=Math.max(g.length,c.length);for(let x=0;x<T;x++){let h=d?`${d}[${x}]`:`[${x}]`;if(x>=g.length)u.added.push(h);else if(x>=c.length)u.deleted.push(h);else{let S=g[x],K=c[x];if(m(S)&&m(K)){let b=A(S,K,h);u.added.push(...b.added),u.deleted.push(...b.deleted),u.modified.push(...b.modified)}else if(Array.isArray(S)&&Array.isArray(K)){let b=A(S,K,h);u.added.push(...b.added),u.deleted.push(...b.deleted),u.modified.push(...b.modified)}else S!==K&&u.modified.push(h)}}return u}if(m(g)&&m(c)){let T=new Set([...Object.keys(g||{}),...Object.keys(c||{})]);for(let x of T){let h=g?.[x],S=c?.[x],K=d?`${d}.${x}`:x;if(!(x in(g||{})))u.added.push(K);else if(!(x in(c||{})))u.deleted.push(K);else if(Array.isArray(h)&&Array.isArray(S)){if(!V(h,S)){let b=A(h,S,K);u.added.push(...b.added),u.deleted.push(...b.deleted),u.modified.push(...b.modified)}}else if(m(h)&&m(S)){let b=A(h,S,K);u.added.push(...b.added),u.deleted.push(...b.deleted),u.modified.push(...b.modified)}else h!==S&&u.modified.push(K)}}return u};if(e==null&&r==null)return{changes:{},added:a,deleted:s,modified:i,hasChanges:!1};if(e==null){if(f&&r)for(let g in r)a.push(g),o[g]=r[g];return{changes:o,added:a,deleted:s,modified:i,hasChanges:a.length>0}}if(r==null){if(t)for(let g in e)s.push(g),o[g]=void 0;return{changes:o,added:a,deleted:s,modified:i,hasChanges:s.length>0}}let p=new Set;for(let g in r){p.add(g);let c=e[g],d=r[g];if(!(g in e)){f&&(a.push(g),o[g]=d);continue}let u=!1;if(Array.isArray(c)&&Array.isArray(d)){if(u=l?!V(c,d):c!==d,u){let T=A(c,d,g);a.push(...T.added),s.push(...T.deleted),i.push(...T.modified),o[g]=d}}else if(m(c)&&m(d)){let T=_(c,d,n);if(u=Object.keys(T).length>0,u){let x=A(c,d,g);a.push(...x.added),s.push(...x.deleted),i.push(...x.modified),o[g]=T}}else u=!y(c,d),u&&(i.push(g),o[g]=d)}for(let g in e)p.has(g)||(s.push(g),o[g]=void 0);return{changes:o,added:a,deleted:s,modified:i,hasChanges:a.length>0||s.length>0||i.length>0}};function Y(e){return!!(e&&(e.diff||e.changes)&&(e.modified||e.deleted||e.hasChanges))}var O=(e,r,n)=>{if(!Y(r)){let u=r,T=n||!1;if(Array.isArray(e)&&Array.isArray(u)){let h=T?e:[...e];u.length<h.length&&(h.length=u.length);for(let S=0;S<u.length;S++){let K=u[S];K!==void 0&&(m(h[S])&&m(K)||Array.isArray(h[S])&&Array.isArray(K)?h[S]=O(h[S],K,T):h[S]=K)}return h}if(!m(e))return u;if(!m(u))return e;let x=T?e:{...e};for(let h in u){let S=u[h];S===void 0?delete x[h]:Array.isArray(x[h])&&Array.isArray(S)||m(x[h])&&m(S)?x[h]=O(x[h],S,T):x[h]=S}return x}let{diff:a,added:s=[],deleted:i=[],modified:o=[],changes:t,keepRef:f}=r,l=n!==void 0?n:f,y=t||a;if(!y)return e;let A=new Set(s),p=new Set(i),g=new Set(o),c=u=>{if(s.length===0&&i.length===0&&o.length===0)return!0;let T=u.split(/[.\[\]]+/).filter(Boolean);for(let x=0;x<=T.length;x++){let h=T.slice(0,x).join("."),S=T.slice(0,x).map((K,b)=>/^\d+$/.test(K)?`[${K}]`:b>0?`.${K}`:K).join("");if(A.has(h)||A.has(S)||p.has(h)||p.has(S)||g.has(h)||g.has(S))return!0}return!1};if(Array.isArray(e)&&Array.isArray(y)){let u=l?e:[...e];u.length=y.length;for(let T=0;T<y.length;T++){let x=`[${T}]`,h=y[T];h!==void 0&&c(x)&&(m(u[T])&&m(h)||Array.isArray(u[T])&&Array.isArray(h)?u[T]=O(u[T],h,l):u[T]=h)}return u}if(!m(e))return y;if(!m(y))return e;let d=l?e:{...e};for(let u of i)u.includes(".")||u.includes("[")||c(u)&&delete d[u];for(let u in y){let T=y[u];c(u)&&(T===void 0?delete d[u]:Array.isArray(d[u])&&Array.isArray(T)||m(d[u])&&m(T)?d[u]=O(d[u],T,l):d[u]=T)}return d};var v=(e,r={})=>{let{type:n="auto",throwOnError:a=!1}=r;if(!e||typeof e!="string")return[];let s=[],i="",o=!1,t=!1,f="",l="",y=0,p=n==="auto"?(c=>c.includes("..")?"descendant":c.includes("[?(")?"filter":c.includes("[:")||c.includes("[0:")?"slice":c.includes("[,")||c.includes("[0,1]")?"union":c.includes("[*]")||c.includes(".*.")?"wildcard":c.includes("[]")?"array-wildcard":c.includes("[")&&c.includes("]")?"bracket":"dot")(e):n,g=c=>{let d=c.trim();if(d==="*"||d==="")return{type:"wildcard",value:d===""?"[]":"*",raw:d===""?"[]":c};if(d==="[]")return{type:"wildcard",value:"[]",raw:c};if(/^-?\d+$/.test(d))return{type:"index",value:parseInt(d,10),raw:c};if(d.includes(":")){let u=d.split(":").map(h=>h.trim()),T=u[0]===""?0:parseInt(u[0],10),x=u[1]===""?1/0:parseInt(u[1],10);if(isNaN(T)||isNaN(x)){if(a)throw new Error(`Invalid slice notation: ${c}`);return{type:"wildcard",value:"*",raw:c}}return{type:"slice",value:[T,x],raw:c}}if(d.includes(",")){let u=d.split(",").map(T=>{let x=parseInt(T.trim(),10);return isNaN(x)?-1:x}).filter(T=>T>=0);if(u.length===0){if(a)throw new Error(`Invalid union notation: ${c}`);return{type:"wildcard",value:"*",raw:c}}return{type:"union",value:u,raw:c}}if(d.startsWith("?(")&&d.endsWith(")")){let u=d.slice(2,-1);try{return{type:"filter",value:ee(u),raw:c}}catch(T){if(a)throw T;return{type:"wildcard",value:"*",raw:c}}}return d.startsWith('"')&&d.endsWith('"')||d.startsWith("'")&&d.endsWith("'")?{type:"property",value:d.slice(1,-1),raw:c}:{type:"property",value:d,raw:c}};for(let c=0;c<e.length;c++){let d=e[c],u=e[c+1];if((d==='"'||d==="'")&&!t){t=!0,f=d;continue}else if(d===f&&t){t=!1,f="",d==='"'||d==="'"||(o?l+=d:i+=d);continue}if(t){o?l+=d:i+=d;continue}if(d==="["&&!o){i&&(s.push({type:"property",value:i,raw:i}),i=""),o=!0,l="";continue}if(d==="]"&&o&&!t){o=!1;let x=g(l);s.push(x);continue}let T=s.length>0?s[s.length-1]:null;if(d==="."&&!o&&!t){if(u==="."){let x=e.split("..")[0];s.push({type:"property",value:x,raw:x}),s.push({type:"descendant",value:"..",raw:".."}),c++}else i&&(i==="*"?s.push({type:"wildcard",value:i,raw:i}):s.push({type:"property",value:i,raw:i}),i="");continue}if(o)l+=d;else if(T&&T.type!=="descendant")i+=d;else{let x=e.split(T?.raw)[1];x!==void 0?i=x:i+=d}}return i&&s.push({type:"property",value:i,raw:i}),s.map(c=>{if(c.type==="property"&&typeof c.value=="string"&&/^-?\d+$/.test(c.value)){let d=parseInt(c.value,10);if(!isNaN(d))return{...c,type:"index",value:d}}return c})},ee=e=>{let r=e.replace(/@\.([a-zA-Z_$][\w$]*)/g,(n,a)=>`item.${a}`).replace(/@/g,"item");try{return new Function("item",`return ${r}`)}catch{throw new Error(`Invalid filter expression: ${e}`)}};var q=(e,r,n)=>{let a=v(r),s=e;for(let i=0;i<a.length;i++){let o=a[i],t=i===a.length-1;switch(o.type){case"property":if(t)s[String(o.value)]=n;else{if(!s[String(o.value)]){let l=a[i+1];s[String(o.value)]=l.type==="index"||l.type==="slice"||l.type==="union"||l.type==="wildcard"?[]:{}}s=s[String(o.value)]}break;case"index":Array.isArray(s)||(s=[]);let f=o.value;if(t){if(f>=s.length)for(let l=s.length;l<=f;l++)s.push(void 0);s[f]=n}else{if(!s[f]){let l=a[i+1];s[f]=l.type==="index"||l.type==="slice"||l.type==="union"||l.type==="wildcard"?[]:{}}s=s[f]}break;case"wildcard":if(Array.isArray(s))if(t)for(let l=0;l<s.length;l++)s[l]=n;else{let l=a[i+1];for(let y=0;y<s.length;y++)s[y]||(s[y]=l.type==="index"||l.type==="slice"||l.type==="union"||l.type==="wildcard"?[]:{});s.length>0&&(s=s[0])}break}}};function $(e,r,n={}){let{preserveStructure:a,multiple:s,throwOnError:i=!1,defaultValue:o,maxDepth:t=20}=n;if(!e||typeof e!="object")return o;if(!r)return e;if(Array.isArray(r))if(a){let y={};for(let A of r){let p=$(e,A,{...n,preserveStructure:!1});p!==void 0&&q(y,A,p)}return y}else return r.map(y=>$(e,y,{...n,preserveStructure:!1}));let f=v(r,{...n,throwOnError:i});if(f.length===0)return e;if(typeof a>"u"||a===!1){let y=F(e,r);return s===!1&&Array.isArray(y)?y[0]:y===void 0&&o!==void 0?o:y}let l=w(e,f,0,t);return l===void 0&&o!==void 0?o:l}function Z(e,r,n,a,s){let i=I(e),o=[];if(typeof r<"u"&&o.push(r),typeof n<"u"&&o.push(n),typeof a<"u"&&o.push(a),typeof s<"u"&&o.push(s),D(i))return typeof r=="function"?r(i):r;if(o.length===1){if(typeof o[0]=="function")return le(i,o[0]);if(Array.isArray(o[0])){if(Array.isArray(i))if(r.length===0)for(let t=0;t<i.length;t++)i.pop();else return C([...i],[...o[0]]).hasChanges&&O(i,[...o[0]],!0),i}else typeof o[0]=="object"&&!Array.isArray(o[0])?typeof i=="object"&&!Array.isArray(i)&&O(i,o[0],!0):i=o[0];return i}if(Array.isArray(i)){if(typeof r=="string"&&(ne(n)||typeof n=="string")&&o.length===3){if(Array.isArray(n)){for(let t=0;t<n.length;t++)P(i,r,a,n[t]);return i}return P(i,r,a,n)}if(typeof r=="string"&&typeof n=="function"&&o.length===2)return P(i,r,n)}if((typeof r=="string"||typeof r=="number")&&(o.length===2||o.length===3))return te(n)?E(i,r,n,a):typeof r=="number"?typeof a<"u"?P(i,`[${r}].${n}`,a):P(i,`[${r}]`,n,a):typeof n=="number"&&typeof a<"u"?U(i,r,n,a):Array.isArray(n)&&n.length>0&&n.every(t=>typeof t=="number")?R(i,r,n,a):typeof a<"u"&&typeof n=="function"?j(i,r,n,a):P(i,r,n,a);if(typeof r=="string"&&typeof n=="number"){if(o.length===3)return U(i,r,n,a);if(o.length===4)return re(i,r,n,a,s)}if(typeof r=="string"&&Array.isArray(n)){if(o.length===3)return R(i,r,n,a);if(o.length===4)return se(i,r,n,a,s)}if(typeof r=="string"&&typeof n=="object"&&!Array.isArray(n)&&n!==null){let t=n;if("from"in t||"to"in t){if(o.length===3)return E(i,r,t,a);if(o.length===4)return ae(i,r,t,a,s)}}if(typeof r=="object"&&!Array.isArray(r)&&o.length===1)return O(i,r,!0);if(typeof r=="string"&&typeof n=="object"&&!Array.isArray(n)&&o.length===2)return oe(i,r,n);if(typeof r=="string"&&typeof n=="function"){if(o.length===3)return j(i,r,n,a);if(o.length===4)return B(i,r,n,a,s)}if(typeof r=="function"&&typeof n=="string"){if(o.length===3)return ie(i,r,n,a);if(o.length===4)return B(i,n,r,a,s)}if(Array.isArray(r)){if(o.length===2&&typeof n=="object"&&!Array.isArray(n))return L(i,r,n);if(o.length===2)return L(i,r,n)}throw new Error(`Invalid set parameters: ${JSON.stringify(o)}`)}function M(e,r,n,a=!1){let s=v(e);if(s.length===0)return n;let i=s[s.length-1].type==="wildcard",o=s.some(f=>f.type==="wildcard")&&Array.isArray(r),t;if((i||o&&a||o&&s.length===2)&&Array.isArray(r))for(let f=0;f<r.length;f++){let l=typeof n=="function"?n(r[f]):typeof r[f]=="object"?O(r[f],n,!0):n;t||(t=[]),t.push(l)}return!i&&!t&&(t=typeof n=="function"?n(r):n),t}function te(e){return typeof e=="object"&&e!==null&&"from"in e&&"to"in e&&typeof e.from=="number"&&typeof e.to=="number"&&e.from<e.to&&e.from>=0&&e.to>0}function ne(e){return Array.isArray(e)&&e.every(r=>typeof r=="string")}function P(e,r,n,a){let s=v(r),i=F(e,r,{paths:s,createMissing:!0}),o;a&&typeof n=="function"&&(o=$(i,a));let f=M(r,a?o:i,n,Array.isArray(e));return a?k(e,`${r}.${a}`,f,{createMissing:!0}):k(e,r,f,{createMissing:!0})}function U(e,r,n,a){let s=F(e,r,{createMissing:!0});if(!Array.isArray(s))throw new Error(`Target at ${r} is not an array ${n}`);let i=structuredClone(s),o=M(r,i[n],a);if(n<0){let t=s.length+n;if(t<0)throw new Error(`Index ${n} is out of bounds`);return k(e,`${r}[${t}]`,o,{createMissing:!0})}return k(e,`${r}[${n}]`,o,{createMissing:!0})}var re=(e,r,n,a,s)=>typeof a=="function"?P(e,`${r}[${n}]`,a):typeof a=="string"?P(e,`${r}[${n}]`,s,a):null,R=(e,r,n,a)=>{let s=F(e,r);if(!Array.isArray(s))throw new Error(`Target at ${r} is not an array`);for(let i of n)typeof i=="number"?U(e,r,i,a):typeof i=="string"&&P(e,r,a,i);return e},se=(e,r,n,a,s)=>R(e,r,n,o=>{let t=typeof s=="function"?s(o?F(o,a):void 0):s,f=o?{...o}:{};return k(f,a,t),f});function E(e,r,n,a){let s=F(e,r);if(!Array.isArray(s))throw new Error(`Target at ${r} is not an array`);let i=n.from??0,o=n.to??s.length-1,t=n.by??1,f=[];for(let l=i;l<=o;l+=t)l>=0&&l<s.length&&f.push(l);return R(e,r,f,a)}var ae=(e,r,n,a,s)=>E(e,r,n,o=>{let t=typeof s=="function"?s(o?F(o,a):void 0):s,f=o?{...o}:{};return k(f,a,t),f});function j(e,r,n,a){let s=F(e,r);if(!Array.isArray(s))throw new Error(`Target at ${r} is not an array`);let i=[],o=[...s];return s.forEach((t,f)=>{n(t,f)&&i.push(f)}),R(e,r,i,a)}function ie(e,r,n,a){let s=e;if(!Array.isArray(s))throw new Error(`Target at ${n} is not an array`);let i=[],o=[...s];return s.forEach((t,f)=>{t=k(t,n,a,{createMissing:!0})}),s}function B(e,r,n,a,s){return j(e,r,n,o=>{let t=typeof s=="function"?s(o?F(o,a):void 0):s,f=o?{...o}:{};return k(f,a,t),f})}function oe(e,r,n){let a=F(e,r,{createMissing:!0}),s=O(a||{},n,!0);return k(e,r,s,{createMissing:!0})}function L(e,r,n){if(typeof n=="object"&&!Array.isArray(n)&&n!==null)for(let[a,s]of Object.entries(n))r.includes(a)&&k(e,a,s,{createMissing:!0});else for(let a of r){let s=M(a,F(e,a),n);k(e,a,s,{createMissing:!0})}return e}function F(e,r,n={}){let{createMissing:a=!1,add:s=!1,debug:i=!1}=n,o=v(r),t=e,f=!1,l="",y=r;if(typeof t=="object"&&!Array.isArray(t)&&y.length>0&&t[y])return t=t[y],t;for(let A=0;A<o.length;A++){let p=o[A],g=o.length>1?A===o.length-1:!1;if(t===null&&!a)return;let c=o[A+1];switch(p.type){case"property":if(t&&typeof t=="object")if(Array.isArray(t)){if(typeof p.value=="number"){let d=p.value;if(a&&d>=t.length)for(let u=t.length;u<=d;u++)t.push(void 0);if(a&&(t[d]===null||t[d]===void 0)&&(!g||f)&&(c?t[d]=c.type==="index"||c.type==="slice"||c.type==="union"||c.type==="wildcard"?[]:{}:t[d]=null,f=!1),t=t[d],c){f=!0;continue}}else s?t.push({[String(p.value)]:null}):t=t.map(d=>d[String(p.value)]);if(c)continue;return z(t)}else{if(t[l]&&l.split(".").length>=2){t=t[l];continue}if(a&&(t[String(p.value)]===null||t[String(p.value)]===void 0)&&(!g||f)&&(c?t[String(p.value)]=c.type==="index"||c.type==="slice"||c.type==="union"||c.type==="wildcard"?[]:{}:t[String(p.value)]=null,f=!1,t=t[String(p.value)],c)){f=!0;continue}if(t?(!t[String(p.value)]&&a&&(t[String(p.value)]=null),t=t[String(p.value)]):t={[String(p.value)]:null},c)continue}else if(a)t={},t[String(p.value)]=c.type==="index"||c.type==="slice"||c.type==="union"||c.type==="wildcard"||n.type==="array"?[]:{},t=t[String(p.value)];else return;break;case"index":case"wildcard":if(Array.isArray(t)){if(p.type==="index"){let d=p.value;if(d<0){t=t[t.length-Math.abs(d)];continue}if(a&&(d>=t.length||t[d]==null||t[d]==null)&&!g){for(let u=t.length;u<=d;u++)t.push(void 0);c&&(t[d]=c.type==="index"||c.type==="slice"||c.type==="union"||c.type==="wildcard"?[]:{})}t=t[d]}else if(!g)continue}else if(a){let d=o[A+1];t=[];let u=p.value;for(let T=0;T<=u;T++)t.push(void 0);t[u]=d.type==="index"||d.type==="slice"||d.type==="union"||d.type==="wildcard"||n.type==="array"?[]:{},t=t[u]}else{if(p.type==="index"&&typeof t=="object"&&t&&t[String(p.value)]!==void 0){t=t[String(p.value)];continue}if(typeof t=="object"){t=Object.values(t);continue}return}break;default:return}}return z(t)}function z(e){return Array.isArray(e)?e.filter(r=>typeof r<"u"):e}var k=(e,r,n,a={})=>{if(r==="[*]")return O(e,n,!0);let{createMissing:s=!0}=a,i=v(r);if(i.length===0)return e;let o=i[i.length-1],t=e;for(let f=0;f<i.length-1;f++){let l=i[f];if(t==null){if(!s)return e;throw new Error(`Cannot navigate through null/undefined at segment ${f}`)}let y=i[f+1],A=y.type==="index"||y.type==="slice"||y.type==="union"||y.type==="wildcard";if(l.type==="property"){if(Array.isArray(t)&&typeof typeof l.value=="number"){let p=l.value;if(p<0)throw new Error(`Negative index ${p} not allowed`);if(p>=t.length&&s)for(let g=t.length;g<=p;g++)t.push(void 0);(t[p]===null||t[p]===void 0)&&s&&(t[p]=A?[]:{}),t=t[p]}else(t[String(l.value)]===null||t[String(l.value)]===void 0)&&s&&(t[String(l.value)]=A?[]:{}),typeof t=="object"&&!Array.isArray(t)&&(t=t[String(l.value)]);if(y)continue;break}else if(l.type==="index"||l.type==="wildcard"){if(!Array.isArray(t)){if(!s)return e;t=[]}if(l.type==="index"){let p=l.value;if(p<0)throw new Error(`Negative index ${p} not allowed`);if(p>=t.length&&s)for(let g=t.length;g<=p;g++)t.push(void 0);(t[p]===null||t[p]===void 0)&&s&&(t[p]=A?[]:void 0),t=t[p]}if(y)continue;break}else throw new Error(`Invalid segment type for set: ${l.type}`)}switch(o.type){case"property":if(Array.isArray(t)&&typeof o.value=="number"){let l=o.value;if(l<0)throw new Error(`Negative index ${l} not allowed`);if(l>=t.length)for(let y=t.length;y<=l;y++)t.push(void 0);Array.isArray(n)?t[l]=O(structuredClone(t[l]),n[l],!0):t[l]=n}else if(t||(t={}),Array.isArray(t)){let l=r.split("."),y;if(l.length>=2){l.shift();for(let A=0;A<t.length;A++)Array.isArray(n)?(y=J(l.join("."),n[A]),t[A]=typeof t[A]=="object"?O(t[A],y,!0):y):(y=J(l.join("."),n),t[A]=typeof t[A]=="object"?O(t[A],y,!0):y)}else y={[String(o.value)]:n}}else Array.isArray(n)&&n.length===0?typeof t[String(o.value)]>"u"?t[String(o.value)]=[]:t[String(o.value)]=[]:t[String(o.value)]=n;break;case"index":case"wildcard":if(!Array.isArray(t))throw new Error("Cannot use index on non-array for final segment");let f=o.value;if(o.type==="index"){if(f<0)throw new Error(`Negative index ${f} not allowed`);if(f>=t.length)for(let l=t.length;l<=f;l++)t.push(void 0);if(Array.isArray(n))if(typeof t[f]==typeof n[f])try{t[f]=O(I(t[f]),n[f],!0)}catch{throw Error("expected on array")}else t[f]=n;else t[f]=n}else if(o.type==="wildcard")if(Array.isArray(n))for(let l=0;l<t.length;l++)typeof t[l]=="object"?t[l]=O(t[l],n[l],!0):t[l]=n[l];else for(let l=0;l<t.length;l++)typeof t[l]=="object"?t[l]=O(t[l],n,!0):t[l]=n;break;default:throw new Error(`Invalid final segment type for set: ${o.type}`)}return e};var J=(e,r)=>{let n=v(e);if(n.length===0)return r;let a=r;for(let s=n.length-1;s>=0;s--){let i=n[s];if(i.type==="property")a={[String(i.value)]:a};else if(i.type==="index"){let o=parseInt(String(i.value)),t=[];t[o]=a,a=t}else i.type==="wildcard"?Array.isArray(a)?a=a:a=[a]:i.type==="slice"?Array.isArray(a)||(a=[a]):i.type==="union"?Array.isArray(a)||(a=[a]):i.type==="filter"?Array.isArray(a)||(a=[a]):i.type==="descendant"&&(a=a)}return a};var le=(e,r)=>{let n=r(e);return O(e,n,!0)};function qe(e,r){if(!m(e))return{};let n={};for(let a in e)Object.prototype.hasOwnProperty.call(e,a)&&(n[a]=r(e[a],a,e));return n}function Be(e,r){if(!m(e))return{};let n={};for(let a in e)if(Object.prototype.hasOwnProperty.call(e,a)){let s=r(a,e[a],e);n[s]=e[a]}return n}function Q(e,r={deep:!0}){if(!m(e))return e;if(Array.isArray(e))return r.deep?e.map(a=>Q(a,r)):e;let n={};for(let a in e)if(Object.prototype.hasOwnProperty.call(e,a)){let s=e[a],i=a.replace(/[-_]([a-z])/g,(o,t)=>t.toUpperCase()).replace(/^([A-Z])/,o=>o.toLowerCase());n[i]=r.deep&&m(s)?Q(s,r):s}return n}function G(e,r={deep:!0}){if(!m(e))return e;if(Array.isArray(e))return r.deep?e.map(a=>G(a,r)):e;let n={};for(let a in e)if(Object.prototype.hasOwnProperty.call(e,a)){let s=e[a],i=a.replace(/[-]([a-z])/g,(o,t)=>`_${t}`).replace(/([a-z0-9])([A-Z])/g,"$1_$2").toLowerCase();n[i]=r.deep&&m(s)?G(s,r):s}return n}function H(e,r={deep:!0}){if(!m(e))return e;if(Array.isArray(e))return r.deep?e.map(a=>H(a,r)):e;let n={};for(let a in e)if(Object.prototype.hasOwnProperty.call(e,a)){let s=e[a],i=a.replace(/[_]([a-z])/g,(o,t)=>`-${t}`).replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();n[i]=r.deep&&m(s)?H(s,r):s}return n}var fe=(e,r={})=>{let{delimiter:n=".",includeArrays:a=!1,maxDepth:s=9}=r;if(Array.isArray(e))return e.map(t=>fe(t,r));let i={},o=(t,f="",l=0)=>{if(l>s){i[f]=t;return}if(!m(t)&&!Array.isArray(t)){f&&(i[f]=t);return}if(Array.isArray(t))for(let y=0;y<t.length;y++){let A=f?`${f}[${y}]`:`[${y}]`;o(t[y],A,l+1)}else{for(let A in t){let p=f?`${f}${n}${A}`:A;o(t[A],p,l+1)}let y=Object.getOwnPropertySymbols(t);for(let A of y){let p=f?`${f}${n}${A.toString()}`:A.toString();o(t[A],p,l+1)}}};return o(e),i};function ye(e,r={}){let{delimiter:n=".",detectArrays:a=!0}=r,s={};for(let i in e)if(Object.prototype.hasOwnProperty.call(e,i)){let o=e[i],t=i.split(n),f=s;for(let y=0;y<t.length-1;y++){let A=t[y],p=t[y+1],g=a&&/^\d+$/.test(p);if(!(A in f))f[A]=g?[]:{};else if(g&&!Array.isArray(f[A])){let c={...f[A]};f[A]=[],Object.assign(f[A],c)}f=f[A]}let l=t[t.length-1];f[l]=o}if(a){let i=o=>{if(!m(o))return o;if(Array.isArray(o))return o.map(i);let t=Object.keys(o);if(t.length>0&&t.every((y,A)=>String(A)===y))return Object.values(o).map(i);let l={};for(let y in o)Object.prototype.hasOwnProperty.call(o,y)&&(l[y]=i(o[y]));return l};return i(s)}return s}function Le(e,...r){if(!m(e)||r.length===0)return e;let n={...e};for(let a in n)if(Object.prototype.hasOwnProperty.call(n,a)){let s=n[a];for(let i of r)s=i(s);n[a]=s}return n}function ze(e,r,n={}){if(!m(e))return e;let{removeUnmapped:a=!1}=n,s={};for(let i in e)Object.prototype.hasOwnProperty.call(e,i)&&(i in r?s[r[i]]=e[i]:a||(s[i]=e[i]));return s}function Je(e,r={}){let{transformObject:n=t=>t,transformArray:a=t=>t,transformValue:s=t=>t,maxDepth:i=1/0}=r;function o(t,f=[],l=0){if(l>i)return t;if(Array.isArray(t)){let A=t.map((p,g)=>o(p,[...f,g.toString()],l+1));return a(A,f)}if(m(t)){let A={};for(let p in t)if(Object.prototype.hasOwnProperty.call(t,p)){let g=[...f,p];A[p]=o(t[p],g,l+1),!Array.isArray(t[p])&&!m(t[p])&&(A[p]=s(A[p],p,g))}return n(A,f)}let y=f.length>0?f[f.length-1]:"";return s(t,y,f)}return o(e)}function Ze(e,r={}){return ye(e,r)}function Qe(e,r,n,a={}){if(!m(e))return e;let s=JSON.parse(JSON.stringify(e)),{transformAll:i=!1}=a,o=Array.isArray(r)?r:[r];for(let l of o)if(l.includes("*")||l.includes("[")){let A=function(g,c=""){if(m(g)){if(Array.isArray(g)){g.forEach((d,u)=>{let T=c?`${c}[${u}]`:`[${u}]`;A(d,T)});return}for(let d in g)if(Object.prototype.hasOwnProperty.call(g,d)){let u=g[d],T=c?`${c}.${d}`:d;if(u===null||typeof u!="object"){let x=c?$(s,c):s,h=i?n(u,T,x):n(u,d,x);g[d]=h}else A(u,T)}}};var t=A;let y=$(s,l,{preserveStructure:!0});if(y===void 0)continue;A(y);let p=v(l);if(p.length>0){let g=p[0];g.type==="property"&&(s[String(g.value)]=y[String(g.value)])}}else{let A=function(p,g,c,d){if(c>=g.length)return p;let u=g[c];if(c===g.length-1){let x=c>0?A(p,g,c-1,g.slice(0,c).join(".")):p,h=i?n(x[u],d,x):n(x[u],u,x);return x[u]=h,x}let T=p[u]||{};return p[u]=A(T,g,c+1,d),p};var f=A;let y=l.split(".");A(s,y,0,l)}return s}function Ge(e,r,n,a={}){if(!m(e))return[];let{flatten:s=!0}=a,o=(Array.isArray(r)?r:[r]).map(t=>{let f=$(e,t);return f===void 0?[]:Array.isArray(f)?f.map((l,y)=>{let A=`${t}[${y}]`;return n(l,A,e)}):[n(f,t,e)]});return s?o.flat():o}function He(e,r,n,a={}){if(!m(e))return e;let s=JSON.parse(JSON.stringify(e)),{recursive:i=!1}=a,o=Array.isArray(r)?r:[r];for(let t of o){let f=t?$(s,t):s;if(!m(f))continue;let l=(y,A=t)=>{if(!m(y))return y;if(Array.isArray(y))return y.map((g,c)=>m(g)&&!Array.isArray(g)?l(g,`${A}[${c}]`):g);let p={};for(let g in y)if(Object.prototype.hasOwnProperty.call(y,g)){let c=n(g,y[g],A);i&&m(y[g])?p[c]=l(y[g],`${A}.${c}`):p[c]=y[g]}return p};if(Array.isArray(f))for(let y=0;y<f.length;y++)m(f[y])&&!Array.isArray(f[y])&&(f[y]=l(f[y],`${t}[${y}]`));else{let y=l(f);t?Z(s,t,y):(Object.keys(s).forEach(A=>{delete s[A]}),Object.assign(s,y))}}return s}export{Q as camelCaseKeys,Je as deepTransform,fe as flatten,H as kebabCaseKeys,Be as mapKeys,Ge as mapPath,qe as mapValues,ze as renameKeys,G as snakeCaseKeys,Ze as structureByKeys,He as transformKeysAtPath,Qe as transformPath,Le as transformValues,ye as unflatten};
1
+ // src/lib/object/utils.ts
2
+ var isObject = (value) => {
3
+ if (value == null) return false;
4
+ if (Array.isArray(value)) return false;
5
+ if (typeof value === "function") return false;
6
+ if (value instanceof Date) return false;
7
+ if (value instanceof RegExp) return false;
8
+ if (value instanceof Map) return false;
9
+ if (value instanceof Set) return false;
10
+ if (value instanceof Error) return false;
11
+ return typeof value === "object";
12
+ };
13
+ var traverseStructure = (current, segments, depth, maxDepth) => {
14
+ if (depth > maxDepth) return void 0;
15
+ if (segments.length === 0) return current;
16
+ const segment = segments[0];
17
+ const remaining = segments.slice(1);
18
+ if (segment.type === "descendant") {
19
+ const result = traverseStructure(current, remaining, depth + 1, maxDepth);
20
+ if (result !== void 0) {
21
+ return result;
22
+ }
23
+ if (current && typeof current === "object") {
24
+ if (Array.isArray(current)) {
25
+ const arrResult = [];
26
+ for (let i = 0; i < current.length; i++) {
27
+ const itemResult = traverseStructure(
28
+ current[i],
29
+ segments,
30
+ depth + 1,
31
+ maxDepth
32
+ );
33
+ if (itemResult !== void 0) {
34
+ arrResult[i] = itemResult;
35
+ }
36
+ }
37
+ return arrResult.length > 0 ? arrResult : void 0;
38
+ } else {
39
+ const objResult = {};
40
+ for (const key in current) {
41
+ if (current.hasOwnProperty(key)) {
42
+ const itemResult = traverseStructure(
43
+ current[key],
44
+ segments,
45
+ depth + 1,
46
+ maxDepth
47
+ );
48
+ if (itemResult !== void 0) {
49
+ objResult[key] = itemResult;
50
+ }
51
+ }
52
+ }
53
+ return Object.keys(objResult).length > 0 ? objResult : void 0;
54
+ }
55
+ }
56
+ return void 0;
57
+ }
58
+ switch (segment.type) {
59
+ case "property":
60
+ if (isObject(current) && segment.value && String(segment.value) in current) {
61
+ const next = current[String(segment.value)];
62
+ const result = traverseStructure(next, remaining, depth + 1, maxDepth);
63
+ if (result !== void 0) {
64
+ return { [String(segment.value)]: result };
65
+ }
66
+ }
67
+ break;
68
+ case "index":
69
+ if (Array.isArray(current)) {
70
+ const index = segment.value;
71
+ if (index >= 0 && index < current.length) {
72
+ const result = traverseStructure(
73
+ current[index],
74
+ remaining,
75
+ depth + 1,
76
+ maxDepth
77
+ );
78
+ if (result !== void 0) {
79
+ const arr = new Array(current.length).filter(
80
+ (a) => a !== void 0
81
+ );
82
+ arr[index] = result;
83
+ return arr;
84
+ }
85
+ }
86
+ } else if (current && typeof current === "object") {
87
+ const key = String(segment.value);
88
+ if (key in current) {
89
+ const result = traverseStructure(
90
+ current[key],
91
+ remaining,
92
+ depth + 1,
93
+ maxDepth
94
+ );
95
+ if (result !== void 0) {
96
+ return { [key]: result };
97
+ }
98
+ }
99
+ }
100
+ break;
101
+ case "wildcard":
102
+ if (current && typeof current === "object") {
103
+ if (Array.isArray(current)) {
104
+ const arrResult = [];
105
+ let hasResults = false;
106
+ for (let i = 0; i < current.length; i++) {
107
+ const result = traverseStructure(
108
+ current[i],
109
+ remaining,
110
+ depth + 1,
111
+ maxDepth
112
+ );
113
+ if (result !== void 0) {
114
+ arrResult[i] = result;
115
+ hasResults = true;
116
+ }
117
+ }
118
+ return hasResults ? arrResult : void 0;
119
+ } else {
120
+ const objResult = {};
121
+ let hasResults = false;
122
+ for (const key in current) {
123
+ if (current.hasOwnProperty(key)) {
124
+ const result = traverseStructure(
125
+ current[key],
126
+ remaining,
127
+ depth + 1,
128
+ maxDepth
129
+ );
130
+ if (result !== void 0) {
131
+ objResult[key] = result;
132
+ hasResults = true;
133
+ }
134
+ }
135
+ }
136
+ return hasResults ? objResult : void 0;
137
+ }
138
+ }
139
+ break;
140
+ case "slice":
141
+ if (Array.isArray(current)) {
142
+ const [start, end] = segment.value;
143
+ const actualStart = Math.max(0, start);
144
+ const actualEnd = Math.min(
145
+ current.length,
146
+ end === Infinity ? current.length : end
147
+ );
148
+ const arrResult = [];
149
+ let hasResults = false;
150
+ for (let i = actualStart; i < actualEnd; i++) {
151
+ const result = traverseStructure(
152
+ current[i],
153
+ remaining,
154
+ depth + 1,
155
+ maxDepth
156
+ );
157
+ if (result !== void 0) {
158
+ arrResult[i] = result;
159
+ hasResults = true;
160
+ }
161
+ }
162
+ return hasResults ? arrResult : void 0;
163
+ }
164
+ break;
165
+ case "union":
166
+ if (Array.isArray(current)) {
167
+ const indices = segment.value;
168
+ const arrResult = [];
169
+ let hasResults = false;
170
+ for (const index of indices) {
171
+ if (index >= 0 && index < current.length) {
172
+ const result = traverseStructure(
173
+ current[index],
174
+ remaining,
175
+ depth + 1,
176
+ maxDepth
177
+ );
178
+ if (result !== void 0) {
179
+ arrResult[index] = result;
180
+ hasResults = true;
181
+ }
182
+ }
183
+ }
184
+ return hasResults ? arrResult : void 0;
185
+ }
186
+ break;
187
+ case "filter":
188
+ if (Array.isArray(current)) {
189
+ const filterFn = segment.value;
190
+ const arrResult = [];
191
+ let hasResults = false;
192
+ for (let i = 0; i < current.length; i++) {
193
+ if (filterFn(current[i])) {
194
+ const result = traverseStructure(
195
+ current[i],
196
+ remaining,
197
+ depth + 1,
198
+ maxDepth
199
+ );
200
+ if (result !== void 0) {
201
+ arrResult[i] = result;
202
+ hasResults = true;
203
+ }
204
+ }
205
+ }
206
+ return hasResults ? arrResult : void 0;
207
+ }
208
+ break;
209
+ }
210
+ return void 0;
211
+ };
212
+
213
+ // src/lib/helpers.ts
214
+ import {
215
+ isDate
216
+ } from "@fluixi/utils/primitive";
217
+ import { isClass, isObject as isObject2 } from "@fluixi/utils/object";
218
+ import { isArray } from "@fluixi/utils/array";
219
+ import { isFunction } from "@fluixi/utils/functions";
220
+ function isPrimitive(v) {
221
+ const type = typeof v;
222
+ return v === null || type === "string" || type === "number" || type === "boolean" || type === "symbol" || type === "bigint" || type === "undefined" || isDate(v);
223
+ }
224
+
225
+ // src/lib/object/clone.ts
226
+ var deepClone = (obj, skipKeys) => {
227
+ if (obj == null || typeof obj !== "object") {
228
+ return obj;
229
+ }
230
+ if (obj instanceof Date) {
231
+ return new Date(obj.getTime());
232
+ }
233
+ if (obj instanceof RegExp) {
234
+ return new RegExp(obj.source, obj.flags);
235
+ }
236
+ if (obj instanceof Map) {
237
+ const clone = /* @__PURE__ */ new Map();
238
+ obj.forEach((value, key) => {
239
+ if (!skipKeys || !skipKeys.some((k) => k.toString() === key.toString())) {
240
+ clone.set(key, deepClone(value));
241
+ }
242
+ });
243
+ return clone;
244
+ }
245
+ if (obj instanceof Set) {
246
+ const clone = /* @__PURE__ */ new Set();
247
+ obj.forEach((value) => {
248
+ clone.add(deepClone(value));
249
+ });
250
+ return clone;
251
+ }
252
+ if (Array.isArray(obj)) {
253
+ return Array.from(obj).map((item) => deepClone(item));
254
+ }
255
+ if (isObject(obj)) {
256
+ const clone = {};
257
+ for (const key in obj) {
258
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
259
+ if (!skipKeys || !skipKeys.some((k) => k.toString() === key.toString())) {
260
+ clone[key] = deepClone(obj[key]);
261
+ }
262
+ }
263
+ }
264
+ const symbols = Object.getOwnPropertySymbols(obj);
265
+ for (const symbol of symbols) {
266
+ if (!skipKeys || !skipKeys.some((s) => s.toString() === symbol.toString())) {
267
+ clone[symbol] = deepClone(obj[symbol]);
268
+ }
269
+ }
270
+ return clone;
271
+ }
272
+ return obj;
273
+ };
274
+
275
+ // src/lib/object/diff.ts
276
+ var defaultEqualityFn = (a, b) => a === b;
277
+ var deepArrayEqual = (arr1, arr2) => {
278
+ if (arr1.length !== arr2.length) return false;
279
+ for (let i = 0; i < arr1.length; i++) {
280
+ if (Array.isArray(arr1[i]) && Array.isArray(arr2[i])) {
281
+ if (!deepArrayEqual(arr1[i], arr2[i])) return false;
282
+ } else if (isObject(arr1[i]) && isObject(arr2[i])) {
283
+ if (!deepObjectEqual(arr1[i], arr2[i])) return false;
284
+ } else if (arr1[i] !== arr2[i]) {
285
+ return false;
286
+ }
287
+ }
288
+ return true;
289
+ };
290
+ var deepObjectEqual = (obj1, obj2) => {
291
+ const keys1 = Object.keys(obj1);
292
+ const keys2 = Object.keys(obj2);
293
+ if (keys1.length !== keys2.length) return false;
294
+ for (const key of keys1) {
295
+ if (!(key in obj2)) return false;
296
+ const val1 = obj1[key];
297
+ const val2 = obj2[key];
298
+ if (Array.isArray(val1) && Array.isArray(val2)) {
299
+ if (!deepArrayEqual(val1, val2)) return false;
300
+ } else if (isObject(val1) && isObject(val2)) {
301
+ if (!deepObjectEqual(val1, val2)) return false;
302
+ } else if (val1 !== val2) {
303
+ return false;
304
+ }
305
+ }
306
+ return true;
307
+ };
308
+ var diffObject = (oldObj, newObj, options = {}) => {
309
+ const {
310
+ includeDeleted = false,
311
+ includeAdded = true,
312
+ deepArrayComparison = true,
313
+ equalityFn = defaultEqualityFn,
314
+ preserveStructure = false
315
+ } = options;
316
+ if (oldObj == null && newObj == null) {
317
+ return {};
318
+ }
319
+ if (oldObj == null) {
320
+ return includeAdded ? { ...newObj } : {};
321
+ }
322
+ if (newObj == null) {
323
+ if (includeDeleted) {
324
+ const result2 = {};
325
+ for (const key in oldObj) {
326
+ result2[key] = void 0;
327
+ }
328
+ return result2;
329
+ }
330
+ return {};
331
+ }
332
+ if (!isObject(oldObj) || !isObject(newObj)) {
333
+ return equalityFn(oldObj, newObj) ? {} : newObj;
334
+ }
335
+ const result = {};
336
+ const processedKeys = /* @__PURE__ */ new Set();
337
+ for (const key in newObj) {
338
+ processedKeys.add(key);
339
+ const oldValue = oldObj[key];
340
+ const newValue = newObj[key];
341
+ if (!(key in oldObj)) {
342
+ if (includeAdded) {
343
+ result[key] = newValue;
344
+ }
345
+ continue;
346
+ }
347
+ if (Array.isArray(oldValue) && Array.isArray(newValue)) {
348
+ if (deepArrayComparison) {
349
+ if (!deepArrayEqual(oldValue, newValue)) {
350
+ result[key] = newValue;
351
+ } else if (preserveStructure) {
352
+ result[key] = void 0;
353
+ }
354
+ } else {
355
+ if (oldValue !== newValue) {
356
+ result[key] = newValue;
357
+ } else if (preserveStructure) {
358
+ result[key] = void 0;
359
+ }
360
+ }
361
+ continue;
362
+ }
363
+ if (isObject(oldValue) && isObject(newValue)) {
364
+ const nestedDiff = diffObject(oldValue, newValue, options);
365
+ if (Object.keys(nestedDiff).length > 0) {
366
+ result[key] = nestedDiff;
367
+ } else if (preserveStructure) {
368
+ result[key] = void 0;
369
+ }
370
+ continue;
371
+ }
372
+ if (!equalityFn(oldValue, newValue)) {
373
+ result[key] = newValue;
374
+ } else if (preserveStructure) {
375
+ result[key] = void 0;
376
+ }
377
+ }
378
+ if (includeDeleted) {
379
+ for (const key in oldObj) {
380
+ if (!processedKeys.has(key)) {
381
+ result[key] = void 0;
382
+ }
383
+ }
384
+ }
385
+ return result;
386
+ };
387
+ var diffObjectDetailed = (oldObj, newObj, options = {}) => {
388
+ const added = [];
389
+ const deleted = [];
390
+ const modified = [];
391
+ const changes = {};
392
+ const {
393
+ includeDeleted = false,
394
+ includeAdded = true,
395
+ deepArrayComparison = true,
396
+ equalityFn = defaultEqualityFn
397
+ } = options;
398
+ if (Array.isArray(oldObj) && Array.isArray(newObj)) {
399
+ const maxLength = Math.max(oldObj.length, newObj.length);
400
+ const arrayChanges = [];
401
+ let hasArrayChanges = false;
402
+ for (let i = 0; i < maxLength; i++) {
403
+ const indexPath = `[${i}]`;
404
+ if (i >= oldObj.length) {
405
+ added.push(indexPath);
406
+ arrayChanges[i] = newObj[i];
407
+ hasArrayChanges = true;
408
+ } else if (i >= newObj.length) {
409
+ deleted.push(indexPath);
410
+ hasArrayChanges = true;
411
+ } else {
412
+ const oldElement = oldObj[i];
413
+ const newElement = newObj[i];
414
+ if (isObject(oldElement) && isObject(newElement)) {
415
+ const nestedDiff = diffObjectDetailed(
416
+ oldElement,
417
+ newElement,
418
+ options
419
+ );
420
+ if (nestedDiff.hasChanges) {
421
+ modified.push(indexPath);
422
+ arrayChanges[i] = newElement;
423
+ hasArrayChanges = true;
424
+ } else {
425
+ arrayChanges[i] = oldElement;
426
+ }
427
+ } else if (Array.isArray(oldElement) && Array.isArray(newElement)) {
428
+ const nestedDiff = diffObjectDetailed(
429
+ oldElement,
430
+ newElement,
431
+ options
432
+ );
433
+ if (nestedDiff.hasChanges) {
434
+ modified.push(indexPath);
435
+ arrayChanges[i] = newElement;
436
+ hasArrayChanges = true;
437
+ } else {
438
+ arrayChanges[i] = oldElement;
439
+ }
440
+ } else if (!equalityFn(oldElement, newElement)) {
441
+ modified.push(indexPath);
442
+ arrayChanges[i] = newElement;
443
+ hasArrayChanges = true;
444
+ } else {
445
+ arrayChanges[i] = oldElement;
446
+ }
447
+ }
448
+ }
449
+ return {
450
+ changes: hasArrayChanges ? arrayChanges : {},
451
+ added,
452
+ deleted,
453
+ modified,
454
+ hasChanges: hasArrayChanges || deleted.length > 0
455
+ };
456
+ }
457
+ const collectDetailedPaths = (old, newVal, currentPath = "") => {
458
+ const result = {
459
+ added: [],
460
+ deleted: [],
461
+ modified: []
462
+ };
463
+ if (Array.isArray(old) && Array.isArray(newVal)) {
464
+ const maxLength = Math.max(old.length, newVal.length);
465
+ for (let i = 0; i < maxLength; i++) {
466
+ const indexPath = currentPath ? `${currentPath}[${i}]` : `[${i}]`;
467
+ if (i >= old.length) {
468
+ result.added.push(indexPath);
469
+ } else if (i >= newVal.length) {
470
+ result.deleted.push(indexPath);
471
+ } else {
472
+ const oldElement = old[i];
473
+ const newElement = newVal[i];
474
+ if (isObject(oldElement) && isObject(newElement)) {
475
+ const nested = collectDetailedPaths(
476
+ oldElement,
477
+ newElement,
478
+ indexPath
479
+ );
480
+ result.added.push(...nested.added);
481
+ result.deleted.push(...nested.deleted);
482
+ result.modified.push(...nested.modified);
483
+ } else if (Array.isArray(oldElement) && Array.isArray(newElement)) {
484
+ const nested = collectDetailedPaths(
485
+ oldElement,
486
+ newElement,
487
+ indexPath
488
+ );
489
+ result.added.push(...nested.added);
490
+ result.deleted.push(...nested.deleted);
491
+ result.modified.push(...nested.modified);
492
+ } else if (oldElement !== newElement) {
493
+ result.modified.push(indexPath);
494
+ }
495
+ }
496
+ }
497
+ return result;
498
+ }
499
+ if (isObject(old) && isObject(newVal)) {
500
+ const allKeys = /* @__PURE__ */ new Set([
501
+ ...Object.keys(old || {}),
502
+ ...Object.keys(newVal || {})
503
+ ]);
504
+ for (const key of allKeys) {
505
+ const oldValue = old?.[key];
506
+ const newValue = newVal?.[key];
507
+ const path = currentPath ? `${currentPath}.${key}` : key;
508
+ if (!(key in (old || {}))) {
509
+ result.added.push(path);
510
+ } else if (!(key in (newVal || {}))) {
511
+ result.deleted.push(path);
512
+ } else if (Array.isArray(oldValue) && Array.isArray(newValue)) {
513
+ if (!deepArrayEqual(oldValue, newValue)) {
514
+ const nested = collectDetailedPaths(oldValue, newValue, path);
515
+ result.added.push(...nested.added);
516
+ result.deleted.push(...nested.deleted);
517
+ result.modified.push(...nested.modified);
518
+ }
519
+ } else if (isObject(oldValue) && isObject(newValue)) {
520
+ const nested = collectDetailedPaths(oldValue, newValue, path);
521
+ result.added.push(...nested.added);
522
+ result.deleted.push(...nested.deleted);
523
+ result.modified.push(...nested.modified);
524
+ } else if (oldValue !== newValue) {
525
+ result.modified.push(path);
526
+ }
527
+ }
528
+ }
529
+ return result;
530
+ };
531
+ if (oldObj == null && newObj == null) {
532
+ return { changes: {}, added, deleted, modified, hasChanges: false };
533
+ }
534
+ if (oldObj == null) {
535
+ if (includeAdded && newObj) {
536
+ for (const key in newObj) {
537
+ added.push(key);
538
+ changes[key] = newObj[key];
539
+ }
540
+ }
541
+ return {
542
+ changes,
543
+ added,
544
+ deleted,
545
+ modified,
546
+ hasChanges: added.length > 0
547
+ };
548
+ }
549
+ if (newObj == null) {
550
+ if (includeDeleted) {
551
+ for (const key in oldObj) {
552
+ deleted.push(key);
553
+ changes[key] = void 0;
554
+ }
555
+ }
556
+ return {
557
+ changes,
558
+ added,
559
+ deleted,
560
+ modified,
561
+ hasChanges: deleted.length > 0
562
+ };
563
+ }
564
+ const processedKeys = /* @__PURE__ */ new Set();
565
+ for (const key in newObj) {
566
+ processedKeys.add(key);
567
+ const oldValue = oldObj[key];
568
+ const newValue = newObj[key];
569
+ if (!(key in oldObj)) {
570
+ if (includeAdded) {
571
+ added.push(key);
572
+ changes[key] = newValue;
573
+ }
574
+ continue;
575
+ }
576
+ let isDifferent = false;
577
+ if (Array.isArray(oldValue) && Array.isArray(newValue)) {
578
+ isDifferent = deepArrayComparison ? !deepArrayEqual(oldValue, newValue) : oldValue !== newValue;
579
+ if (isDifferent) {
580
+ const paths = collectDetailedPaths(oldValue, newValue, key);
581
+ added.push(...paths.added);
582
+ deleted.push(...paths.deleted);
583
+ modified.push(...paths.modified);
584
+ changes[key] = newValue;
585
+ }
586
+ } else if (isObject(oldValue) && isObject(newValue)) {
587
+ const nestedDiff = diffObject(oldValue, newValue, options);
588
+ isDifferent = Object.keys(nestedDiff).length > 0;
589
+ if (isDifferent) {
590
+ const paths = collectDetailedPaths(oldValue, newValue, key);
591
+ added.push(...paths.added);
592
+ deleted.push(...paths.deleted);
593
+ modified.push(...paths.modified);
594
+ changes[key] = nestedDiff;
595
+ }
596
+ } else {
597
+ isDifferent = !equalityFn(oldValue, newValue);
598
+ if (isDifferent) {
599
+ modified.push(key);
600
+ changes[key] = newValue;
601
+ }
602
+ }
603
+ }
604
+ for (const key in oldObj) {
605
+ if (!processedKeys.has(key)) {
606
+ deleted.push(key);
607
+ changes[key] = void 0;
608
+ }
609
+ }
610
+ return {
611
+ changes,
612
+ added,
613
+ deleted,
614
+ modified,
615
+ hasChanges: added.length > 0 || deleted.length > 0 || modified.length > 0
616
+ };
617
+ };
618
+ function isApplyDiff(value) {
619
+ if (value && (value.diff || value.changes) && (value.modified || value.deleted || value.hasChanges)) {
620
+ return true;
621
+ }
622
+ return false;
623
+ }
624
+ var applyDiff = (baseObj, option, keepRefParam) => {
625
+ if (!isApplyDiff(option)) {
626
+ const diff2 = option;
627
+ const shouldKeepRef2 = keepRefParam || false;
628
+ if (Array.isArray(baseObj) && Array.isArray(diff2)) {
629
+ const result3 = shouldKeepRef2 ? baseObj : [...baseObj];
630
+ if (diff2.length < result3.length) {
631
+ result3.length = diff2.length;
632
+ }
633
+ for (let i = 0; i < diff2.length; i++) {
634
+ const diffValue = diff2[i];
635
+ if (diffValue === void 0) {
636
+ continue;
637
+ }
638
+ if (isObject(result3[i]) && isObject(diffValue)) {
639
+ result3[i] = applyDiff(result3[i], diffValue, shouldKeepRef2);
640
+ } else if (Array.isArray(result3[i]) && Array.isArray(diffValue)) {
641
+ result3[i] = applyDiff(
642
+ result3[i],
643
+ diffValue,
644
+ shouldKeepRef2
645
+ );
646
+ } else {
647
+ result3[i] = diffValue;
648
+ }
649
+ }
650
+ return result3;
651
+ }
652
+ if (!isObject(baseObj)) return diff2;
653
+ if (!isObject(diff2)) return baseObj;
654
+ const result2 = shouldKeepRef2 ? baseObj : { ...baseObj };
655
+ for (const key in diff2) {
656
+ const diffValue = diff2[key];
657
+ if (diffValue === void 0) {
658
+ delete result2[key];
659
+ } else if (Array.isArray(result2[key]) && Array.isArray(diffValue)) {
660
+ result2[key] = applyDiff(result2[key], diffValue, shouldKeepRef2);
661
+ } else if (isObject(result2[key]) && isObject(diffValue)) {
662
+ result2[key] = applyDiff(result2[key], diffValue, shouldKeepRef2);
663
+ } else {
664
+ result2[key] = diffValue;
665
+ }
666
+ }
667
+ return result2;
668
+ }
669
+ const {
670
+ diff,
671
+ added = [],
672
+ deleted = [],
673
+ modified = [],
674
+ changes,
675
+ keepRef: keepRefOption
676
+ } = option;
677
+ const shouldKeepRef = keepRefParam !== void 0 ? keepRefParam : keepRefOption;
678
+ const diffToApply = changes || diff;
679
+ if (!diffToApply) return baseObj;
680
+ const addedSet = new Set(added);
681
+ const deletedSet = new Set(deleted);
682
+ const modifiedSet = new Set(modified);
683
+ const shouldApplyPath = (path) => {
684
+ if (added.length === 0 && deleted.length === 0 && modified.length === 0) {
685
+ return true;
686
+ }
687
+ const pathParts = path.split(/[.\[\]]+/).filter(Boolean);
688
+ for (let i = 0; i <= pathParts.length; i++) {
689
+ const partialPath = pathParts.slice(0, i).join(".");
690
+ const bracketPath = pathParts.slice(0, i).map((p, idx) => /^\d+$/.test(p) ? `[${p}]` : idx > 0 ? `.${p}` : p).join("");
691
+ if (addedSet.has(partialPath) || addedSet.has(bracketPath) || deletedSet.has(partialPath) || deletedSet.has(bracketPath) || modifiedSet.has(partialPath) || modifiedSet.has(bracketPath)) {
692
+ return true;
693
+ }
694
+ }
695
+ return false;
696
+ };
697
+ if (Array.isArray(baseObj) && Array.isArray(diffToApply)) {
698
+ const result2 = shouldKeepRef ? baseObj : [...baseObj];
699
+ result2.length = diffToApply.length;
700
+ for (let i = 0; i < diffToApply.length; i++) {
701
+ const indexPath = `[${i}]`;
702
+ const diffValue = diffToApply[i];
703
+ if (diffValue === void 0) {
704
+ continue;
705
+ }
706
+ if (!shouldApplyPath(indexPath)) {
707
+ continue;
708
+ }
709
+ if (isObject(result2[i]) && isObject(diffValue)) {
710
+ result2[i] = applyDiff(result2[i], diffValue, shouldKeepRef);
711
+ } else if (Array.isArray(result2[i]) && Array.isArray(diffValue)) {
712
+ result2[i] = applyDiff(
713
+ result2[i],
714
+ diffValue,
715
+ shouldKeepRef
716
+ );
717
+ } else {
718
+ result2[i] = diffValue;
719
+ }
720
+ }
721
+ return result2;
722
+ }
723
+ if (!isObject(baseObj)) return diffToApply;
724
+ if (!isObject(diffToApply)) return baseObj;
725
+ const result = shouldKeepRef ? baseObj : { ...baseObj };
726
+ for (const path of deleted) {
727
+ if (path.includes(".") || path.includes("[")) continue;
728
+ if (shouldApplyPath(path)) {
729
+ delete result[path];
730
+ }
731
+ }
732
+ for (const key in diffToApply) {
733
+ const diffValue = diffToApply[key];
734
+ if (!shouldApplyPath(key)) {
735
+ continue;
736
+ }
737
+ if (diffValue === void 0) {
738
+ delete result[key];
739
+ } else if (Array.isArray(result[key]) && Array.isArray(diffValue)) {
740
+ result[key] = applyDiff(result[key], diffValue, shouldKeepRef);
741
+ } else if (isObject(result[key]) && isObject(diffValue)) {
742
+ result[key] = applyDiff(result[key], diffValue, shouldKeepRef);
743
+ } else {
744
+ result[key] = diffValue;
745
+ }
746
+ }
747
+ return result;
748
+ };
749
+
750
+ // src/lib/object/selector.ts
751
+ var parseSelector = (selector, options = {}) => {
752
+ const { type = "auto", throwOnError = false } = options;
753
+ if (!selector || typeof selector !== "string") {
754
+ return [];
755
+ }
756
+ const segments = [];
757
+ let current = "";
758
+ let inBrackets = false;
759
+ let inQuotes = false;
760
+ let quoteChar = "";
761
+ let bracketContent = "";
762
+ let bracketDepth = 0;
763
+ const detectType = (str) => {
764
+ if (str.includes("..")) return "descendant";
765
+ if (str.includes("[?(")) return "filter";
766
+ if (str.includes("[:") || str.includes("[0:")) return "slice";
767
+ if (str.includes("[,") || str.includes("[0,1]")) return "union";
768
+ if (str.includes("[*]") || str.includes(".*.")) return "wildcard";
769
+ if (str.includes("[]")) return "array-wildcard";
770
+ if (str.includes("[") && str.includes("]")) return "bracket";
771
+ return "dot";
772
+ };
773
+ const actualType = type === "auto" ? detectType(selector) : type;
774
+ const parseBracketContent = (content) => {
775
+ const trimmed = content.trim();
776
+ if (trimmed === "*" || trimmed === "") {
777
+ return {
778
+ type: "wildcard",
779
+ value: trimmed === "" ? "[]" : "*",
780
+ raw: trimmed === "" ? "[]" : content
781
+ };
782
+ }
783
+ if (trimmed === "[]") {
784
+ return { type: "wildcard", value: "[]", raw: content };
785
+ }
786
+ if (/^-?\d+$/.test(trimmed)) {
787
+ return { type: "index", value: parseInt(trimmed, 10), raw: content };
788
+ }
789
+ if (trimmed.includes(":")) {
790
+ const parts = trimmed.split(":").map((p) => p.trim());
791
+ const start = parts[0] === "" ? 0 : parseInt(parts[0], 10);
792
+ const end = parts[1] === "" ? Infinity : parseInt(parts[1], 10);
793
+ if (isNaN(start) || isNaN(end)) {
794
+ if (throwOnError) throw new Error(`Invalid slice notation: ${content}`);
795
+ return { type: "wildcard", value: "*", raw: content };
796
+ }
797
+ return { type: "slice", value: [start, end], raw: content };
798
+ }
799
+ if (trimmed.includes(",")) {
800
+ const indices = trimmed.split(",").map((p) => {
801
+ const num = parseInt(p.trim(), 10);
802
+ return isNaN(num) ? -1 : num;
803
+ }).filter((n) => n >= 0);
804
+ if (indices.length === 0) {
805
+ if (throwOnError) throw new Error(`Invalid union notation: ${content}`);
806
+ return { type: "wildcard", value: "*", raw: content };
807
+ }
808
+ return { type: "union", value: indices, raw: content };
809
+ }
810
+ if (trimmed.startsWith("?(") && trimmed.endsWith(")")) {
811
+ const expr = trimmed.slice(2, -1);
812
+ try {
813
+ const filterFn = createFilterFunction(expr);
814
+ return { type: "filter", value: filterFn, raw: content };
815
+ } catch (error) {
816
+ if (throwOnError) throw error;
817
+ return { type: "wildcard", value: "*", raw: content };
818
+ }
819
+ }
820
+ if (trimmed.startsWith('"') && trimmed.endsWith('"') || trimmed.startsWith("'") && trimmed.endsWith("'")) {
821
+ return { type: "property", value: trimmed.slice(1, -1), raw: content };
822
+ }
823
+ return { type: "property", value: trimmed, raw: content };
824
+ };
825
+ for (let i = 0; i < selector.length; i++) {
826
+ const char = selector[i];
827
+ const nextChar = selector[i + 1];
828
+ if ((char === '"' || char === "'") && !inQuotes) {
829
+ inQuotes = true;
830
+ quoteChar = char;
831
+ continue;
832
+ } else if (char === quoteChar && inQuotes) {
833
+ inQuotes = false;
834
+ quoteChar = "";
835
+ if (!(char === '"' || char === "'")) {
836
+ if (inBrackets) {
837
+ bracketContent += char;
838
+ } else {
839
+ current += char;
840
+ }
841
+ }
842
+ continue;
843
+ }
844
+ if (inQuotes) {
845
+ if (inBrackets) {
846
+ bracketContent += char;
847
+ } else {
848
+ current += char;
849
+ }
850
+ continue;
851
+ }
852
+ if (char === "[" && !inBrackets) {
853
+ if (current) {
854
+ segments.push({ type: "property", value: current, raw: current });
855
+ current = "";
856
+ }
857
+ inBrackets = true;
858
+ bracketContent = "";
859
+ continue;
860
+ }
861
+ if (char === "]" && inBrackets && !inQuotes) {
862
+ inBrackets = false;
863
+ const segment = parseBracketContent(bracketContent);
864
+ segments.push(segment);
865
+ continue;
866
+ }
867
+ let lastDot = segments.length > 0 ? segments[segments.length - 1] : null;
868
+ if (char === "." && !inBrackets && !inQuotes) {
869
+ if (nextChar === ".") {
870
+ const l = selector.split("..")[0];
871
+ segments.push({ type: "property", value: l, raw: l });
872
+ segments.push({ type: "descendant", value: "..", raw: ".." });
873
+ i++;
874
+ } else if (current) {
875
+ if (current === "*") {
876
+ segments.push({ type: "wildcard", value: current, raw: current });
877
+ } else {
878
+ segments.push({ type: "property", value: current, raw: current });
879
+ }
880
+ current = "";
881
+ }
882
+ continue;
883
+ }
884
+ if (inBrackets) {
885
+ bracketContent += char;
886
+ } else {
887
+ if (lastDot && lastDot.type !== "descendant") {
888
+ current += char;
889
+ } else {
890
+ const l = selector.split(lastDot?.raw)[1];
891
+ if (l !== void 0) {
892
+ current = l;
893
+ } else {
894
+ current += char;
895
+ }
896
+ }
897
+ }
898
+ }
899
+ if (current) {
900
+ segments.push({ type: "property", value: current, raw: current });
901
+ }
902
+ return segments.map((segment) => {
903
+ if (segment.type === "property" && typeof segment.value === "string") {
904
+ if (/^-?\d+$/.test(segment.value)) {
905
+ const num = parseInt(segment.value, 10);
906
+ if (!isNaN(num)) {
907
+ return { ...segment, type: "index", value: num };
908
+ }
909
+ }
910
+ }
911
+ return segment;
912
+ });
913
+ };
914
+ var createFilterFunction = (expr) => {
915
+ const safeExpr = expr.replace(/@\.([a-zA-Z_$][\w$]*)/g, (_, prop) => `item.${prop}`).replace(/@/g, "item");
916
+ try {
917
+ return new Function("item", `return ${safeExpr}`);
918
+ } catch (error) {
919
+ throw new Error(`Invalid filter expression: ${expr}`);
920
+ }
921
+ };
922
+
923
+ // src/lib/object/merge.ts
924
+ var mergeIntoStructure = (target, selector, value) => {
925
+ const segments = parseSelector(selector);
926
+ let current = target;
927
+ for (let i = 0; i < segments.length; i++) {
928
+ const segment = segments[i];
929
+ const isLast = i === segments.length - 1;
930
+ switch (segment.type) {
931
+ case "property":
932
+ if (isLast) {
933
+ current[String(segment.value)] = value;
934
+ } else {
935
+ if (!current[String(segment.value)]) {
936
+ const nextSegment = segments[i + 1];
937
+ current[String(segment.value)] = nextSegment.type === "index" || nextSegment.type === "slice" || nextSegment.type === "union" || nextSegment.type === "wildcard" ? [] : {};
938
+ }
939
+ current = current[String(segment.value)];
940
+ }
941
+ break;
942
+ case "index":
943
+ if (!Array.isArray(current)) {
944
+ current = [];
945
+ }
946
+ const index = segment.value;
947
+ if (isLast) {
948
+ if (index >= current.length) {
949
+ for (let j = current.length; j <= index; j++) {
950
+ current.push(void 0);
951
+ }
952
+ }
953
+ current[index] = value;
954
+ } else {
955
+ if (!current[index]) {
956
+ const nextSegment = segments[i + 1];
957
+ current[index] = nextSegment.type === "index" || nextSegment.type === "slice" || nextSegment.type === "union" || nextSegment.type === "wildcard" ? [] : {};
958
+ }
959
+ current = current[index];
960
+ }
961
+ break;
962
+ case "wildcard":
963
+ if (Array.isArray(current)) {
964
+ if (isLast) {
965
+ for (let j = 0; j < current.length; j++) {
966
+ current[j] = value;
967
+ }
968
+ } else {
969
+ const nextSegment = segments[i + 1];
970
+ for (let j = 0; j < current.length; j++) {
971
+ if (!current[j]) {
972
+ current[j] = nextSegment.type === "index" || nextSegment.type === "slice" || nextSegment.type === "union" || nextSegment.type === "wildcard" ? [] : {};
973
+ }
974
+ }
975
+ if (current.length > 0) {
976
+ current = current[0];
977
+ }
978
+ }
979
+ }
980
+ break;
981
+ }
982
+ }
983
+ };
984
+
985
+ // src/lib/object/getter-setter.ts
986
+ function get(obj, selector, options = {}) {
987
+ const {
988
+ preserveStructure,
989
+ multiple,
990
+ throwOnError = false,
991
+ defaultValue,
992
+ maxDepth = 20
993
+ } = options;
994
+ if (!obj || typeof obj !== "object") {
995
+ return defaultValue;
996
+ }
997
+ if (!selector) {
998
+ return obj;
999
+ }
1000
+ if (Array.isArray(selector)) {
1001
+ if (preserveStructure) {
1002
+ const result2 = {};
1003
+ for (const sel of selector) {
1004
+ const value = get(obj, sel, { ...options, preserveStructure: false });
1005
+ if (value !== void 0) {
1006
+ mergeIntoStructure(result2, sel, value);
1007
+ }
1008
+ }
1009
+ return result2;
1010
+ } else {
1011
+ return selector.map(
1012
+ (sel) => get(obj, sel, { ...options, preserveStructure: false })
1013
+ );
1014
+ }
1015
+ }
1016
+ const segments = parseSelector(selector, { ...options, throwOnError });
1017
+ if (segments.length === 0) {
1018
+ return obj;
1019
+ }
1020
+ if (typeof preserveStructure === "undefined" || preserveStructure === false) {
1021
+ const v = ValueOfKey(obj, selector);
1022
+ if (multiple === false && Array.isArray(v)) {
1023
+ return v[0];
1024
+ }
1025
+ if (v === void 0 && defaultValue !== void 0) {
1026
+ return defaultValue;
1027
+ }
1028
+ return v;
1029
+ }
1030
+ const result = traverseStructure(obj, segments, 0, maxDepth);
1031
+ if (result === void 0 && defaultValue !== void 0) {
1032
+ return defaultValue;
1033
+ }
1034
+ return result;
1035
+ }
1036
+ function set(_obj, first, second, third, fourth) {
1037
+ let obj = deepClone(_obj);
1038
+ const params = [];
1039
+ if (typeof first !== "undefined") params.push(first);
1040
+ if (typeof second !== "undefined") params.push(second);
1041
+ if (typeof third !== "undefined") params.push(third);
1042
+ if (typeof fourth !== "undefined") params.push(fourth);
1043
+ if (isPrimitive(obj)) {
1044
+ if (typeof first === "function") {
1045
+ return first(obj);
1046
+ }
1047
+ return first;
1048
+ }
1049
+ if (params.length === 1) {
1050
+ if (typeof params[0] === "function") {
1051
+ return updateWithCallBack(obj, params[0]);
1052
+ }
1053
+ if (Array.isArray(params[0])) {
1054
+ if (Array.isArray(obj)) {
1055
+ if (first.length === 0) {
1056
+ for (let i = 0; i < obj.length; i++) {
1057
+ obj.pop();
1058
+ }
1059
+ } else {
1060
+ const diff = diffObjectDetailed([...obj], [...params[0]]);
1061
+ if (diff.hasChanges) {
1062
+ applyDiff(obj, [...params[0]], true);
1063
+ }
1064
+ return obj;
1065
+ }
1066
+ }
1067
+ } else if (typeof params[0] === "object" && !Array.isArray(params[0])) {
1068
+ if (typeof obj === "object" && !Array.isArray(obj)) {
1069
+ applyDiff(obj, params[0], true);
1070
+ }
1071
+ } else {
1072
+ obj = params[0];
1073
+ }
1074
+ return obj;
1075
+ }
1076
+ if (Array.isArray(obj)) {
1077
+ if (typeof first === "string" && (isArrayOfString(second) || typeof second === "string") && params.length === 3) {
1078
+ if (Array.isArray(second)) {
1079
+ for (let i = 0; i < second.length; i++) {
1080
+ setValueAtPath(obj, first, third, second[i]);
1081
+ }
1082
+ return obj;
1083
+ }
1084
+ return setValueAtPath(obj, first, third, second);
1085
+ }
1086
+ if (typeof first === "string" && typeof second === "function" && params.length === 2) {
1087
+ return setValueAtPath(obj, first, second);
1088
+ }
1089
+ }
1090
+ if ((typeof first === "string" || typeof first === "number") && (params.length === 2 || params.length === 3)) {
1091
+ if (isRangeObject(second)) {
1092
+ return setValueBetweenRange(
1093
+ obj,
1094
+ first,
1095
+ second,
1096
+ third
1097
+ );
1098
+ }
1099
+ if (typeof first === "number") {
1100
+ if (typeof third !== "undefined") {
1101
+ return setValueAtPath(obj, `[${first}].${second}`, third);
1102
+ } else {
1103
+ return setValueAtPath(obj, `[${first}]`, second, third);
1104
+ }
1105
+ }
1106
+ if (typeof second === "number" && typeof third !== "undefined") {
1107
+ return setValueAtIndex(obj, first, second, third);
1108
+ }
1109
+ if (Array.isArray(second) && second.length > 0 && second.every((s) => typeof s === "number")) {
1110
+ return setValueWithIndices(obj, first, second, third);
1111
+ }
1112
+ if (typeof third !== "undefined" && typeof second === "function") {
1113
+ return setValueWithFilter(obj, first, second, third);
1114
+ }
1115
+ return setValueAtPath(obj, first, second, third);
1116
+ }
1117
+ if (typeof first === "string" && typeof second === "number") {
1118
+ if (params.length === 3) {
1119
+ return setValueAtIndex(obj, first, second, third);
1120
+ } else if (params.length === 4) {
1121
+ return setIndexWithSubPath(
1122
+ obj,
1123
+ first,
1124
+ second,
1125
+ third,
1126
+ fourth
1127
+ );
1128
+ }
1129
+ }
1130
+ if (typeof first === "string" && Array.isArray(second)) {
1131
+ if (params.length === 3) {
1132
+ return setValueWithIndices(obj, first, second, third);
1133
+ } else if (params.length === 4) {
1134
+ return setValueWithIndicesWithSubPath(
1135
+ obj,
1136
+ first,
1137
+ second,
1138
+ third,
1139
+ fourth
1140
+ );
1141
+ }
1142
+ }
1143
+ if (typeof first === "string" && typeof second === "object" && !Array.isArray(second) && second !== null) {
1144
+ const range = second;
1145
+ if ("from" in range || "to" in range) {
1146
+ if (params.length === 3) {
1147
+ return setValueBetweenRange(obj, first, range, third);
1148
+ } else if (params.length === 4) {
1149
+ return setValueBetweenRangeWithSubPath(
1150
+ obj,
1151
+ first,
1152
+ range,
1153
+ third,
1154
+ fourth
1155
+ );
1156
+ }
1157
+ }
1158
+ }
1159
+ if (typeof first === "object" && !Array.isArray(first) && params.length === 1) {
1160
+ return applyDiff(obj, first, true);
1161
+ }
1162
+ if (typeof first === "string" && typeof second === "object" && !Array.isArray(second) && params.length === 2) {
1163
+ return mergeUpdateAtPath(obj, first, second);
1164
+ }
1165
+ if (typeof first === "string" && typeof second === "function") {
1166
+ if (params.length === 3) {
1167
+ return setValueWithFilter(
1168
+ obj,
1169
+ first,
1170
+ second,
1171
+ third
1172
+ );
1173
+ } else if (params.length === 4) {
1174
+ return setValueWithFilterWithSubPath(
1175
+ obj,
1176
+ first,
1177
+ second,
1178
+ third,
1179
+ fourth
1180
+ );
1181
+ }
1182
+ }
1183
+ if (typeof first === "function" && typeof second === "string") {
1184
+ if (params.length === 3) {
1185
+ return setArrayValueWithFilter(
1186
+ obj,
1187
+ first,
1188
+ second,
1189
+ third
1190
+ );
1191
+ } else if (params.length === 4) {
1192
+ return setValueWithFilterWithSubPath(
1193
+ obj,
1194
+ second,
1195
+ first,
1196
+ third,
1197
+ fourth
1198
+ );
1199
+ }
1200
+ }
1201
+ if (Array.isArray(first)) {
1202
+ if (params.length === 2 && typeof second === "object" && !Array.isArray(second)) {
1203
+ return setValueWithArraySelectors(obj, first, second);
1204
+ } else if (params.length === 2) {
1205
+ return setValueWithArraySelectors(obj, first, second);
1206
+ }
1207
+ }
1208
+ throw new Error(`Invalid set parameters: ${JSON.stringify(params)}`);
1209
+ }
1210
+ function handleFunctionParams(selector, data, value, isArray2 = false) {
1211
+ const paths = parseSelector(selector);
1212
+ if (paths.length === 0) return value;
1213
+ const isWildcard = paths[paths.length - 1].type === "wildcard";
1214
+ const containWildcard = paths.some((path) => path.type === "wildcard") && Array.isArray(data);
1215
+ let finalValue;
1216
+ if (isWildcard || containWildcard && isArray2 || containWildcard && paths.length === 2) {
1217
+ if (Array.isArray(data)) {
1218
+ for (let i = 0; i < data.length; i++) {
1219
+ const v = typeof value === "function" ? value(data[i]) : typeof data[i] === "object" ? applyDiff(data[i], value, true) : value;
1220
+ if (!finalValue) finalValue = [];
1221
+ finalValue.push(v);
1222
+ }
1223
+ }
1224
+ }
1225
+ if (!isWildcard && !finalValue) {
1226
+ finalValue = typeof value === "function" ? value(data) : value;
1227
+ }
1228
+ return finalValue;
1229
+ }
1230
+ function isRangeObject(obj) {
1231
+ return typeof obj === "object" && obj !== null && "from" in obj && "to" in obj && typeof obj.from === "number" && typeof obj.to === "number" && obj.from < obj.to && obj.from >= 0 && obj.to > 0;
1232
+ }
1233
+ function isArrayOfString(value) {
1234
+ return Array.isArray(value) && value.every((item) => typeof item === "string");
1235
+ }
1236
+ function setValueAtPath(obj, selector, value, subPath) {
1237
+ const paths = parseSelector(selector);
1238
+ let target = ValueOfKey(obj, selector, {
1239
+ paths,
1240
+ createMissing: true
1241
+ });
1242
+ let get_value;
1243
+ if (subPath) {
1244
+ if (typeof value === "function") {
1245
+ get_value = get(target, subPath);
1246
+ }
1247
+ }
1248
+ const data = subPath ? get_value : target;
1249
+ const finalValue = handleFunctionParams(
1250
+ selector,
1251
+ data,
1252
+ value,
1253
+ Array.isArray(obj)
1254
+ );
1255
+ if (subPath) {
1256
+ const result = setAtPath(obj, `${selector}.${subPath}`, finalValue, {
1257
+ createMissing: true
1258
+ });
1259
+ return result;
1260
+ } else {
1261
+ const r = setAtPath(obj, selector, finalValue, { createMissing: true });
1262
+ return r;
1263
+ }
1264
+ }
1265
+ function setValueAtIndex(obj, selector, index, value) {
1266
+ const target = ValueOfKey(obj, selector, { createMissing: true });
1267
+ if (!Array.isArray(target)) {
1268
+ throw new Error(`Target at ${selector} is not an array ${index}`);
1269
+ }
1270
+ const target_copy = structuredClone(target);
1271
+ const finalValue = handleFunctionParams(selector, target_copy[index], value);
1272
+ if (index < 0) {
1273
+ const actualIndex = target.length + index;
1274
+ if (actualIndex < 0) {
1275
+ throw new Error(`Index ${index} is out of bounds`);
1276
+ }
1277
+ return setAtPath(obj, `${selector}[${actualIndex}]`, finalValue, {
1278
+ createMissing: true
1279
+ });
1280
+ }
1281
+ return setAtPath(obj, `${selector}[${index}]`, finalValue, {
1282
+ createMissing: true
1283
+ });
1284
+ }
1285
+ var setIndexWithSubPath = (obj, selector, index, subPath, value) => {
1286
+ if (typeof subPath === "function") {
1287
+ return setValueAtPath(obj, `${selector}[${index}]`, subPath);
1288
+ }
1289
+ if (typeof subPath === "string") {
1290
+ return setValueAtPath(obj, `${selector}[${index}]`, value, subPath);
1291
+ }
1292
+ return null;
1293
+ };
1294
+ var setValueWithIndices = (obj, selector, indices, value) => {
1295
+ const target = ValueOfKey(obj, selector);
1296
+ if (!Array.isArray(target)) {
1297
+ throw new Error(`Target at ${selector} is not an array`);
1298
+ }
1299
+ for (const index of indices) {
1300
+ if (typeof index === "number") {
1301
+ setValueAtIndex(obj, selector, index, value);
1302
+ } else if (typeof index === "string") {
1303
+ setValueAtPath(obj, selector, value, index);
1304
+ }
1305
+ }
1306
+ return obj;
1307
+ };
1308
+ var setValueWithIndicesWithSubPath = (obj, selector, indices, subPath, value) => {
1309
+ const updater = (prev) => {
1310
+ const newValue = typeof value === "function" ? value(prev ? ValueOfKey(prev, subPath) : void 0) : value;
1311
+ const result = prev ? { ...prev } : {};
1312
+ setAtPath(result, subPath, newValue);
1313
+ return result;
1314
+ };
1315
+ return setValueWithIndices(obj, selector, indices, updater);
1316
+ };
1317
+ function setValueBetweenRange(obj, selector, range, value) {
1318
+ const target = ValueOfKey(obj, selector);
1319
+ if (!Array.isArray(target)) {
1320
+ throw new Error(`Target at ${selector} is not an array`);
1321
+ }
1322
+ const from = range.from ?? 0;
1323
+ const to = range.to ?? target.length - 1;
1324
+ const by = range.by ?? 1;
1325
+ const indices = [];
1326
+ for (let i = from; i <= to; i += by) {
1327
+ if (i >= 0 && i < target.length) {
1328
+ indices.push(i);
1329
+ }
1330
+ }
1331
+ return setValueWithIndices(obj, selector, indices, value);
1332
+ }
1333
+ var setValueBetweenRangeWithSubPath = (obj, selector, range, subPath, value) => {
1334
+ const updater = (prev) => {
1335
+ const newValue = typeof value === "function" ? value(prev ? ValueOfKey(prev, subPath) : void 0) : value;
1336
+ const result = prev ? { ...prev } : {};
1337
+ setAtPath(result, subPath, newValue);
1338
+ return result;
1339
+ };
1340
+ return setValueBetweenRange(obj, selector, range, updater);
1341
+ };
1342
+ function setValueWithFilter(obj, selector, filterFn, value) {
1343
+ const target = ValueOfKey(obj, selector);
1344
+ if (!Array.isArray(target)) {
1345
+ throw new Error(`Target at ${selector} is not an array`);
1346
+ }
1347
+ const indices = [];
1348
+ const target_copy = [...target];
1349
+ target.forEach((item, index) => {
1350
+ if (filterFn(item, index)) {
1351
+ indices.push(index);
1352
+ }
1353
+ });
1354
+ return setValueWithIndices(obj, selector, indices, value);
1355
+ }
1356
+ function setArrayValueWithFilter(obj, filterFn, selector, value) {
1357
+ let target = obj;
1358
+ if (!Array.isArray(target)) {
1359
+ throw new Error(`Target at ${selector} is not an array`);
1360
+ }
1361
+ const indices = [];
1362
+ const target_copy = [...target];
1363
+ target.forEach((item, index) => {
1364
+ const n = setAtPath(item, selector, value, { createMissing: true });
1365
+ item = n;
1366
+ });
1367
+ return target;
1368
+ }
1369
+ function setValueWithFilterWithSubPath(obj, selector, filterFn, subPath, value) {
1370
+ const updater = (prev) => {
1371
+ const newValue = typeof value === "function" ? value(prev ? ValueOfKey(prev, subPath) : void 0) : value;
1372
+ const result = prev ? { ...prev } : {};
1373
+ setAtPath(result, subPath, newValue);
1374
+ return result;
1375
+ };
1376
+ return setValueWithFilter(obj, selector, filterFn, updater);
1377
+ }
1378
+ function mergeUpdateAtPath(obj, selector, updates) {
1379
+ const current = ValueOfKey(obj, selector, { createMissing: true });
1380
+ const merged = applyDiff(current || {}, updates, true);
1381
+ return setAtPath(obj, selector, merged, { createMissing: true });
1382
+ }
1383
+ function setValueWithArraySelectors(obj, selectors, value) {
1384
+ if (typeof value === "object" && !Array.isArray(value) && value !== null) {
1385
+ for (const [path, val] of Object.entries(value)) {
1386
+ if (selectors.includes(path)) {
1387
+ setAtPath(obj, path, val, { createMissing: true });
1388
+ }
1389
+ }
1390
+ } else {
1391
+ for (const selector of selectors) {
1392
+ const finalValue = handleFunctionParams(
1393
+ selector,
1394
+ ValueOfKey(obj, selector),
1395
+ value
1396
+ );
1397
+ setAtPath(obj, selector, finalValue, { createMissing: true });
1398
+ }
1399
+ }
1400
+ return obj;
1401
+ }
1402
+ function ValueOfKey(obj, selector, options = {}) {
1403
+ const { createMissing = false, add = false, debug = false } = options;
1404
+ const segments = parseSelector(selector);
1405
+ let current = obj;
1406
+ let updateEvenIfNotlast = false;
1407
+ let chained_property = "";
1408
+ const stringify = selector;
1409
+ if (typeof current === "object" && !Array.isArray(current) && stringify.length > 0) {
1410
+ if (current[stringify]) {
1411
+ current = current[stringify];
1412
+ return current;
1413
+ }
1414
+ }
1415
+ for (let i = 0; i < segments.length; i++) {
1416
+ const segment = segments[i];
1417
+ const isLast = segments.length > 1 ? i === segments.length - 1 : false;
1418
+ if (current === null && !createMissing) {
1419
+ return void 0;
1420
+ }
1421
+ const nextSegment = segments[i + 1];
1422
+ switch (segment.type) {
1423
+ case "property":
1424
+ if (current && typeof current === "object") {
1425
+ if (Array.isArray(current)) {
1426
+ if (typeof segment.value === "number") {
1427
+ const index = segment.value;
1428
+ if (createMissing && index >= current.length) {
1429
+ for (let j = current.length; j <= index; j++) {
1430
+ current.push(void 0);
1431
+ }
1432
+ }
1433
+ if (createMissing && (current[index] === null || current[index] === void 0) && (!isLast || updateEvenIfNotlast)) {
1434
+ if (nextSegment) {
1435
+ current[index] = nextSegment.type === "index" || nextSegment.type === "slice" || nextSegment.type === "union" || nextSegment.type === "wildcard" ? [] : {};
1436
+ } else {
1437
+ current[index] = null;
1438
+ }
1439
+ updateEvenIfNotlast = false;
1440
+ }
1441
+ current = current[index];
1442
+ if (nextSegment) {
1443
+ updateEvenIfNotlast = true;
1444
+ continue;
1445
+ }
1446
+ } else if (add) {
1447
+ current.push({
1448
+ [String(segment.value)]: null
1449
+ });
1450
+ } else {
1451
+ current = current.map((item) => item[String(segment.value)]);
1452
+ }
1453
+ if (nextSegment) {
1454
+ continue;
1455
+ }
1456
+ return filterDefined(current);
1457
+ } else {
1458
+ if (current[chained_property] && chained_property.split(".").length >= 2) {
1459
+ current = current[chained_property];
1460
+ continue;
1461
+ }
1462
+ if (createMissing && (current[String(segment.value)] === null || current[String(segment.value)] === void 0) && (!isLast || updateEvenIfNotlast)) {
1463
+ if (nextSegment) {
1464
+ current[String(segment.value)] = nextSegment.type === "index" || nextSegment.type === "slice" || nextSegment.type === "union" || nextSegment.type === "wildcard" ? [] : {};
1465
+ } else {
1466
+ current[String(segment.value)] = null;
1467
+ }
1468
+ updateEvenIfNotlast = false;
1469
+ current = current[String(segment.value)];
1470
+ if (nextSegment) {
1471
+ updateEvenIfNotlast = true;
1472
+ continue;
1473
+ }
1474
+ }
1475
+ if (!current) {
1476
+ current = { [String(segment.value)]: null };
1477
+ } else {
1478
+ if (!current[String(segment.value)] && createMissing) {
1479
+ current[String(segment.value)] = null;
1480
+ }
1481
+ current = current[String(segment.value)];
1482
+ }
1483
+ if (nextSegment) {
1484
+ continue;
1485
+ }
1486
+ }
1487
+ } else if (createMissing) {
1488
+ current = {};
1489
+ current[String(segment.value)] = nextSegment.type === "index" || nextSegment.type === "slice" || nextSegment.type === "union" || nextSegment.type === "wildcard" || options.type === "array" ? [] : {};
1490
+ current = current[String(segment.value)];
1491
+ } else {
1492
+ return void 0;
1493
+ }
1494
+ break;
1495
+ case "index":
1496
+ case "wildcard":
1497
+ if (Array.isArray(current)) {
1498
+ if (segment.type === "index") {
1499
+ const index = segment.value;
1500
+ if (index < 0) {
1501
+ current = current[current.length - Math.abs(index)];
1502
+ continue;
1503
+ }
1504
+ if (createMissing && (index >= current.length || current[index] == null || current[index] == void 0) && !isLast) {
1505
+ for (let j = current.length; j <= index; j++) {
1506
+ current.push(void 0);
1507
+ }
1508
+ if (nextSegment) {
1509
+ current[index] = nextSegment.type === "index" || nextSegment.type === "slice" || nextSegment.type === "union" || nextSegment.type === "wildcard" ? [] : {};
1510
+ }
1511
+ }
1512
+ current = current[index];
1513
+ } else {
1514
+ if (!isLast) {
1515
+ continue;
1516
+ }
1517
+ }
1518
+ } else if (createMissing) {
1519
+ const nextSegment2 = segments[i + 1];
1520
+ current = [];
1521
+ const index = segment.value;
1522
+ for (let j = 0; j <= index; j++) {
1523
+ current.push(void 0);
1524
+ }
1525
+ current[index] = nextSegment2.type === "index" || nextSegment2.type === "slice" || nextSegment2.type === "union" || nextSegment2.type === "wildcard" || options.type === "array" ? [] : {};
1526
+ current = current[index];
1527
+ } else {
1528
+ if (segment.type === "index" && typeof current === "object") {
1529
+ if (current && current[String(segment.value)] !== void 0) {
1530
+ current = current[String(segment.value)];
1531
+ continue;
1532
+ }
1533
+ }
1534
+ if (typeof current === "object") {
1535
+ const values = Object.values(current);
1536
+ current = values;
1537
+ continue;
1538
+ }
1539
+ return void 0;
1540
+ }
1541
+ break;
1542
+ default:
1543
+ return void 0;
1544
+ }
1545
+ }
1546
+ return filterDefined(current);
1547
+ }
1548
+ function filterDefined(obj) {
1549
+ if (Array.isArray(obj)) {
1550
+ return obj.filter((item) => typeof item !== "undefined");
1551
+ }
1552
+ return obj;
1553
+ }
1554
+ var setAtPath = (obj, selector, value, options = {}) => {
1555
+ if (selector === "[*]") {
1556
+ return applyDiff(obj, value, true);
1557
+ }
1558
+ const { createMissing = true } = options;
1559
+ const segments = parseSelector(selector);
1560
+ if (segments.length === 0) {
1561
+ return obj;
1562
+ }
1563
+ const lastSegment = segments[segments.length - 1];
1564
+ let current = obj;
1565
+ for (let i = 0; i < segments.length - 1; i++) {
1566
+ const segment = segments[i];
1567
+ if (current == null) {
1568
+ if (!createMissing) return obj;
1569
+ throw new Error(`Cannot navigate through null/undefined at segment ${i}`);
1570
+ }
1571
+ const nextSegment = segments[i + 1];
1572
+ const shouldBeArray = nextSegment.type === "index" || nextSegment.type === "slice" || nextSegment.type === "union" || nextSegment.type === "wildcard";
1573
+ if (segment.type === "property") {
1574
+ if (Array.isArray(current) && typeof typeof segment.value === "number") {
1575
+ const index = segment.value;
1576
+ if (index < 0) {
1577
+ throw new Error(`Negative index ${index} not allowed`);
1578
+ }
1579
+ if (index >= current.length && createMissing) {
1580
+ for (let j = current.length; j <= index; j++) {
1581
+ current.push(void 0);
1582
+ }
1583
+ }
1584
+ if ((current[index] === null || current[index] === void 0) && createMissing) {
1585
+ current[index] = shouldBeArray ? [] : {};
1586
+ }
1587
+ current = current[index];
1588
+ } else {
1589
+ if ((current[String(segment.value)] === null || current[String(segment.value)] === void 0) && createMissing) {
1590
+ current[String(segment.value)] = shouldBeArray ? [] : {};
1591
+ }
1592
+ if (typeof current === "object" && !Array.isArray(current)) {
1593
+ current = current[String(segment.value)];
1594
+ }
1595
+ }
1596
+ if (nextSegment) {
1597
+ continue;
1598
+ }
1599
+ break;
1600
+ } else if (segment.type === "index" || segment.type === "wildcard") {
1601
+ if (!Array.isArray(current)) {
1602
+ if (!createMissing) return obj;
1603
+ current = [];
1604
+ }
1605
+ if (segment.type === "index") {
1606
+ const index = segment.value;
1607
+ if (index < 0) {
1608
+ throw new Error(`Negative index ${index} not allowed`);
1609
+ }
1610
+ if (index >= current.length && createMissing) {
1611
+ for (let j = current.length; j <= index; j++) {
1612
+ current.push(void 0);
1613
+ }
1614
+ }
1615
+ if ((current[index] === null || current[index] === void 0) && createMissing) {
1616
+ current[index] = shouldBeArray ? [] : void 0;
1617
+ }
1618
+ current = current[index];
1619
+ }
1620
+ if (nextSegment) {
1621
+ continue;
1622
+ }
1623
+ break;
1624
+ } else {
1625
+ throw new Error(`Invalid segment type for set: ${segment.type}`);
1626
+ }
1627
+ }
1628
+ switch (lastSegment.type) {
1629
+ case "property":
1630
+ if (Array.isArray(current) && typeof lastSegment.value === "number") {
1631
+ const index2 = lastSegment.value;
1632
+ if (index2 < 0) {
1633
+ throw new Error(`Negative index ${index2} not allowed`);
1634
+ }
1635
+ if (index2 >= current.length) {
1636
+ for (let j = current.length; j <= index2; j++) {
1637
+ current.push(void 0);
1638
+ }
1639
+ }
1640
+ if (Array.isArray(value)) {
1641
+ current[index2] = applyDiff(
1642
+ structuredClone(current[index2]),
1643
+ value[index2],
1644
+ true
1645
+ );
1646
+ } else {
1647
+ current[index2] = value;
1648
+ }
1649
+ } else {
1650
+ if (!current) current = {};
1651
+ if (Array.isArray(current)) {
1652
+ const paths = selector.split(".");
1653
+ let ob;
1654
+ if (paths.length >= 2) {
1655
+ paths.shift();
1656
+ for (let i = 0; i < current.length; i++) {
1657
+ if (Array.isArray(value)) {
1658
+ ob = fromPath(paths.join("."), value[i]);
1659
+ current[i] = typeof current[i] === "object" ? applyDiff(current[i], ob, true) : ob;
1660
+ } else {
1661
+ ob = fromPath(paths.join("."), value);
1662
+ current[i] = typeof current[i] === "object" ? applyDiff(current[i], ob, true) : ob;
1663
+ }
1664
+ }
1665
+ } else {
1666
+ ob = {
1667
+ [String(lastSegment.value)]: value
1668
+ };
1669
+ }
1670
+ } else {
1671
+ if (Array.isArray(value) && value.length === 0) {
1672
+ if (typeof current[String(lastSegment.value)] === "undefined") {
1673
+ current[String(lastSegment.value)] = [];
1674
+ } else {
1675
+ current[String(lastSegment.value)] = [];
1676
+ }
1677
+ } else {
1678
+ current[String(lastSegment.value)] = value;
1679
+ }
1680
+ }
1681
+ }
1682
+ break;
1683
+ case "index":
1684
+ case "wildcard":
1685
+ if (!Array.isArray(current)) {
1686
+ throw new Error(`Cannot use index on non-array for final segment`);
1687
+ }
1688
+ const index = lastSegment.value;
1689
+ if (lastSegment.type === "index") {
1690
+ if (index < 0) {
1691
+ throw new Error(`Negative index ${index} not allowed`);
1692
+ }
1693
+ if (index >= current.length) {
1694
+ for (let j = current.length; j <= index; j++) {
1695
+ current.push(void 0);
1696
+ }
1697
+ }
1698
+ if (Array.isArray(value)) {
1699
+ if (typeof current[index] === typeof value[index]) {
1700
+ try {
1701
+ current[index] = applyDiff(
1702
+ deepClone(current[index]),
1703
+ value[index],
1704
+ true
1705
+ );
1706
+ } catch (e) {
1707
+ throw Error("expected on array");
1708
+ }
1709
+ } else {
1710
+ current[index] = value;
1711
+ }
1712
+ } else {
1713
+ current[index] = value;
1714
+ }
1715
+ } else if (lastSegment.type === "wildcard") {
1716
+ if (Array.isArray(value)) {
1717
+ for (let i = 0; i < current.length; i++) {
1718
+ if (typeof current[i] === "object") {
1719
+ current[i] = applyDiff(current[i], value[i], true);
1720
+ } else {
1721
+ current[i] = value[i];
1722
+ }
1723
+ }
1724
+ } else {
1725
+ for (let i = 0; i < current.length; i++) {
1726
+ if (typeof current[i] === "object") {
1727
+ current[i] = applyDiff(current[i], value, true);
1728
+ } else {
1729
+ current[i] = value;
1730
+ }
1731
+ }
1732
+ }
1733
+ }
1734
+ break;
1735
+ default:
1736
+ throw new Error(
1737
+ `Invalid final segment type for set: ${lastSegment.type}`
1738
+ );
1739
+ }
1740
+ return obj;
1741
+ };
1742
+ var fromPath = (path, value) => {
1743
+ const segments = parseSelector(path);
1744
+ if (segments.length === 0) {
1745
+ return value;
1746
+ }
1747
+ let result = value;
1748
+ for (let i = segments.length - 1; i >= 0; i--) {
1749
+ const segment = segments[i];
1750
+ if (segment.type === "property") {
1751
+ result = { [String(segment.value)]: result };
1752
+ } else if (segment.type === "index") {
1753
+ const index = parseInt(String(segment.value));
1754
+ const arr = [];
1755
+ arr[index] = result;
1756
+ result = arr;
1757
+ } else if (segment.type === "wildcard") {
1758
+ if (Array.isArray(result)) {
1759
+ result = result;
1760
+ } else {
1761
+ result = [result];
1762
+ }
1763
+ } else if (segment.type === "slice") {
1764
+ if (!Array.isArray(result)) {
1765
+ result = [result];
1766
+ }
1767
+ } else if (segment.type === "union") {
1768
+ if (!Array.isArray(result)) {
1769
+ result = [result];
1770
+ }
1771
+ } else if (segment.type === "filter") {
1772
+ if (!Array.isArray(result)) {
1773
+ result = [result];
1774
+ }
1775
+ } else if (segment.type === "descendant") {
1776
+ result = result;
1777
+ }
1778
+ }
1779
+ return result;
1780
+ };
1781
+ var updateWithCallBack = (obj, updater) => {
1782
+ const newValue = updater(obj);
1783
+ const result = applyDiff(obj, newValue, true);
1784
+ return result;
1785
+ };
1786
+
1787
+ // src/lib/object/transform.ts
1788
+ function mapValues(obj, fn) {
1789
+ if (!isObject(obj)) {
1790
+ return {};
1791
+ }
1792
+ const result = {};
1793
+ for (const key in obj) {
1794
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
1795
+ result[key] = fn(obj[key], key, obj);
1796
+ }
1797
+ }
1798
+ return result;
1799
+ }
1800
+ function mapKeys(obj, fn) {
1801
+ if (!isObject(obj)) {
1802
+ return {};
1803
+ }
1804
+ const result = {};
1805
+ for (const key in obj) {
1806
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
1807
+ const newKey = fn(key, obj[key], obj);
1808
+ result[newKey] = obj[key];
1809
+ }
1810
+ }
1811
+ return result;
1812
+ }
1813
+ function camelCaseKeys(obj, options = { deep: true }) {
1814
+ if (!isObject(obj)) {
1815
+ return obj;
1816
+ }
1817
+ if (Array.isArray(obj)) {
1818
+ return options.deep ? obj.map((item) => camelCaseKeys(item, options)) : obj;
1819
+ }
1820
+ const result = {};
1821
+ for (const key in obj) {
1822
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
1823
+ const value = obj[key];
1824
+ const camelKey = key.replace(/[-_]([a-z])/g, (_, c) => c.toUpperCase()).replace(/^([A-Z])/, (c) => c.toLowerCase());
1825
+ result[camelKey] = options.deep && isObject(value) ? camelCaseKeys(value, options) : value;
1826
+ }
1827
+ }
1828
+ return result;
1829
+ }
1830
+ function snakeCaseKeys(obj, options = { deep: true }) {
1831
+ if (!isObject(obj)) {
1832
+ return obj;
1833
+ }
1834
+ if (Array.isArray(obj)) {
1835
+ return options.deep ? obj.map((item) => snakeCaseKeys(item, options)) : obj;
1836
+ }
1837
+ const result = {};
1838
+ for (const key in obj) {
1839
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
1840
+ const value = obj[key];
1841
+ const snakeKey = key.replace(/[-]([a-z])/g, (_, c) => `_${c}`).replace(/([a-z0-9])([A-Z])/g, "$1_$2").toLowerCase();
1842
+ result[snakeKey] = options.deep && isObject(value) ? snakeCaseKeys(value, options) : value;
1843
+ }
1844
+ }
1845
+ return result;
1846
+ }
1847
+ function kebabCaseKeys(obj, options = { deep: true }) {
1848
+ if (!isObject(obj)) {
1849
+ return obj;
1850
+ }
1851
+ if (Array.isArray(obj)) {
1852
+ return options.deep ? obj.map((item) => kebabCaseKeys(item, options)) : obj;
1853
+ }
1854
+ const result = {};
1855
+ for (const key in obj) {
1856
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
1857
+ const value = obj[key];
1858
+ const kebabKey = key.replace(/[_]([a-z])/g, (_, c) => `-${c}`).replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
1859
+ result[kebabKey] = options.deep && isObject(value) ? kebabCaseKeys(value, options) : value;
1860
+ }
1861
+ }
1862
+ return result;
1863
+ }
1864
+ var flatten = (obj, options = {}) => {
1865
+ const { delimiter = ".", includeArrays = false, maxDepth = 9 } = options;
1866
+ if (Array.isArray(obj)) {
1867
+ return obj.map((item) => flatten(item, options));
1868
+ }
1869
+ const result = {};
1870
+ const flattenRecursive = (current, path = "", depth = 0) => {
1871
+ if (depth > maxDepth) {
1872
+ result[path] = current;
1873
+ return;
1874
+ }
1875
+ if (!isObject(current) && !Array.isArray(current)) {
1876
+ if (path) {
1877
+ result[path] = current;
1878
+ }
1879
+ return;
1880
+ }
1881
+ if (Array.isArray(current)) {
1882
+ for (let i = 0; i < current.length; i++) {
1883
+ const newPath = path ? `${path}[${i}]` : `[${i}]`;
1884
+ flattenRecursive(current[i], newPath, depth + 1);
1885
+ }
1886
+ } else {
1887
+ for (const key in current) {
1888
+ const newPath = path ? `${path}${delimiter}${key}` : key;
1889
+ flattenRecursive(current[key], newPath, depth + 1);
1890
+ }
1891
+ const symbols = Object.getOwnPropertySymbols(current);
1892
+ for (const symbol of symbols) {
1893
+ const newPath = path ? `${path}${delimiter}${symbol.toString()}` : symbol.toString();
1894
+ flattenRecursive(current[symbol], newPath, depth + 1);
1895
+ }
1896
+ }
1897
+ };
1898
+ flattenRecursive(obj);
1899
+ return result;
1900
+ };
1901
+ function unflatten(obj, options = {}) {
1902
+ const { delimiter = ".", detectArrays = true } = options;
1903
+ const result = {};
1904
+ for (const key in obj) {
1905
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
1906
+ const value = obj[key];
1907
+ const parts = key.split(delimiter);
1908
+ let current = result;
1909
+ for (let i = 0; i < parts.length - 1; i++) {
1910
+ const part = parts[i];
1911
+ const nextPart = parts[i + 1];
1912
+ const isNextPartArrayIndex = detectArrays && /^\d+$/.test(nextPart);
1913
+ if (!(part in current)) {
1914
+ current[part] = isNextPartArrayIndex ? [] : {};
1915
+ } else if (isNextPartArrayIndex && !Array.isArray(current[part])) {
1916
+ const temp = { ...current[part] };
1917
+ current[part] = [];
1918
+ Object.assign(current[part], temp);
1919
+ }
1920
+ current = current[part];
1921
+ }
1922
+ const lastPart = parts[parts.length - 1];
1923
+ current[lastPart] = value;
1924
+ }
1925
+ }
1926
+ if (detectArrays) {
1927
+ const convertToArrayIfNeeded = (obj2) => {
1928
+ if (!isObject(obj2)) return obj2;
1929
+ if (Array.isArray(obj2)) {
1930
+ return obj2.map(convertToArrayIfNeeded);
1931
+ }
1932
+ const keys = Object.keys(obj2);
1933
+ const isNumericSequence = keys.length > 0 && keys.every((key, index) => {
1934
+ return String(index) === key;
1935
+ });
1936
+ if (isNumericSequence) {
1937
+ return Object.values(obj2).map(convertToArrayIfNeeded);
1938
+ }
1939
+ const result2 = {};
1940
+ for (const key in obj2) {
1941
+ if (Object.prototype.hasOwnProperty.call(obj2, key)) {
1942
+ result2[key] = convertToArrayIfNeeded(obj2[key]);
1943
+ }
1944
+ }
1945
+ return result2;
1946
+ };
1947
+ return convertToArrayIfNeeded(result);
1948
+ }
1949
+ return result;
1950
+ }
1951
+ function transformValues(obj, ...transformers) {
1952
+ if (!isObject(obj) || transformers.length === 0) {
1953
+ return obj;
1954
+ }
1955
+ const result = { ...obj };
1956
+ for (const key in result) {
1957
+ if (Object.prototype.hasOwnProperty.call(result, key)) {
1958
+ let value = result[key];
1959
+ for (const transformer of transformers) {
1960
+ value = transformer(value);
1961
+ }
1962
+ result[key] = value;
1963
+ }
1964
+ }
1965
+ return result;
1966
+ }
1967
+ function renameKeys(obj, mapping, options = {}) {
1968
+ if (!isObject(obj)) {
1969
+ return obj;
1970
+ }
1971
+ const { removeUnmapped = false } = options;
1972
+ const result = {};
1973
+ for (const key in obj) {
1974
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
1975
+ if (key in mapping) {
1976
+ result[mapping[key]] = obj[key];
1977
+ } else if (!removeUnmapped) {
1978
+ result[key] = obj[key];
1979
+ }
1980
+ }
1981
+ }
1982
+ return result;
1983
+ }
1984
+ function deepTransform(data, options = {}) {
1985
+ const {
1986
+ transformObject = (x) => x,
1987
+ transformArray = (x) => x,
1988
+ transformValue = (x) => x,
1989
+ maxDepth = Infinity
1990
+ } = options;
1991
+ function transform(value, path = [], depth = 0) {
1992
+ if (depth > maxDepth) {
1993
+ return value;
1994
+ }
1995
+ if (Array.isArray(value)) {
1996
+ const transformedArray = value.map(
1997
+ (item, index) => transform(item, [...path, index.toString()], depth + 1)
1998
+ );
1999
+ return transformArray(transformedArray, path);
2000
+ }
2001
+ if (isObject(value)) {
2002
+ const transformedObj = {};
2003
+ for (const key2 in value) {
2004
+ if (Object.prototype.hasOwnProperty.call(value, key2)) {
2005
+ const newPath = [...path, key2];
2006
+ transformedObj[key2] = transform(value[key2], newPath, depth + 1);
2007
+ if (!Array.isArray(value[key2]) && !isObject(value[key2])) {
2008
+ transformedObj[key2] = transformValue(
2009
+ transformedObj[key2],
2010
+ key2,
2011
+ newPath
2012
+ );
2013
+ }
2014
+ }
2015
+ }
2016
+ return transformObject(transformedObj, path);
2017
+ }
2018
+ const key = path.length > 0 ? path[path.length - 1] : "";
2019
+ return transformValue(value, key, path);
2020
+ }
2021
+ return transform(data);
2022
+ }
2023
+ function structureByKeys(obj, options = {}) {
2024
+ return unflatten(obj, options);
2025
+ }
2026
+ function transformPath(obj, paths, transformer, options = {}) {
2027
+ if (!isObject(obj)) {
2028
+ return obj;
2029
+ }
2030
+ const result = JSON.parse(JSON.stringify(obj));
2031
+ const { transformAll = false } = options;
2032
+ const pathsArray = Array.isArray(paths) ? paths : [paths];
2033
+ for (const path of pathsArray) {
2034
+ if (path.includes("*") || path.includes("[")) {
2035
+ let applyTransform2 = function(obj2, basePath = "") {
2036
+ if (!isObject(obj2)) return;
2037
+ if (Array.isArray(obj2)) {
2038
+ obj2.forEach((item, index) => {
2039
+ const currentPath = basePath ? `${basePath}[${index}]` : `[${index}]`;
2040
+ applyTransform2(item, currentPath);
2041
+ });
2042
+ return;
2043
+ }
2044
+ for (const key in obj2) {
2045
+ if (Object.prototype.hasOwnProperty.call(obj2, key)) {
2046
+ const value = obj2[key];
2047
+ const currentPath = basePath ? `${basePath}.${key}` : key;
2048
+ if (value === null || typeof value !== "object") {
2049
+ const parent = basePath ? get(result, basePath) : result;
2050
+ const transformed = transformAll ? transformer(value, currentPath, parent) : transformer(value, key, parent);
2051
+ obj2[key] = transformed;
2052
+ } else {
2053
+ applyTransform2(value, currentPath);
2054
+ }
2055
+ }
2056
+ }
2057
+ };
2058
+ var applyTransform = applyTransform2;
2059
+ const matches = get(result, path, { preserveStructure: true });
2060
+ if (matches === void 0) {
2061
+ continue;
2062
+ }
2063
+ applyTransform2(matches);
2064
+ const segments = parseSelector(path);
2065
+ if (segments.length > 0) {
2066
+ const firstSegment = segments[0];
2067
+ if (firstSegment.type === "property") {
2068
+ result[String(firstSegment.value)] = matches[String(firstSegment.value)];
2069
+ }
2070
+ }
2071
+ } else {
2072
+ let setValueAtPath3 = function(obj2, segments2, index, fullPath) {
2073
+ if (index >= segments2.length) return obj2;
2074
+ const key = segments2[index];
2075
+ if (index === segments2.length - 1) {
2076
+ const parent = index > 0 ? setValueAtPath3(
2077
+ obj2,
2078
+ segments2,
2079
+ index - 1,
2080
+ segments2.slice(0, index).join(".")
2081
+ ) : obj2;
2082
+ const transformed = transformAll ? transformer(parent[key], fullPath, parent) : transformer(parent[key], key, parent);
2083
+ parent[key] = transformed;
2084
+ return parent;
2085
+ }
2086
+ const nextObj = obj2[key] || {};
2087
+ obj2[key] = setValueAtPath3(nextObj, segments2, index + 1, fullPath);
2088
+ return obj2;
2089
+ };
2090
+ var setValueAtPath2 = setValueAtPath3;
2091
+ const segments = path.split(".");
2092
+ setValueAtPath3(result, segments, 0, path);
2093
+ }
2094
+ }
2095
+ return result;
2096
+ }
2097
+ function mapPath(obj, paths, mapper, options = {}) {
2098
+ if (!isObject(obj)) {
2099
+ return [];
2100
+ }
2101
+ const { flatten: flatten2 = true } = options;
2102
+ const pathsArray = Array.isArray(paths) ? paths : [paths];
2103
+ const results = pathsArray.map((path) => {
2104
+ const values = get(obj, path);
2105
+ if (values === void 0) {
2106
+ return [];
2107
+ }
2108
+ if (Array.isArray(values)) {
2109
+ return values.map((value, index) => {
2110
+ const fullPath = `${path}[${index}]`;
2111
+ return mapper(value, fullPath, obj);
2112
+ });
2113
+ }
2114
+ return [mapper(values, path, obj)];
2115
+ });
2116
+ return flatten2 ? results.flat() : results;
2117
+ }
2118
+ function transformKeysAtPath(obj, paths, transformer, options = {}) {
2119
+ if (!isObject(obj)) {
2120
+ return obj;
2121
+ }
2122
+ const result = JSON.parse(JSON.stringify(obj));
2123
+ const { recursive = false } = options;
2124
+ const pathsArray = Array.isArray(paths) ? paths : [paths];
2125
+ for (const path of pathsArray) {
2126
+ const target = path ? get(result, path) : result;
2127
+ if (!isObject(target)) {
2128
+ continue;
2129
+ }
2130
+ const transformObjectKeys = (obj2, currentPath = path) => {
2131
+ if (!isObject(obj2)) {
2132
+ return obj2;
2133
+ }
2134
+ if (Array.isArray(obj2)) {
2135
+ return obj2.map(
2136
+ (item, index) => isObject(item) && !Array.isArray(item) ? transformObjectKeys(item, `${currentPath}[${index}]`) : item
2137
+ );
2138
+ }
2139
+ const transformed = {};
2140
+ for (const key in obj2) {
2141
+ if (Object.prototype.hasOwnProperty.call(obj2, key)) {
2142
+ const newKey = transformer(key, obj2[key], currentPath);
2143
+ if (recursive && isObject(obj2[key])) {
2144
+ transformed[newKey] = transformObjectKeys(
2145
+ obj2[key],
2146
+ `${currentPath}.${newKey}`
2147
+ );
2148
+ } else {
2149
+ transformed[newKey] = obj2[key];
2150
+ }
2151
+ }
2152
+ }
2153
+ return transformed;
2154
+ };
2155
+ if (Array.isArray(target)) {
2156
+ for (let i = 0; i < target.length; i++) {
2157
+ if (isObject(target[i]) && !Array.isArray(target[i])) {
2158
+ target[i] = transformObjectKeys(target[i], `${path}[${i}]`);
2159
+ }
2160
+ }
2161
+ } else {
2162
+ const transformed = transformObjectKeys(target);
2163
+ if (path) {
2164
+ set(result, path, transformed);
2165
+ } else {
2166
+ Object.keys(result).forEach((key) => {
2167
+ delete result[key];
2168
+ });
2169
+ Object.assign(result, transformed);
2170
+ }
2171
+ }
2172
+ }
2173
+ return result;
2174
+ }
2175
+ export {
2176
+ camelCaseKeys,
2177
+ deepTransform,
2178
+ flatten,
2179
+ kebabCaseKeys,
2180
+ mapKeys,
2181
+ mapPath,
2182
+ mapValues,
2183
+ renameKeys,
2184
+ snakeCaseKeys,
2185
+ structureByKeys,
2186
+ transformKeysAtPath,
2187
+ transformPath,
2188
+ transformValues,
2189
+ unflatten
2190
+ };