@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,2204 @@
1
- var A=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 h=(e,t,n,r)=>{if(n>r)return;if(t.length===0)return e;let i=t[0],s=t.slice(1);if(i.type==="descendant"){let u=h(e,s,n+1,r);if(u!==void 0)return u;if(e&&typeof e=="object")if(Array.isArray(e)){let o=[];for(let a=0;a<e.length;a++){let f=h(e[a],t,n+1,r);f!==void 0&&(o[a]=f)}return o.length>0?o:void 0}else{let o={};for(let a in e)if(e.hasOwnProperty(a)){let f=h(e[a],t,n+1,r);f!==void 0&&(o[a]=f)}return Object.keys(o).length>0?o:void 0}return}switch(i.type){case"property":if(A(e)&&i.value&&String(i.value)in e){let u=e[String(i.value)],o=h(u,s,n+1,r);if(o!==void 0)return{[String(i.value)]:o}}break;case"index":if(Array.isArray(e)){let u=i.value;if(u>=0&&u<e.length){let o=h(e[u],s,n+1,r);if(o!==void 0){let a=new Array(e.length).filter(f=>f!==void 0);return a[u]=o,a}}}else if(e&&typeof e=="object"){let u=String(i.value);if(u in e){let o=h(e[u],s,n+1,r);if(o!==void 0)return{[u]:o}}}break;case"wildcard":if(e&&typeof e=="object")if(Array.isArray(e)){let u=[],o=!1;for(let a=0;a<e.length;a++){let f=h(e[a],s,n+1,r);f!==void 0&&(u[a]=f,o=!0)}return o?u:void 0}else{let u={},o=!1;for(let a in e)if(e.hasOwnProperty(a)){let f=h(e[a],s,n+1,r);f!==void 0&&(u[a]=f,o=!0)}return o?u:void 0}break;case"slice":if(Array.isArray(e)){let[u,o]=i.value,a=Math.max(0,u),f=Math.min(e.length,o===1/0?e.length:o),y=[],g=!1;for(let p=a;p<f;p++){let b=h(e[p],s,n+1,r);b!==void 0&&(y[p]=b,g=!0)}return g?y:void 0}break;case"union":if(Array.isArray(e)){let u=i.value,o=[],a=!1;for(let f of u)if(f>=0&&f<e.length){let y=h(e[f],s,n+1,r);y!==void 0&&(o[f]=y,a=!0)}return a?o:void 0}break;case"filter":if(Array.isArray(e)){let u=i.value,o=[],a=!1;for(let f=0;f<e.length;f++)if(u(e[f])){let y=h(e[f],s,n+1,r);y!==void 0&&(o[f]=y,a=!0)}return a?o:void 0}break}};var S=(e,t)=>{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((r,i)=>{(!t||!t.some(s=>s.toString()===i.toString()))&&n.set(i,S(r))}),n}if(e instanceof Set){let n=new Set;return e.forEach(r=>{n.add(S(r))}),n}if(Array.isArray(e))return Array.from(e).map(n=>S(n));if(A(e)){let n={};for(let i in e)Object.prototype.hasOwnProperty.call(e,i)&&(!t||!t.some(s=>s.toString()===i.toString()))&&(n[i]=S(e[i]));let r=Object.getOwnPropertySymbols(e);for(let i of r)(!t||!t.some(s=>s.toString()===i.toString()))&&(n[i]=S(e[i]));return n}return e};var K=(e,t={})=>{let{type:n="auto",throwOnError:r=!1}=t;if(!e||typeof e!="string")return[];let i=[],s="",u=!1,o=!1,a="",f="",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,b=c=>{let l=c.trim();if(l==="*"||l==="")return{type:"wildcard",value:l===""?"[]":"*",raw:l===""?"[]":c};if(l==="[]")return{type:"wildcard",value:"[]",raw:c};if(/^-?\d+$/.test(l))return{type:"index",value:parseInt(l,10),raw:c};if(l.includes(":")){let T=l.split(":").map(k=>k.trim()),m=T[0]===""?0:parseInt(T[0],10),x=T[1]===""?1/0:parseInt(T[1],10);if(isNaN(m)||isNaN(x)){if(r)throw new Error(`Invalid slice notation: ${c}`);return{type:"wildcard",value:"*",raw:c}}return{type:"slice",value:[m,x],raw:c}}if(l.includes(",")){let T=l.split(",").map(m=>{let x=parseInt(m.trim(),10);return isNaN(x)?-1:x}).filter(m=>m>=0);if(T.length===0){if(r)throw new Error(`Invalid union notation: ${c}`);return{type:"wildcard",value:"*",raw:c}}return{type:"union",value:T,raw:c}}if(l.startsWith("?(")&&l.endsWith(")")){let T=l.slice(2,-1);try{return{type:"filter",value:V(T),raw:c}}catch(m){if(r)throw m;return{type:"wildcard",value:"*",raw:c}}}return l.startsWith('"')&&l.endsWith('"')||l.startsWith("'")&&l.endsWith("'")?{type:"property",value:l.slice(1,-1),raw:c}:{type:"property",value:l,raw:c}};for(let c=0;c<e.length;c++){let l=e[c],T=e[c+1];if((l==='"'||l==="'")&&!o){o=!0,a=l;continue}else if(l===a&&o){o=!1,a="",l==='"'||l==="'"||(u?f+=l:s+=l);continue}if(o){u?f+=l:s+=l;continue}if(l==="["&&!u){s&&(i.push({type:"property",value:s,raw:s}),s=""),u=!0,f="";continue}if(l==="]"&&u&&!o){u=!1;let x=b(f);i.push(x);continue}let m=i.length>0?i[i.length-1]:null;if(l==="."&&!u&&!o){if(T==="."){let x=e.split("..")[0];i.push({type:"property",value:x,raw:x}),i.push({type:"descendant",value:"..",raw:".."}),c++}else s&&(s==="*"?i.push({type:"wildcard",value:s,raw:s}):i.push({type:"property",value:s,raw:s}),s="");continue}if(u)f+=l;else if(m&&m.type!=="descendant")s+=l;else{let x=e.split(m?.raw)[1];x!==void 0?s=x:s+=l}}return s&&i.push({type:"property",value:s,raw:s}),i.map(c=>{if(c.type==="property"&&typeof c.value=="string"&&/^-?\d+$/.test(c.value)){let l=parseInt(c.value,10);if(!isNaN(l))return{...c,type:"index",value:l}}return c})},V=e=>{let t=e.replace(/@\.([a-zA-Z_$][\w$]*)/g,(n,r)=>`item.${r}`).replace(/@/g,"item");try{return new Function("item",`return ${t}`)}catch{throw new Error(`Invalid filter expression: ${e}`)}};var I=(e,t,n)=>{let r=K(t),i=e;for(let s=0;s<r.length;s++){let u=r[s],o=s===r.length-1;switch(u.type){case"property":if(o)i[String(u.value)]=n;else{if(!i[String(u.value)]){let f=r[s+1];i[String(u.value)]=f.type==="index"||f.type==="slice"||f.type==="union"||f.type==="wildcard"?[]:{}}i=i[String(u.value)]}break;case"index":Array.isArray(i)||(i=[]);let a=u.value;if(o){if(a>=i.length)for(let f=i.length;f<=a;f++)i.push(void 0);i[a]=n}else{if(!i[a]){let f=r[s+1];i[a]=f.type==="index"||f.type==="slice"||f.type==="union"||f.type==="wildcard"?[]:{}}i=i[a]}break;case"wildcard":if(Array.isArray(i))if(o)for(let f=0;f<i.length;f++)i[f]=n;else{let f=r[s+1];for(let y=0;y<i.length;y++)i[y]||(i[y]=f.type==="index"||f.type==="slice"||f.type==="union"||f.type==="wildcard"?[]:{});i.length>0&&(i=i[0])}break}}};function d(e,t,n={}){let{preserveStructure:r,multiple:i,throwOnError:s=!1,defaultValue:u,maxDepth:o=20}=n;if(!e||typeof e!="object")return u;if(!t)return e;if(Array.isArray(t))if(r){let y={};for(let g of t){let p=d(e,g,{...n,preserveStructure:!1});p!==void 0&&I(y,g,p)}return y}else return t.map(y=>d(e,y,{...n,preserveStructure:!1}));let a=K(t,{...n,throwOnError:s});if(a.length===0)return e;if(typeof r>"u"||r===!1){let y=R(e,t);return i===!1&&Array.isArray(y)?y[0]:y===void 0&&u!==void 0?u:y}let f=h(e,a,0,o);return f===void 0&&u!==void 0?u:f}function R(e,t,n={}){let{createMissing:r=!1,add:i=!1,debug:s=!1}=n,u=K(t),o=e,a=!1,f="",y=t;if(typeof o=="object"&&!Array.isArray(o)&&y.length>0&&o[y])return o=o[y],o;for(let g=0;g<u.length;g++){let p=u[g],b=u.length>1?g===u.length-1:!1;if(o===null&&!r)return;let c=u[g+1];switch(p.type){case"property":if(o&&typeof o=="object")if(Array.isArray(o)){if(typeof p.value=="number"){let l=p.value;if(r&&l>=o.length)for(let T=o.length;T<=l;T++)o.push(void 0);if(r&&(o[l]===null||o[l]===void 0)&&(!b||a)&&(c?o[l]=c.type==="index"||c.type==="slice"||c.type==="union"||c.type==="wildcard"?[]:{}:o[l]=null,a=!1),o=o[l],c){a=!0;continue}}else i?o.push({[String(p.value)]:null}):o=o.map(l=>l[String(p.value)]);if(c)continue;return F(o)}else{if(o[f]&&f.split(".").length>=2){o=o[f];continue}if(r&&(o[String(p.value)]===null||o[String(p.value)]===void 0)&&(!b||a)&&(c?o[String(p.value)]=c.type==="index"||c.type==="slice"||c.type==="union"||c.type==="wildcard"?[]:{}:o[String(p.value)]=null,a=!1,o=o[String(p.value)],c)){a=!0;continue}if(o?(!o[String(p.value)]&&r&&(o[String(p.value)]=null),o=o[String(p.value)]):o={[String(p.value)]:null},c)continue}else if(r)o={},o[String(p.value)]=c.type==="index"||c.type==="slice"||c.type==="union"||c.type==="wildcard"||n.type==="array"?[]:{},o=o[String(p.value)];else return;break;case"index":case"wildcard":if(Array.isArray(o)){if(p.type==="index"){let l=p.value;if(l<0){o=o[o.length-Math.abs(l)];continue}if(r&&(l>=o.length||o[l]==null||o[l]==null)&&!b){for(let T=o.length;T<=l;T++)o.push(void 0);c&&(o[l]=c.type==="index"||c.type==="slice"||c.type==="union"||c.type==="wildcard"?[]:{})}o=o[l]}else if(!b)continue}else if(r){let l=u[g+1];o=[];let T=p.value;for(let m=0;m<=T;m++)o.push(void 0);o[T]=l.type==="index"||l.type==="slice"||l.type==="union"||l.type==="wildcard"||n.type==="array"?[]:{},o=o[T]}else{if(p.type==="index"&&typeof o=="object"&&o&&o[String(p.value)]!==void 0){o=o[String(p.value)];continue}if(typeof o=="object"){o=Object.values(o);continue}return}break;default:return}}return F(o)}function F(e){return Array.isArray(e)?e.filter(t=>typeof t<"u"):e}function v(e,t){if(!Array.isArray(e)||t<1)return[];let n=[];for(let r=0;r<e.length;r+=t)n.push(e.slice(r,r+t));return n}function se(e){return e.reduce((t,n)=>t.concat(n),[])}function $(e,t=1/0){return t<1?e.slice():e.reduce((n,r)=>(Array.isArray(r)?n.push(...$(r,t-1)):n.push(r),n),[])}function O(e,t){if(!Array.isArray(e))return[];if(!t)return[...new Set(e)];let n=new Set;return e.filter(r=>{let i=typeof t=="function"?t(r):A(r)?d(r,t):r;return n.has(i)?!1:(n.add(i),!0)})}function oe(e,t){return Array.isArray(e)?e.reduce((n,r)=>{let i;return typeof t=="function"?i=String(t(r)):i=String(A(r)?d(r,t):r),n[i]||(n[i]=[]),n[i].push(r),n},{}):{}}function ue(e,t){return Array.isArray(e)?e.reduce((n,r)=>{let i;return typeof t=="function"?i=String(t(r)):t?i=String(A(r)?d(r,t):r):i=String(r),n[i]=(n[i]||0)+1,n},{}):{}}function ae(e,t,n){return Array.isArray(e)?e.reduce((r,i)=>{let s;typeof t=="function"?s=String(t(i)):s=String(A(i)?d(i,t):i);let u;return n?typeof n=="function"?u=n(i):u=d(i,n):u=i,r[s]=u,r},{}):{}}function fe(e,t){if(!Array.isArray(e)||e.length===0)return[];let n=[...e],i=(Array.isArray(t)?t:[t]).map(s=>typeof s=="object"&&"key"in s?{key:s.key,dir:s.dir||"asc"}:{key:s,dir:"asc"});return n.sort((s,u)=>{for(let{key:o,dir:a}of i){let f=A(s)?d(s,o):s,y=A(u)?d(u,o):u;if(f===y)continue;let g=f<y?-1:1;return a==="asc"?g:-g}return 0}),n}function le(e,t,n){if(!Array.isArray(e))return[];if(!Array.isArray(t))return e;if(!n){let i=new Set(t);return e.filter(s=>!i.has(s))}let r=new Set(t.map(i=>A(i)?d(i,n):i));return e.filter(i=>{let s=A(i)?d(i,n):i;return!r.has(s)})}function ce(e,t,n){if(!Array.isArray(e)||!Array.isArray(t))return[];if(!n){let i=new Set(t);return e.filter(s=>i.has(s))}let r=new Set(t.map(i=>A(i)?d(i,n):i));return e.filter(i=>{let s=A(i)?d(i,n):i;return r.has(s)})}function ye(e,t,n){return!Array.isArray(e)&&!Array.isArray(t)?[]:Array.isArray(e)?Array.isArray(t)?O([...e,...t],n):O(e,n):O(t,n)}function pe(e,t){return Array.isArray(e)?e.reduce((n,r,i)=>(n[t(r,i)?0:1].push(r),n),[[],[]]):[[],[]]}function de(e,t){return!Array.isArray(e)||t<=0?[]:e.slice(0,t)}function Te(e,t){return!Array.isArray(e)||t<=0?[]:e.slice(-t)}function Ae(e,t){if(!Array.isArray(e))return[];let n=[];for(let r=0;r<e.length&&t(e[r],r);r++)n.push(e[r]);return n}function ge(e,t){return!Array.isArray(e)||t<=0?e?[...e]:[]:e.slice(t)}function me(e,t){if(!Array.isArray(e))return[];let n=0;for(;n<e.length&&t(e[n],n);)n++;return e.slice(n)}function xe(e){return Array.isArray(e)?e.filter(Boolean):[]}function he(...e){if(e.length===0)return[];let t=Math.max(...e.map(r=>Array.isArray(r)?r.length:0)),n=[];for(let r=0;r<t;r++){let i=[];for(let s of e)i.push(Array.isArray(s)?s[r]:void 0);n.push(i)}return n}function be(e){if(!Array.isArray(e)||e.length===0)return[];let t=Math.max(...e.map(r=>Array.isArray(r)?r.length:0)),n=[];for(let r=0;r<t;r++){let i=[];for(let s of e)Array.isArray(s)&&i.push(s[r]);n.push(i)}return n}function C(e){if(!Array.isArray(e))return[];let t=[...e];for(let n=t.length-1;n>0;n--){let r=Math.floor(Math.random()*(n+1));[t[n],t[r]]=[t[r],t[n]]}return t}function Se(e){if(!(!Array.isArray(e)||e.length===0))return e[Math.floor(Math.random()*e.length)]}function Ke(e,t){return!Array.isArray(e)||t<=0?[]:C(e).slice(0,Math.min(t,e.length))}function we(e,t,n=0){if(!Array.isArray(e))return-1;for(let r=n;r<e.length;r++)if(t(e[r],r))return r;return-1}function ve(e,t,n){if(!Array.isArray(e))return-1;let r=n!==void 0?n:e.length-1;for(let i=r;i>=0;i--)if(t(e[i],i))return i;return-1}function Oe(e,t){return Array.isArray(e)?e.map(n=>d(n,t)):[]}function Pe(e,t){return!Array.isArray(e)||!Array.isArray(t)?[]:e.map(n=>{let r={};for(let i of t)i in n&&(r[i]=n[i]);return r})}function Ie(e,t){return!Array.isArray(e)||!Array.isArray(t)?[]:e.map(n=>{let r={...n};for(let i of t)delete r[i];return r})}function Fe(e,t){return Array.isArray(e)?e.reduce((n,r,i)=>{let s=t(r,i);return n.concat(s)},[]):[]}function je(e,t,n){if(!Array.isArray(e))return n;let r=n;for(let i=e.length-1;i>=0;i--)r=t(r,e[i],i);return r}function ke(e,t,n=1){if(n===0)return[];let r=[];if(n>0)for(let i=e;i<t;i+=n)r.push(i);else for(let i=e;i>t;i+=n)r.push(i);return r}function Ve(e,t,n=0,r){if(!Array.isArray(e))return[];let i=[...e],s=r===void 0?i.length:r;for(let u=n;u<s&&u<i.length;u++)i[u]=t;return i}function Re(e){return Array.isArray(e)?S(e):[]}function $e(e,t,...n){let r,i;if(typeof t=="string")r=t,i=[e];else{let u=n[n.length-1];typeof u=="string"?(r=u,i=[e,t,...n.slice(0,-1).filter(Array.isArray)]):(r="id",i=[e,t,...n.filter(Array.isArray)])}if(i.length===0)return[];let s=new Map;for(let u of i)if(Array.isArray(u))for(let o of u){let a=A(o)?d(o,r):void 0;if(a!==void 0){let f=s.get(a);s.set(a,f?{...f,...o}:o)}}return Array.from(s.values())}function Ce(e,t,n){if(!Array.isArray(e)||t===n)return e?[...e]:[];let r=[...e],[i]=r.splice(t,1);return r.splice(n,0,i),r}function Me(e,t){if(!Array.isArray(e)||e.length===0||t===0)return e?[...e]:[];let n=e.length,r=(t%n+n)%n;return[...e.slice(-r),...e.slice(0,-r)]}function Ue(e,t,...n){if(!Array.isArray(e))return n;let r=[...e];return r.splice(t,0,...n),r}function Ee(e,t,n=1){if(!Array.isArray(e))return[];let r=[...e];return r.splice(t,n),r}function We(e,t,n){if(!Array.isArray(e))return[];let r=[...e];return r[t]=n,r}function qe(e,t){if(!Array.isArray(e))return[];let n=e.filter(r=>r!=null);return t?n.filter(t):n}function Be(...e){return e.length===0?[[]]:e.length===1?e[0].map(t=>[t]):e.reduce((t,n)=>t.flatMap(r=>n.map(i=>[...r,i])),[[]])}function Ne(e,t){if(!Array.isArray(e))return[];let n=[];for(let r=0;r<e.length;r++)t(e[r],r)&&n.push(r);return n}function Le(e,t,n=!0){if(!Array.isArray(e)||!Array.isArray(t)||e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(n&&A(e[r])&&A(t[r])){if(JSON.stringify(e[r])!==JSON.stringify(t[r]))return!1}else if(e[r]!==t[r])return!1;return!0}function _e(e,t){if(!Array.isArray(e)||e.length===0)return[];let n=[],r=[e[0]],i=t(e[0],0);for(let s=1;s<e.length;s++){let u=t(e[s],s);u===i?r.push(e[s]):(n.push(r),r=[e[s]],i=u)}return n.push(r),n}function ze(e,t,n,r){if(!Array.isArray(e))return[];let i=typeof t=="function",s=i?n:r;return e.map(u=>{let o=!1;return i?o=t(u):o=(A(u)?d(u,t):u)===n,o?{...u,...s}:u})}function Je(e,t){if(!Array.isArray(e))return{unique:[],duplicates:[]};let n=new Set,r=[],i=[];for(let s of e){let u=t&&A(s)?d(s,t):s;n.has(u)?i.push(s):(n.add(u),r.push(s))}return{unique:r,duplicates:i}}function M(e){return Array.isArray(e)?e:e==null?[]:[e]}function De(e){return M(e)}function Qe(e,t,n=1){if(!Array.isArray(e)||t<1||n<1)return[];let r=[];for(let i=0;i<=e.length-t;i+=n)r.push(e.slice(i,i+t));return r}function Ze(e,t){if(!Array.isArray(e)||e.length===0)return;let n=e[0],r=typeof t=="function"?t(n):d(n,t);for(let i=1;i<e.length;i++){let s=e[i],u=typeof t=="function"?t(s):d(s,t);u<r&&(r=u,n=s)}return n}function Ge(e,t){if(!Array.isArray(e)||e.length===0)return;let n=e[0],r=typeof t=="function"?t(n):d(n,t);for(let i=1;i<e.length;i++){let s=e[i],u=typeof t=="function"?t(s):d(s,t);u>r&&(r=u,n=s)}return n}function U(e,t){if(!Array.isArray(e)||e.length===0)return 0;let n=0;for(let r of e){let i=typeof t=="function"?t(r):d(r,t);typeof i=="number"&&!isNaN(i)&&(n+=i)}return n}function He(e,t){return!Array.isArray(e)||e.length===0?0:U(e,t)/e.length}function w(e){let t=new Map;if(!Array.isArray(e))return t;for(let n of e)t.set(n,(t.get(n)||0)+1);return t}function E(e,t=1){if(!Array.isArray(e)||e.length===0||t<1)return[];let n=w(e);return Array.from(n.entries()).sort((i,s)=>s[1]-i[1]).slice(0,t).map(([i])=>i)}function Xe(e,t=1){if(!Array.isArray(e)||e.length===0||t<1)return[];let n=w(e);return Array.from(n.entries()).sort((i,s)=>i[1]-s[1]).slice(0,t).map(([i])=>i)}async function Ye(e,t,n){if(!Array.isArray(e)||t<1)return;let r=v(e,t);for(let i=0;i<r.length;i++)await n(r[i],i)}async function en(e,t,n,r){if(!Array.isArray(e)||t<1||n<1)return;let i=v(e,t),s=v(i.map((u,o)=>({batch:u,index:o})),n);for(let u of s)await Promise.all(u.map(({batch:o,index:a})=>r(o,a)))}function nn(e){if(!Array.isArray(e)||e.length===0)return[];let t=Math.max(...e.map(r=>r.length)),n=[];for(let r=0;r<t;r++){let i=[];for(let s=0;s<e.length;s++)r<e[s].length&&i.push(e[s][r]);n.push(i)}return n}function tn(e,t){if(!Array.isArray(e)||!Array.isArray(t)||e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function rn(e,t){if(!Array.isArray(e)||!Array.isArray(t)||e.length!==t.length)return!1;let n=w(e),r=w(t);if(n.size!==r.size)return!1;for(let[i,s]of n)if(r.get(i)!==s)return!1;return!0}function W(e,t){if(!Array.isArray(e)||!Array.isArray(t))return!1;let n=new Set(t);return e.every(r=>n.has(r))}function sn(e,t){return W(t,e)}function on(...e){if(e.length===0)return[];let t=Math.max(...e.map(r=>r.length)),n=[];for(let r=0;r<t;r++)for(let i of e)r<i.length&&n.push(i[r]);return n}function un(e,t){let n=[],r=[];if(!Array.isArray(e))return{pass:n,fail:r};for(let i=0;i<e.length;i++)t(e[i],i)?n.push(e[i]):r.push(e[i]);return{pass:n,fail:r}}function an(e,t){if(e<0)return[];let n=[];for(let r=0;r<e;r++)n.push(t(r));return n}function fn(e,t){if(!Array.isArray(e)||t<0)return[];let n=[];for(let r=0;r<t;r++)n.push(...e);return n}function ln(e){if(!Array.isArray(e)||e.length===0)return;let t=[...e].sort((r,i)=>r-i),n=Math.floor(t.length/2);return t.length%2===0?(t[n-1]+t[n])/2:t[n]}function cn(e){let t=E(e,1);return t.length>0?t[0]:void 0}function yn(e,...t){if(!Array.isArray(e))return[];let n=new Set(t);return e.filter(r=>!n.has(r))}function pn(e,...t){if(!Array.isArray(e))return[];let n=new Set(t.flat());return e.filter(r=>!n.has(r))}function dn(e){if(!Array.isArray(e)||e.length===0)return[];let t=[],n=[e[0]];for(let r=1;r<e.length;r++)e[r]===e[r-1]?n.push(e[r]):(t.push(n),n=[e[r]]);return t.push(n),t}function Tn(e){if(!Array.isArray(e)||e.length===0)return[];let t=[e[0]];for(let n=1;n<e.length;n++)e[n]!==e[n-1]&&t.push(e[n]);return t}function An(e,t="standard"){if(!Array.isArray(e)||e.length===0)return[];let n=e.map((i,s)=>({value:i,index:s}));n.sort((i,s)=>i.value-s.value);let r=new Array(e.length);if(t==="ordinal")for(let i=0;i<n.length;i++)r[n[i].index]=i+1;else if(t==="dense"){let i=1;r[n[0].index]=i;for(let s=1;s<n.length;s++)n[s].value!==n[s-1].value&&i++,r[n[s].index]=i}else{let i=0;for(;i<n.length;){let s=i;for(;s<n.length&&n[s].value===n[i].value;)s++;let u=i+1;for(let o=i;o<s;o++)r[n[o].index]=u;i=s}}return r}function P(e,t){if(!Array.isArray(e)||e.length===0||t<0||t>100)return;let n=[...e].sort((o,a)=>o-a),r=t/100*(n.length-1),i=Math.floor(r),s=Math.ceil(r),u=r-i;return i===s?n[i]:n[i]*(1-u)+n[s]*u}function gn(e){if(!Array.isArray(e)||e.length===0)return;let t=P(e,25),n=P(e,50),r=P(e,75);return{q1:t,q2:n,q3:r,iqr:r-t}}function j(e,t=!1){if(!Array.isArray(e)||e.length===0||t&&e.length===1)return;let n=e.reduce((s,u)=>s+u,0)/e.length,i=e.map(s=>Math.pow(s-n,2)).reduce((s,u)=>s+u,0)/(t?e.length-1:e.length);return Math.sqrt(i)}function mn(e,t=!1){let n=j(e,t);return n!==void 0?Math.pow(n,2):void 0}function xn(e){if(!Array.isArray(e)||e.length===0)return[];let t=Math.min(...e),r=Math.max(...e)-t;return r===0?e.map(()=>0):e.map(i=>(i-t)/r)}function hn(e){if(!Array.isArray(e)||e.length===0)return[];let t=e.reduce((r,i)=>r+i,0)/e.length,n=j(e);return n===void 0||n===0?e.map(()=>0):e.map(r=>(r-t)/n)}function q(e,t,n){if(!Array.isArray(e))return[];let r=[],i=n;for(let s=0;s<e.length;s++)i=t(i,e[s],s),r.push(i);return r}function bn(e){return q(e,(t,n)=>t+n,0)}function Sn(e){if(!Array.isArray(e)||e.length<2)return[];let t=[];for(let n=1;n<e.length;n++)t.push(e[n]-e[n-1]);return t}function Kn(e,t,n,r="end"){if(!Array.isArray(e)||t<=e.length)return[...e];let i=new Array(t-e.length).fill(n);return r==="start"?[...i,...e]:[...e,...i]}function wn(e,t){if(!Array.isArray(e)||e.length===0)return[];let n=0,r=e.length-1;for(;n<=r&&t(e[n]);)n++;for(;r>=n&&t(e[r]);)r--;return e.slice(n,r+1)}function vn(e){if(!Array.isArray(e)||e.length<2)return[];let t=[];for(let n=0;n<e.length-1;n++)t.push([e[n],e[n+1]]);return t}function On(e){return Array.isArray(e)?e.map((t,n)=>[n,t]):[]}function Pn(e,t){return Array.isArray(e)?e.map((n,r)=>{let i=t[r%t.length];return i(n)}):[]}function B(e,t=1){if(!Array.isArray(e)||e.length===0)return[];let n=e.length,r=(t%n+n)%n;return[...e.slice(r),...e.slice(0,r)]}function In(e,t=1){return B(e,-t)}function Fn(e,t,n){if(!Array.isArray(e)||t<0||n<0||t>=e.length||n>=e.length)return[...e];let r=[...e];return[r[t],r[n]]=[r[n],r[t]],r}function jn(e,t,n){if(!Array.isArray(e)||t<0||n>=e.length||t>=n)return[...e];let r=[...e],i=r.slice(t,n+1).reverse();return r.splice(t,n-t+1,...i),r}function kn(e,t){if(!Array.isArray(e)||e.length<=1)return!0;let n=t||((r,i)=>r<i?-1:r>i?1:0);for(let r=1;r<e.length;r++)if(n(e[r-1],e[r])>0)return!1;return!0}function Vn(e){return Array.isArray(e)?new Set(e).size!==e.length:!1}function Rn(e,t){return Array.isArray(e)?e.map(n=>{let r={};for(let i of t)i in n&&(r[i]=n[i]);return r}):[]}function N(e,t,n){if(!Array.isArray(e))return{};let r={};for(let i=0;i<e.length;i++){let s=t(e[i],i),u=n?n(e[i],i):e[i];r[s]=u}return r}async function $n(e,t){if(!Array.isArray(e))return[];let n=[];for(let r=0;r<e.length;r++)n.push(await t(e[r],r));return n}async function Cn(e,t){return Array.isArray(e)?Promise.all(e.map((n,r)=>t(n,r))):[]}async function Mn(e,t){if(!Array.isArray(e))return[];let n=[];for(let r=0;r<e.length;r++)await t(e[r],r)&&n.push(e[r]);return n}async function Un(e,t,n){if(!Array.isArray(e))return n;let r=n;for(let i=0;i<e.length;i++)r=await t(r,e[i],i);return r}async function En(e,t){if(Array.isArray(e)){for(let n=0;n<e.length;n++)if(await t(e[n],n))return e[n]}}async function Wn(e,t){if(!Array.isArray(e))return!1;for(let n=0;n<e.length;n++)if(await t(e[n],n))return!0;return!1}async function qn(e,t){if(!Array.isArray(e))return!0;for(let n=0;n<e.length;n++)if(!await t(e[n],n))return!1;return!0}function Bn(e,t,n){if(!Array.isArray(e)||e.length===0)return 0;let r=0,i=0;for(let s of e){let u=typeof t=="function"?t(s):d(s,t),o=typeof n=="function"?n(s):d(s,n);typeof u=="number"&&typeof o=="number"&&(i+=u*o,r+=o)}return r===0?0:i/r}function Nn(e,t,n=1){if(!Array.isArray(e)||e.length===0||n<1)return[];let r=[],i=0;for(let u of e){let o=typeof t=="function"?t(u):d(u,t);i+=typeof o=="number"&&o>0?o:0,r.push(i)}if(i===0)return[];let s=[];for(let u=0;u<n;u++){let o=Math.random()*i,a=r.findIndex(f=>o<f);a!==-1&&s.push(e[a])}return s}function Ln(e,t){if(!Array.isArray(e)||!Array.isArray(t))return[];let n=[],r=0;for(let i of t){if(r>=e.length)break;n.push(e.slice(r,r+i)),r+=i}return n}function _n(e,t){if(!Array.isArray(e)||t<1)return[];let n=w(e),r=[];for(let i of e)n.get(i)===t&&r.push(i);return r}function zn(e,t,n){if(!Array.isArray(e)||t<1)return[];let r=[],i=0,s=[];for(let u of e)n(u)?(i++,s.push(u),i>=t&&r.push(...s.splice(0,s.length-t+1))):(i=0,s.length=0);return i>=t&&r.push(...s),r}function Jn(e,t,n){if(!Array.isArray(e))return[];let r=[],i=n;for(let s=0;s<e.length;s++){let{value:u,newContext:o}=t(e[s],i,s);r.push(u),i=o}return r}function Dn(e,t){return v(e,t)}function Qn(e,t,n){if(!Array.isArray(e)||!Array.isArray(t))return[];let r=Math.min(e.length,t.length),i=[];for(let s=0;s<r;s++)i.push(n(e[s],t[s]));return i}function Zn(e,t,n="last"){if(!Array.isArray(e)||e.length===0)return[];let r=new Map;for(let s of e)if(Array.isArray(s))for(let u of s){let o=d(u,t);if(n==="first")r.has(o)||r.set(o,u);else if(n==="last")r.set(o,u);else if(n==="concat"){let a=r.get(o);Array.isArray(a)?a.push(u):a?r.set(o,[a,u]):r.set(o,u)}else if(typeof n=="function"){let a=r.get(o);a&&!Array.isArray(a)?r.set(o,n(a,u)):r.set(o,u)}}let i=[];for(let s of r.values())Array.isArray(s)&&n==="concat"?i.push(...s):Array.isArray(s)||i.push(s);return i}function Gn(e,t){return N(e,n=>String(d(n,t)))}function Hn(e,t,n){if(!Array.isArray(e)||e.length===0)return-1;let r=n||((u,o)=>u<o?-1:u>o?1:0),i=0,s=e.length-1;for(;i<=s;){let u=Math.floor((i+s)/2),o=r(e[u],t);if(o===0)return u;o<0?i=u+1:s=u-1}return-1}function Xn(e,t,n){if(!Array.isArray(e))return[t];let r=n||((u,o)=>u<o?-1:u>o?1:0),i=[...e],s=0;for(;s<i.length&&r(i[s],t)<0;)s++;return i.splice(s,0,t),i}export{Pn as applyByIndex,He as avgBy,Dn as batch,Ye as batchProcess,en as batchProcessParallel,un as bifurcate,Hn as binarySearch,Be as cartesian,v as chunk,_e as chunkBy,xe as compact,ue as countBy,bn as cumulativeSum,Tn as dedupeConsecutive,Re as deepCloneArray,Sn as diff,le as difference,pn as differenceWith,ge as drop,me as dropWhile,M as ensureArray,On as enumerate,qn as everyAsync,Ve as fill,Mn as filterAsync,qe as filterCompact,zn as filterConsecutive,Ne as findAllIndices,En as findAsync,we as findIndex,ve as findLastIndex,Fe as flatMap,se as flatten,$ as flattenDeep,w as frequencies,an as generate,oe as groupBy,dn as groupConsecutive,Vn as hasDuplicates,rn as hasSameElements,Gn as indexBy,Ue as insert,Xn as insertSorted,on as interleave,ce as intersection,tn as isArrayEqual,Le as isEqual,kn as isSorted,W as isSubset,sn as isSuperset,ae as keyBy,Xe as leastCommon,$n as mapAsync,Cn as mapAsyncParallel,Jn as mapWithContext,Ge as maxBy,ln as median,Zn as mergeArraysByKey,$e as mergeByKey,Ze as minBy,cn as mode,E as mostCommon,Ce as move,xn as normalize,Ie as omit,Kn as pad,vn as pairwise,pe as partition,P as percentile,Pe as pick,Rn as pickMany,Oe as pluck,gn as quartiles,ke as range,An as rank,Un as reduceAsync,je as reduceRight,Ee as remove,fn as repeat,We as replace,jn as reverseSegment,Me as rotate,B as rotateLeft,In as rotateRight,Se as sample,Ke as sampleSize,q as scan,Ln as segment,_n as selectByCount,C as shuffle,Qe as slidingWindow,Wn as someAsync,fe as sortBy,Je as splitDuplicates,j as standardDeviation,hn as standardize,U as sumBy,Fn as swap,de as take,Te as takeLast,Ae as takeWhile,N as toObject,nn as transpose,wn as trim,ye as union,O as unique,be as unzip,ze as updateBy,mn as variance,Bn as weightedAverage,Nn as weightedSample,yn as without,De as wrap,he as zip,Qn as zipWith};
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 segment2 = segments[0];
17
+ const remaining = segments.slice(1);
18
+ if (segment2.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 (segment2.type) {
59
+ case "property":
60
+ if (isObject(current) && segment2.value && String(segment2.value) in current) {
61
+ const next = current[String(segment2.value)];
62
+ const result = traverseStructure(next, remaining, depth + 1, maxDepth);
63
+ if (result !== void 0) {
64
+ return { [String(segment2.value)]: result };
65
+ }
66
+ }
67
+ break;
68
+ case "index":
69
+ if (Array.isArray(current)) {
70
+ const index = segment2.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(segment2.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] = segment2.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 = segment2.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 = segment2.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/object/clone.ts
214
+ var deepClone = (obj, skipKeys) => {
215
+ if (obj == null || typeof obj !== "object") {
216
+ return obj;
217
+ }
218
+ if (obj instanceof Date) {
219
+ return new Date(obj.getTime());
220
+ }
221
+ if (obj instanceof RegExp) {
222
+ return new RegExp(obj.source, obj.flags);
223
+ }
224
+ if (obj instanceof Map) {
225
+ const clone = /* @__PURE__ */ new Map();
226
+ obj.forEach((value, key) => {
227
+ if (!skipKeys || !skipKeys.some((k) => k.toString() === key.toString())) {
228
+ clone.set(key, deepClone(value));
229
+ }
230
+ });
231
+ return clone;
232
+ }
233
+ if (obj instanceof Set) {
234
+ const clone = /* @__PURE__ */ new Set();
235
+ obj.forEach((value) => {
236
+ clone.add(deepClone(value));
237
+ });
238
+ return clone;
239
+ }
240
+ if (Array.isArray(obj)) {
241
+ return Array.from(obj).map((item) => deepClone(item));
242
+ }
243
+ if (isObject(obj)) {
244
+ const clone = {};
245
+ for (const key in obj) {
246
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
247
+ if (!skipKeys || !skipKeys.some((k) => k.toString() === key.toString())) {
248
+ clone[key] = deepClone(obj[key]);
249
+ }
250
+ }
251
+ }
252
+ const symbols = Object.getOwnPropertySymbols(obj);
253
+ for (const symbol of symbols) {
254
+ if (!skipKeys || !skipKeys.some((s) => s.toString() === symbol.toString())) {
255
+ clone[symbol] = deepClone(obj[symbol]);
256
+ }
257
+ }
258
+ return clone;
259
+ }
260
+ return obj;
261
+ };
262
+
263
+ // src/lib/object/selector.ts
264
+ var parseSelector = (selector, options = {}) => {
265
+ const { type = "auto", throwOnError = false } = options;
266
+ if (!selector || typeof selector !== "string") {
267
+ return [];
268
+ }
269
+ const segments = [];
270
+ let current = "";
271
+ let inBrackets = false;
272
+ let inQuotes = false;
273
+ let quoteChar = "";
274
+ let bracketContent = "";
275
+ let bracketDepth = 0;
276
+ const detectType = (str) => {
277
+ if (str.includes("..")) return "descendant";
278
+ if (str.includes("[?(")) return "filter";
279
+ if (str.includes("[:") || str.includes("[0:")) return "slice";
280
+ if (str.includes("[,") || str.includes("[0,1]")) return "union";
281
+ if (str.includes("[*]") || str.includes(".*.")) return "wildcard";
282
+ if (str.includes("[]")) return "array-wildcard";
283
+ if (str.includes("[") && str.includes("]")) return "bracket";
284
+ return "dot";
285
+ };
286
+ const actualType = type === "auto" ? detectType(selector) : type;
287
+ const parseBracketContent = (content) => {
288
+ const trimmed = content.trim();
289
+ if (trimmed === "*" || trimmed === "") {
290
+ return {
291
+ type: "wildcard",
292
+ value: trimmed === "" ? "[]" : "*",
293
+ raw: trimmed === "" ? "[]" : content
294
+ };
295
+ }
296
+ if (trimmed === "[]") {
297
+ return { type: "wildcard", value: "[]", raw: content };
298
+ }
299
+ if (/^-?\d+$/.test(trimmed)) {
300
+ return { type: "index", value: parseInt(trimmed, 10), raw: content };
301
+ }
302
+ if (trimmed.includes(":")) {
303
+ const parts = trimmed.split(":").map((p) => p.trim());
304
+ const start = parts[0] === "" ? 0 : parseInt(parts[0], 10);
305
+ const end = parts[1] === "" ? Infinity : parseInt(parts[1], 10);
306
+ if (isNaN(start) || isNaN(end)) {
307
+ if (throwOnError) throw new Error(`Invalid slice notation: ${content}`);
308
+ return { type: "wildcard", value: "*", raw: content };
309
+ }
310
+ return { type: "slice", value: [start, end], raw: content };
311
+ }
312
+ if (trimmed.includes(",")) {
313
+ const indices = trimmed.split(",").map((p) => {
314
+ const num = parseInt(p.trim(), 10);
315
+ return isNaN(num) ? -1 : num;
316
+ }).filter((n) => n >= 0);
317
+ if (indices.length === 0) {
318
+ if (throwOnError) throw new Error(`Invalid union notation: ${content}`);
319
+ return { type: "wildcard", value: "*", raw: content };
320
+ }
321
+ return { type: "union", value: indices, raw: content };
322
+ }
323
+ if (trimmed.startsWith("?(") && trimmed.endsWith(")")) {
324
+ const expr = trimmed.slice(2, -1);
325
+ try {
326
+ const filterFn = createFilterFunction(expr);
327
+ return { type: "filter", value: filterFn, raw: content };
328
+ } catch (error) {
329
+ if (throwOnError) throw error;
330
+ return { type: "wildcard", value: "*", raw: content };
331
+ }
332
+ }
333
+ if (trimmed.startsWith('"') && trimmed.endsWith('"') || trimmed.startsWith("'") && trimmed.endsWith("'")) {
334
+ return { type: "property", value: trimmed.slice(1, -1), raw: content };
335
+ }
336
+ return { type: "property", value: trimmed, raw: content };
337
+ };
338
+ for (let i = 0; i < selector.length; i++) {
339
+ const char = selector[i];
340
+ const nextChar = selector[i + 1];
341
+ if ((char === '"' || char === "'") && !inQuotes) {
342
+ inQuotes = true;
343
+ quoteChar = char;
344
+ continue;
345
+ } else if (char === quoteChar && inQuotes) {
346
+ inQuotes = false;
347
+ quoteChar = "";
348
+ if (!(char === '"' || char === "'")) {
349
+ if (inBrackets) {
350
+ bracketContent += char;
351
+ } else {
352
+ current += char;
353
+ }
354
+ }
355
+ continue;
356
+ }
357
+ if (inQuotes) {
358
+ if (inBrackets) {
359
+ bracketContent += char;
360
+ } else {
361
+ current += char;
362
+ }
363
+ continue;
364
+ }
365
+ if (char === "[" && !inBrackets) {
366
+ if (current) {
367
+ segments.push({ type: "property", value: current, raw: current });
368
+ current = "";
369
+ }
370
+ inBrackets = true;
371
+ bracketContent = "";
372
+ continue;
373
+ }
374
+ if (char === "]" && inBrackets && !inQuotes) {
375
+ inBrackets = false;
376
+ const segment2 = parseBracketContent(bracketContent);
377
+ segments.push(segment2);
378
+ continue;
379
+ }
380
+ let lastDot = segments.length > 0 ? segments[segments.length - 1] : null;
381
+ if (char === "." && !inBrackets && !inQuotes) {
382
+ if (nextChar === ".") {
383
+ const l = selector.split("..")[0];
384
+ segments.push({ type: "property", value: l, raw: l });
385
+ segments.push({ type: "descendant", value: "..", raw: ".." });
386
+ i++;
387
+ } else if (current) {
388
+ if (current === "*") {
389
+ segments.push({ type: "wildcard", value: current, raw: current });
390
+ } else {
391
+ segments.push({ type: "property", value: current, raw: current });
392
+ }
393
+ current = "";
394
+ }
395
+ continue;
396
+ }
397
+ if (inBrackets) {
398
+ bracketContent += char;
399
+ } else {
400
+ if (lastDot && lastDot.type !== "descendant") {
401
+ current += char;
402
+ } else {
403
+ const l = selector.split(lastDot?.raw)[1];
404
+ if (l !== void 0) {
405
+ current = l;
406
+ } else {
407
+ current += char;
408
+ }
409
+ }
410
+ }
411
+ }
412
+ if (current) {
413
+ segments.push({ type: "property", value: current, raw: current });
414
+ }
415
+ return segments.map((segment2) => {
416
+ if (segment2.type === "property" && typeof segment2.value === "string") {
417
+ if (/^-?\d+$/.test(segment2.value)) {
418
+ const num = parseInt(segment2.value, 10);
419
+ if (!isNaN(num)) {
420
+ return { ...segment2, type: "index", value: num };
421
+ }
422
+ }
423
+ }
424
+ return segment2;
425
+ });
426
+ };
427
+ var createFilterFunction = (expr) => {
428
+ const safeExpr = expr.replace(/@\.([a-zA-Z_$][\w$]*)/g, (_, prop) => `item.${prop}`).replace(/@/g, "item");
429
+ try {
430
+ return new Function("item", `return ${safeExpr}`);
431
+ } catch (error) {
432
+ throw new Error(`Invalid filter expression: ${expr}`);
433
+ }
434
+ };
435
+
436
+ // src/lib/object/merge.ts
437
+ var mergeIntoStructure = (target, selector, value) => {
438
+ const segments = parseSelector(selector);
439
+ let current = target;
440
+ for (let i = 0; i < segments.length; i++) {
441
+ const segment2 = segments[i];
442
+ const isLast = i === segments.length - 1;
443
+ switch (segment2.type) {
444
+ case "property":
445
+ if (isLast) {
446
+ current[String(segment2.value)] = value;
447
+ } else {
448
+ if (!current[String(segment2.value)]) {
449
+ const nextSegment = segments[i + 1];
450
+ current[String(segment2.value)] = nextSegment.type === "index" || nextSegment.type === "slice" || nextSegment.type === "union" || nextSegment.type === "wildcard" ? [] : {};
451
+ }
452
+ current = current[String(segment2.value)];
453
+ }
454
+ break;
455
+ case "index":
456
+ if (!Array.isArray(current)) {
457
+ current = [];
458
+ }
459
+ const index = segment2.value;
460
+ if (isLast) {
461
+ if (index >= current.length) {
462
+ for (let j = current.length; j <= index; j++) {
463
+ current.push(void 0);
464
+ }
465
+ }
466
+ current[index] = value;
467
+ } else {
468
+ if (!current[index]) {
469
+ const nextSegment = segments[i + 1];
470
+ current[index] = nextSegment.type === "index" || nextSegment.type === "slice" || nextSegment.type === "union" || nextSegment.type === "wildcard" ? [] : {};
471
+ }
472
+ current = current[index];
473
+ }
474
+ break;
475
+ case "wildcard":
476
+ if (Array.isArray(current)) {
477
+ if (isLast) {
478
+ for (let j = 0; j < current.length; j++) {
479
+ current[j] = value;
480
+ }
481
+ } else {
482
+ const nextSegment = segments[i + 1];
483
+ for (let j = 0; j < current.length; j++) {
484
+ if (!current[j]) {
485
+ current[j] = nextSegment.type === "index" || nextSegment.type === "slice" || nextSegment.type === "union" || nextSegment.type === "wildcard" ? [] : {};
486
+ }
487
+ }
488
+ if (current.length > 0) {
489
+ current = current[0];
490
+ }
491
+ }
492
+ }
493
+ break;
494
+ }
495
+ }
496
+ };
497
+
498
+ // src/lib/object/getter-setter.ts
499
+ function get(obj, selector, options = {}) {
500
+ const {
501
+ preserveStructure,
502
+ multiple,
503
+ throwOnError = false,
504
+ defaultValue,
505
+ maxDepth = 20
506
+ } = options;
507
+ if (!obj || typeof obj !== "object") {
508
+ return defaultValue;
509
+ }
510
+ if (!selector) {
511
+ return obj;
512
+ }
513
+ if (Array.isArray(selector)) {
514
+ if (preserveStructure) {
515
+ const result2 = {};
516
+ for (const sel of selector) {
517
+ const value = get(obj, sel, { ...options, preserveStructure: false });
518
+ if (value !== void 0) {
519
+ mergeIntoStructure(result2, sel, value);
520
+ }
521
+ }
522
+ return result2;
523
+ } else {
524
+ return selector.map(
525
+ (sel) => get(obj, sel, { ...options, preserveStructure: false })
526
+ );
527
+ }
528
+ }
529
+ const segments = parseSelector(selector, { ...options, throwOnError });
530
+ if (segments.length === 0) {
531
+ return obj;
532
+ }
533
+ if (typeof preserveStructure === "undefined" || preserveStructure === false) {
534
+ const v = ValueOfKey(obj, selector);
535
+ if (multiple === false && Array.isArray(v)) {
536
+ return v[0];
537
+ }
538
+ if (v === void 0 && defaultValue !== void 0) {
539
+ return defaultValue;
540
+ }
541
+ return v;
542
+ }
543
+ const result = traverseStructure(obj, segments, 0, maxDepth);
544
+ if (result === void 0 && defaultValue !== void 0) {
545
+ return defaultValue;
546
+ }
547
+ return result;
548
+ }
549
+ function ValueOfKey(obj, selector, options = {}) {
550
+ const { createMissing = false, add = false, debug = false } = options;
551
+ const segments = parseSelector(selector);
552
+ let current = obj;
553
+ let updateEvenIfNotlast = false;
554
+ let chained_property = "";
555
+ const stringify = selector;
556
+ if (typeof current === "object" && !Array.isArray(current) && stringify.length > 0) {
557
+ if (current[stringify]) {
558
+ current = current[stringify];
559
+ return current;
560
+ }
561
+ }
562
+ for (let i = 0; i < segments.length; i++) {
563
+ const segment2 = segments[i];
564
+ const isLast = segments.length > 1 ? i === segments.length - 1 : false;
565
+ if (current === null && !createMissing) {
566
+ return void 0;
567
+ }
568
+ const nextSegment = segments[i + 1];
569
+ switch (segment2.type) {
570
+ case "property":
571
+ if (current && typeof current === "object") {
572
+ if (Array.isArray(current)) {
573
+ if (typeof segment2.value === "number") {
574
+ const index = segment2.value;
575
+ if (createMissing && index >= current.length) {
576
+ for (let j = current.length; j <= index; j++) {
577
+ current.push(void 0);
578
+ }
579
+ }
580
+ if (createMissing && (current[index] === null || current[index] === void 0) && (!isLast || updateEvenIfNotlast)) {
581
+ if (nextSegment) {
582
+ current[index] = nextSegment.type === "index" || nextSegment.type === "slice" || nextSegment.type === "union" || nextSegment.type === "wildcard" ? [] : {};
583
+ } else {
584
+ current[index] = null;
585
+ }
586
+ updateEvenIfNotlast = false;
587
+ }
588
+ current = current[index];
589
+ if (nextSegment) {
590
+ updateEvenIfNotlast = true;
591
+ continue;
592
+ }
593
+ } else if (add) {
594
+ current.push({
595
+ [String(segment2.value)]: null
596
+ });
597
+ } else {
598
+ current = current.map((item) => item[String(segment2.value)]);
599
+ }
600
+ if (nextSegment) {
601
+ continue;
602
+ }
603
+ return filterDefined(current);
604
+ } else {
605
+ if (current[chained_property] && chained_property.split(".").length >= 2) {
606
+ current = current[chained_property];
607
+ continue;
608
+ }
609
+ if (createMissing && (current[String(segment2.value)] === null || current[String(segment2.value)] === void 0) && (!isLast || updateEvenIfNotlast)) {
610
+ if (nextSegment) {
611
+ current[String(segment2.value)] = nextSegment.type === "index" || nextSegment.type === "slice" || nextSegment.type === "union" || nextSegment.type === "wildcard" ? [] : {};
612
+ } else {
613
+ current[String(segment2.value)] = null;
614
+ }
615
+ updateEvenIfNotlast = false;
616
+ current = current[String(segment2.value)];
617
+ if (nextSegment) {
618
+ updateEvenIfNotlast = true;
619
+ continue;
620
+ }
621
+ }
622
+ if (!current) {
623
+ current = { [String(segment2.value)]: null };
624
+ } else {
625
+ if (!current[String(segment2.value)] && createMissing) {
626
+ current[String(segment2.value)] = null;
627
+ }
628
+ current = current[String(segment2.value)];
629
+ }
630
+ if (nextSegment) {
631
+ continue;
632
+ }
633
+ }
634
+ } else if (createMissing) {
635
+ current = {};
636
+ current[String(segment2.value)] = nextSegment.type === "index" || nextSegment.type === "slice" || nextSegment.type === "union" || nextSegment.type === "wildcard" || options.type === "array" ? [] : {};
637
+ current = current[String(segment2.value)];
638
+ } else {
639
+ return void 0;
640
+ }
641
+ break;
642
+ case "index":
643
+ case "wildcard":
644
+ if (Array.isArray(current)) {
645
+ if (segment2.type === "index") {
646
+ const index = segment2.value;
647
+ if (index < 0) {
648
+ current = current[current.length - Math.abs(index)];
649
+ continue;
650
+ }
651
+ if (createMissing && (index >= current.length || current[index] == null || current[index] == void 0) && !isLast) {
652
+ for (let j = current.length; j <= index; j++) {
653
+ current.push(void 0);
654
+ }
655
+ if (nextSegment) {
656
+ current[index] = nextSegment.type === "index" || nextSegment.type === "slice" || nextSegment.type === "union" || nextSegment.type === "wildcard" ? [] : {};
657
+ }
658
+ }
659
+ current = current[index];
660
+ } else {
661
+ if (!isLast) {
662
+ continue;
663
+ }
664
+ }
665
+ } else if (createMissing) {
666
+ const nextSegment2 = segments[i + 1];
667
+ current = [];
668
+ const index = segment2.value;
669
+ for (let j = 0; j <= index; j++) {
670
+ current.push(void 0);
671
+ }
672
+ current[index] = nextSegment2.type === "index" || nextSegment2.type === "slice" || nextSegment2.type === "union" || nextSegment2.type === "wildcard" || options.type === "array" ? [] : {};
673
+ current = current[index];
674
+ } else {
675
+ if (segment2.type === "index" && typeof current === "object") {
676
+ if (current && current[String(segment2.value)] !== void 0) {
677
+ current = current[String(segment2.value)];
678
+ continue;
679
+ }
680
+ }
681
+ if (typeof current === "object") {
682
+ const values = Object.values(current);
683
+ current = values;
684
+ continue;
685
+ }
686
+ return void 0;
687
+ }
688
+ break;
689
+ default:
690
+ return void 0;
691
+ }
692
+ }
693
+ return filterDefined(current);
694
+ }
695
+ function filterDefined(obj) {
696
+ if (Array.isArray(obj)) {
697
+ return obj.filter((item) => typeof item !== "undefined");
698
+ }
699
+ return obj;
700
+ }
701
+
702
+ // src/lib/array/advanced.ts
703
+ function chunk(array, size) {
704
+ if (!Array.isArray(array) || size < 1) {
705
+ return [];
706
+ }
707
+ const chunks = [];
708
+ for (let i = 0; i < array.length; i += size) {
709
+ chunks.push(array.slice(i, i + size));
710
+ }
711
+ return chunks;
712
+ }
713
+ function flatten(array) {
714
+ return array.reduce((acc, val) => {
715
+ return acc.concat(val);
716
+ }, []);
717
+ }
718
+ function flattenDeep(array, depth = Infinity) {
719
+ if (depth < 1) {
720
+ return array.slice();
721
+ }
722
+ return array.reduce((acc, val) => {
723
+ if (Array.isArray(val)) {
724
+ acc.push(...flattenDeep(val, depth - 1));
725
+ } else {
726
+ acc.push(val);
727
+ }
728
+ return acc;
729
+ }, []);
730
+ }
731
+ function unique(array, selector) {
732
+ if (!Array.isArray(array)) {
733
+ return [];
734
+ }
735
+ if (!selector) {
736
+ return [...new Set(array)];
737
+ }
738
+ const seen = /* @__PURE__ */ new Set();
739
+ return array.filter((item) => {
740
+ const value = typeof selector === "function" ? selector(item) : isObject(item) ? get(item, selector) : item;
741
+ if (seen.has(value)) {
742
+ return false;
743
+ }
744
+ seen.add(value);
745
+ return true;
746
+ });
747
+ }
748
+ function groupBy(array, keyOrFn) {
749
+ if (!Array.isArray(array)) {
750
+ return {};
751
+ }
752
+ return array.reduce((acc, item) => {
753
+ let key;
754
+ if (typeof keyOrFn === "function") {
755
+ key = String(keyOrFn(item));
756
+ } else {
757
+ key = String(isObject(item) ? get(item, keyOrFn) : item);
758
+ }
759
+ if (!acc[key]) {
760
+ acc[key] = [];
761
+ }
762
+ acc[key].push(item);
763
+ return acc;
764
+ }, {});
765
+ }
766
+ function countBy(array, key) {
767
+ if (!Array.isArray(array)) {
768
+ return {};
769
+ }
770
+ return array.reduce((acc, item) => {
771
+ let countKey;
772
+ if (typeof key === "function") {
773
+ countKey = String(key(item));
774
+ } else if (key) {
775
+ countKey = String(
776
+ isObject(item) ? get(item, key) : item
777
+ );
778
+ } else {
779
+ countKey = String(item);
780
+ }
781
+ acc[countKey] = (acc[countKey] || 0) + 1;
782
+ return acc;
783
+ }, {});
784
+ }
785
+ function keyBy(array, keyFn, valueFn) {
786
+ if (!Array.isArray(array)) {
787
+ return {};
788
+ }
789
+ return array.reduce((acc, item) => {
790
+ let key;
791
+ if (typeof keyFn === "function") {
792
+ key = String(keyFn(item));
793
+ } else {
794
+ key = String(isObject(item) ? get(item, keyFn) : item);
795
+ }
796
+ let value;
797
+ if (valueFn) {
798
+ if (typeof valueFn === "function") {
799
+ value = valueFn(item);
800
+ } else {
801
+ value = get(item, valueFn);
802
+ }
803
+ } else {
804
+ value = item;
805
+ }
806
+ acc[key] = value;
807
+ return acc;
808
+ }, {});
809
+ }
810
+ function sortBy(array, keys) {
811
+ if (!Array.isArray(array) || array.length === 0) {
812
+ return [];
813
+ }
814
+ const sorted = [...array];
815
+ const keysArray = Array.isArray(keys) ? keys : [keys];
816
+ const normalizedKeys = keysArray.map((k) => {
817
+ if (typeof k === "object" && "key" in k) {
818
+ return { key: k.key, dir: k.dir || "asc" };
819
+ }
820
+ return { key: k, dir: "asc" };
821
+ });
822
+ sorted.sort((a, b) => {
823
+ for (const { key, dir } of normalizedKeys) {
824
+ const aVal = isObject(a) ? get(a, key) : a;
825
+ const bVal = isObject(b) ? get(b, key) : b;
826
+ if (aVal === bVal) continue;
827
+ const comparison = aVal < bVal ? -1 : 1;
828
+ return dir === "asc" ? comparison : -comparison;
829
+ }
830
+ return 0;
831
+ });
832
+ return sorted;
833
+ }
834
+ function difference(array1, array2, key) {
835
+ if (!Array.isArray(array1)) return [];
836
+ if (!Array.isArray(array2)) return array1;
837
+ if (!key) {
838
+ const set2 = new Set(array2);
839
+ return array1.filter((item) => !set2.has(item));
840
+ }
841
+ const values2 = new Set(
842
+ array2.map(
843
+ (item) => isObject(item) ? get(item, key) : item
844
+ )
845
+ );
846
+ return array1.filter((item) => {
847
+ const value = isObject(item) ? get(item, key) : item;
848
+ return !values2.has(value);
849
+ });
850
+ }
851
+ function intersection(array1, array2, key) {
852
+ if (!Array.isArray(array1) || !Array.isArray(array2)) {
853
+ return [];
854
+ }
855
+ if (!key) {
856
+ const set2 = new Set(array2);
857
+ return array1.filter((item) => set2.has(item));
858
+ }
859
+ const values2 = new Set(
860
+ array2.map(
861
+ (item) => isObject(item) ? get(item, key) : item
862
+ )
863
+ );
864
+ return array1.filter((item) => {
865
+ const value = isObject(item) ? get(item, key) : item;
866
+ return values2.has(value);
867
+ });
868
+ }
869
+ function union(array1, array2, key) {
870
+ if (!Array.isArray(array1) && !Array.isArray(array2)) {
871
+ return [];
872
+ }
873
+ if (!Array.isArray(array1)) return unique(array2, key);
874
+ if (!Array.isArray(array2)) return unique(array1, key);
875
+ return unique([...array1, ...array2], key);
876
+ }
877
+ function partition(array, predicate) {
878
+ if (!Array.isArray(array)) {
879
+ return [[], []];
880
+ }
881
+ return array.reduce(
882
+ (acc, item, index) => {
883
+ acc[predicate(item, index) ? 0 : 1].push(item);
884
+ return acc;
885
+ },
886
+ [[], []]
887
+ );
888
+ }
889
+ function take(array, n) {
890
+ if (!Array.isArray(array) || n <= 0) {
891
+ return [];
892
+ }
893
+ return array.slice(0, n);
894
+ }
895
+ function takeLast(array, n) {
896
+ if (!Array.isArray(array) || n <= 0) {
897
+ return [];
898
+ }
899
+ return array.slice(-n);
900
+ }
901
+ function takeWhile(array, predicate) {
902
+ if (!Array.isArray(array)) {
903
+ return [];
904
+ }
905
+ const result = [];
906
+ for (let i = 0; i < array.length; i++) {
907
+ if (!predicate(array[i], i)) break;
908
+ result.push(array[i]);
909
+ }
910
+ return result;
911
+ }
912
+ function drop(array, n) {
913
+ if (!Array.isArray(array) || n <= 0) {
914
+ return array ? [...array] : [];
915
+ }
916
+ return array.slice(n);
917
+ }
918
+ function dropWhile(array, predicate) {
919
+ if (!Array.isArray(array)) {
920
+ return [];
921
+ }
922
+ let index = 0;
923
+ while (index < array.length && predicate(array[index], index)) {
924
+ index++;
925
+ }
926
+ return array.slice(index);
927
+ }
928
+ function compact(array) {
929
+ if (!Array.isArray(array)) {
930
+ return [];
931
+ }
932
+ return array.filter(Boolean);
933
+ }
934
+ function zip(...arrays) {
935
+ if (arrays.length === 0) return [];
936
+ const maxLength = Math.max(
937
+ ...arrays.map((arr) => Array.isArray(arr) ? arr.length : 0)
938
+ );
939
+ const result = [];
940
+ for (let i = 0; i < maxLength; i++) {
941
+ const tuple = [];
942
+ for (const array of arrays) {
943
+ tuple.push(Array.isArray(array) ? array[i] : void 0);
944
+ }
945
+ result.push(tuple);
946
+ }
947
+ return result;
948
+ }
949
+ function unzip(array) {
950
+ if (!Array.isArray(array) || array.length === 0) {
951
+ return [];
952
+ }
953
+ const maxLength = Math.max(
954
+ ...array.map((arr) => Array.isArray(arr) ? arr.length : 0)
955
+ );
956
+ const result = [];
957
+ for (let i = 0; i < maxLength; i++) {
958
+ const tuple = [];
959
+ for (const arr of array) {
960
+ if (Array.isArray(arr)) {
961
+ tuple.push(arr[i]);
962
+ }
963
+ }
964
+ result.push(tuple);
965
+ }
966
+ return result;
967
+ }
968
+ function shuffle(array) {
969
+ if (!Array.isArray(array)) {
970
+ return [];
971
+ }
972
+ const result = [...array];
973
+ for (let i = result.length - 1; i > 0; i--) {
974
+ const j = Math.floor(Math.random() * (i + 1));
975
+ [result[i], result[j]] = [result[j], result[i]];
976
+ }
977
+ return result;
978
+ }
979
+ function sample(array) {
980
+ if (!Array.isArray(array) || array.length === 0) {
981
+ return void 0;
982
+ }
983
+ return array[Math.floor(Math.random() * array.length)];
984
+ }
985
+ function sampleSize(array, n) {
986
+ if (!Array.isArray(array) || n <= 0) {
987
+ return [];
988
+ }
989
+ const shuffled = shuffle(array);
990
+ return shuffled.slice(0, Math.min(n, array.length));
991
+ }
992
+ function findIndex(array, predicate, fromIndex = 0) {
993
+ if (!Array.isArray(array)) {
994
+ return -1;
995
+ }
996
+ for (let i = fromIndex; i < array.length; i++) {
997
+ if (predicate(array[i], i)) {
998
+ return i;
999
+ }
1000
+ }
1001
+ return -1;
1002
+ }
1003
+ function findLastIndex(array, predicate, fromIndex) {
1004
+ if (!Array.isArray(array)) {
1005
+ return -1;
1006
+ }
1007
+ const startIndex = fromIndex !== void 0 ? fromIndex : array.length - 1;
1008
+ for (let i = startIndex; i >= 0; i--) {
1009
+ if (predicate(array[i], i)) {
1010
+ return i;
1011
+ }
1012
+ }
1013
+ return -1;
1014
+ }
1015
+ function pluck(array, path) {
1016
+ if (!Array.isArray(array)) {
1017
+ return [];
1018
+ }
1019
+ return array.map((item) => get(item, path));
1020
+ }
1021
+ function pick(array, keys) {
1022
+ if (!Array.isArray(array) || !Array.isArray(keys)) {
1023
+ return [];
1024
+ }
1025
+ return array.map((item) => {
1026
+ const result = {};
1027
+ for (const key of keys) {
1028
+ if (key in item) {
1029
+ result[key] = item[key];
1030
+ }
1031
+ }
1032
+ return result;
1033
+ });
1034
+ }
1035
+ function omit(array, keys) {
1036
+ if (!Array.isArray(array) || !Array.isArray(keys)) {
1037
+ return [];
1038
+ }
1039
+ return array.map((item) => {
1040
+ const result = { ...item };
1041
+ for (const key of keys) {
1042
+ delete result[key];
1043
+ }
1044
+ return result;
1045
+ });
1046
+ }
1047
+ function flatMap(array, callback) {
1048
+ if (!Array.isArray(array)) {
1049
+ return [];
1050
+ }
1051
+ return array.reduce((acc, item, index) => {
1052
+ const result = callback(item, index);
1053
+ return acc.concat(result);
1054
+ }, []);
1055
+ }
1056
+ function reduceRight(array, callback, initialValue) {
1057
+ if (!Array.isArray(array)) {
1058
+ return initialValue;
1059
+ }
1060
+ let accumulator = initialValue;
1061
+ for (let i = array.length - 1; i >= 0; i--) {
1062
+ accumulator = callback(accumulator, array[i], i);
1063
+ }
1064
+ return accumulator;
1065
+ }
1066
+ function range(start, end, step = 1) {
1067
+ if (step === 0) {
1068
+ return [];
1069
+ }
1070
+ const result = [];
1071
+ if (step > 0) {
1072
+ for (let i = start; i < end; i += step) {
1073
+ result.push(i);
1074
+ }
1075
+ } else {
1076
+ for (let i = start; i > end; i += step) {
1077
+ result.push(i);
1078
+ }
1079
+ }
1080
+ return result;
1081
+ }
1082
+ function fill(array, value, start = 0, end) {
1083
+ if (!Array.isArray(array)) {
1084
+ return [];
1085
+ }
1086
+ const result = [...array];
1087
+ const actualEnd = end === void 0 ? result.length : end;
1088
+ for (let i = start; i < actualEnd && i < result.length; i++) {
1089
+ result[i] = value;
1090
+ }
1091
+ return result;
1092
+ }
1093
+ function deepCloneArray(array) {
1094
+ if (!Array.isArray(array)) {
1095
+ return [];
1096
+ }
1097
+ return deepClone(array);
1098
+ }
1099
+ function mergeByKey(arr1, arr2, ...keyOrMore) {
1100
+ let key;
1101
+ let arrays;
1102
+ if (typeof arr2 === "string") {
1103
+ key = arr2;
1104
+ arrays = [arr1];
1105
+ } else {
1106
+ const lastArg = keyOrMore[keyOrMore.length - 1];
1107
+ if (typeof lastArg === "string") {
1108
+ key = lastArg;
1109
+ arrays = [
1110
+ arr1,
1111
+ arr2,
1112
+ ...keyOrMore.slice(0, -1).filter(Array.isArray)
1113
+ ];
1114
+ } else {
1115
+ key = "id";
1116
+ arrays = [arr1, arr2, ...keyOrMore.filter(Array.isArray)];
1117
+ }
1118
+ }
1119
+ if (arrays.length === 0) {
1120
+ return [];
1121
+ }
1122
+ const map = /* @__PURE__ */ new Map();
1123
+ for (const array of arrays) {
1124
+ if (Array.isArray(array)) {
1125
+ for (const item of array) {
1126
+ const keyValue = isObject(item) ? get(item, key) : void 0;
1127
+ if (keyValue !== void 0) {
1128
+ const existing = map.get(keyValue);
1129
+ map.set(keyValue, existing ? { ...existing, ...item } : item);
1130
+ }
1131
+ }
1132
+ }
1133
+ }
1134
+ return Array.from(map.values());
1135
+ }
1136
+ function move(array, fromIndex, toIndex) {
1137
+ if (!Array.isArray(array) || fromIndex === toIndex) {
1138
+ return array ? [...array] : [];
1139
+ }
1140
+ const result = [...array];
1141
+ const [removed] = result.splice(fromIndex, 1);
1142
+ result.splice(toIndex, 0, removed);
1143
+ return result;
1144
+ }
1145
+ function rotate(array, n) {
1146
+ if (!Array.isArray(array) || array.length === 0 || n === 0) {
1147
+ return array ? [...array] : [];
1148
+ }
1149
+ const len = array.length;
1150
+ const rotations = (n % len + len) % len;
1151
+ return [...array.slice(-rotations), ...array.slice(0, -rotations)];
1152
+ }
1153
+ function insert(array, index, ...items) {
1154
+ if (!Array.isArray(array)) {
1155
+ return items;
1156
+ }
1157
+ const result = [...array];
1158
+ result.splice(index, 0, ...items);
1159
+ return result;
1160
+ }
1161
+ function remove(array, index, count = 1) {
1162
+ if (!Array.isArray(array)) {
1163
+ return [];
1164
+ }
1165
+ const result = [...array];
1166
+ result.splice(index, count);
1167
+ return result;
1168
+ }
1169
+ function replace(array, index, item) {
1170
+ if (!Array.isArray(array)) {
1171
+ return [];
1172
+ }
1173
+ const result = [...array];
1174
+ result[index] = item;
1175
+ return result;
1176
+ }
1177
+ function filterCompact(array, predicate) {
1178
+ if (!Array.isArray(array)) {
1179
+ return [];
1180
+ }
1181
+ const filtered = array.filter((item) => item != null);
1182
+ return predicate ? filtered.filter(predicate) : filtered;
1183
+ }
1184
+ function cartesian(...arrays) {
1185
+ if (arrays.length === 0) return [[]];
1186
+ if (arrays.length === 1) return arrays[0].map((item) => [item]);
1187
+ return arrays.reduce(
1188
+ (acc, array) => {
1189
+ return acc.flatMap((x) => array.map((y) => [...x, y]));
1190
+ },
1191
+ [[]]
1192
+ );
1193
+ }
1194
+ function findAllIndices(array, predicate) {
1195
+ if (!Array.isArray(array)) {
1196
+ return [];
1197
+ }
1198
+ const indices = [];
1199
+ for (let i = 0; i < array.length; i++) {
1200
+ if (predicate(array[i], i)) {
1201
+ indices.push(i);
1202
+ }
1203
+ }
1204
+ return indices;
1205
+ }
1206
+ function isEqual(array1, array2, deep = true) {
1207
+ if (!Array.isArray(array1) || !Array.isArray(array2)) {
1208
+ return false;
1209
+ }
1210
+ if (array1.length !== array2.length) {
1211
+ return false;
1212
+ }
1213
+ for (let i = 0; i < array1.length; i++) {
1214
+ if (deep && isObject(array1[i]) && isObject(array2[i])) {
1215
+ if (JSON.stringify(array1[i]) !== JSON.stringify(array2[i])) {
1216
+ return false;
1217
+ }
1218
+ } else if (array1[i] !== array2[i]) {
1219
+ return false;
1220
+ }
1221
+ }
1222
+ return true;
1223
+ }
1224
+ function chunkBy(array, predicate) {
1225
+ if (!Array.isArray(array) || array.length === 0) {
1226
+ return [];
1227
+ }
1228
+ const result = [];
1229
+ let currentChunk = [array[0]];
1230
+ let currentKey = predicate(array[0], 0);
1231
+ for (let i = 1; i < array.length; i++) {
1232
+ const key = predicate(array[i], i);
1233
+ if (key === currentKey) {
1234
+ currentChunk.push(array[i]);
1235
+ } else {
1236
+ result.push(currentChunk);
1237
+ currentChunk = [array[i]];
1238
+ currentKey = key;
1239
+ }
1240
+ }
1241
+ result.push(currentChunk);
1242
+ return result;
1243
+ }
1244
+ function updateBy(array, predicate, updates, updatesOrUndefined) {
1245
+ if (!Array.isArray(array)) {
1246
+ return [];
1247
+ }
1248
+ const isPredicate = typeof predicate === "function";
1249
+ const actualUpdates = isPredicate ? updates : updatesOrUndefined;
1250
+ return array.map((item) => {
1251
+ let shouldUpdate = false;
1252
+ if (isPredicate) {
1253
+ shouldUpdate = predicate(item);
1254
+ } else {
1255
+ const itemValue = isObject(item) ? get(item, predicate) : item;
1256
+ shouldUpdate = itemValue === updates;
1257
+ }
1258
+ if (shouldUpdate) {
1259
+ return { ...item, ...actualUpdates };
1260
+ }
1261
+ return item;
1262
+ });
1263
+ }
1264
+ function splitDuplicates(array, key) {
1265
+ if (!Array.isArray(array)) {
1266
+ return { unique: [], duplicates: [] };
1267
+ }
1268
+ const seen = /* @__PURE__ */ new Set();
1269
+ const unique2 = [];
1270
+ const duplicates = [];
1271
+ for (const item of array) {
1272
+ const value = key && isObject(item) ? get(item, key) : item;
1273
+ if (seen.has(value)) {
1274
+ duplicates.push(item);
1275
+ } else {
1276
+ seen.add(value);
1277
+ unique2.push(item);
1278
+ }
1279
+ }
1280
+ return { unique: unique2, duplicates };
1281
+ }
1282
+ function ensureArray(value) {
1283
+ if (Array.isArray(value)) {
1284
+ return value;
1285
+ }
1286
+ return value === void 0 || value === null ? [] : [value];
1287
+ }
1288
+ function wrap(value) {
1289
+ return ensureArray(value);
1290
+ }
1291
+ function slidingWindow(array, size, step = 1) {
1292
+ if (!Array.isArray(array) || size < 1 || step < 1) {
1293
+ return [];
1294
+ }
1295
+ const windows = [];
1296
+ for (let i = 0; i <= array.length - size; i += step) {
1297
+ windows.push(array.slice(i, i + size));
1298
+ }
1299
+ return windows;
1300
+ }
1301
+ function minBy(array, selector) {
1302
+ if (!Array.isArray(array) || array.length === 0) {
1303
+ return void 0;
1304
+ }
1305
+ let minItem = array[0];
1306
+ let minValue = typeof selector === "function" ? selector(minItem) : get(minItem, selector);
1307
+ for (let i = 1; i < array.length; i++) {
1308
+ const item = array[i];
1309
+ const value = typeof selector === "function" ? selector(item) : get(item, selector);
1310
+ if (value < minValue) {
1311
+ minValue = value;
1312
+ minItem = item;
1313
+ }
1314
+ }
1315
+ return minItem;
1316
+ }
1317
+ function maxBy(array, selector) {
1318
+ if (!Array.isArray(array) || array.length === 0) {
1319
+ return void 0;
1320
+ }
1321
+ let maxItem = array[0];
1322
+ let maxValue = typeof selector === "function" ? selector(maxItem) : get(maxItem, selector);
1323
+ for (let i = 1; i < array.length; i++) {
1324
+ const item = array[i];
1325
+ const value = typeof selector === "function" ? selector(item) : get(item, selector);
1326
+ if (value > maxValue) {
1327
+ maxValue = value;
1328
+ maxItem = item;
1329
+ }
1330
+ }
1331
+ return maxItem;
1332
+ }
1333
+ function sumBy(array, selector) {
1334
+ if (!Array.isArray(array) || array.length === 0) {
1335
+ return 0;
1336
+ }
1337
+ let sum = 0;
1338
+ for (const item of array) {
1339
+ const value = typeof selector === "function" ? selector(item) : get(item, selector);
1340
+ if (typeof value === "number" && !isNaN(value)) {
1341
+ sum += value;
1342
+ }
1343
+ }
1344
+ return sum;
1345
+ }
1346
+ function avgBy(array, selector) {
1347
+ if (!Array.isArray(array) || array.length === 0) {
1348
+ return 0;
1349
+ }
1350
+ const sum = sumBy(array, selector);
1351
+ return sum / array.length;
1352
+ }
1353
+ function frequencies(array) {
1354
+ const freqMap = /* @__PURE__ */ new Map();
1355
+ if (!Array.isArray(array)) {
1356
+ return freqMap;
1357
+ }
1358
+ for (const item of array) {
1359
+ freqMap.set(item, (freqMap.get(item) || 0) + 1);
1360
+ }
1361
+ return freqMap;
1362
+ }
1363
+ function mostCommon(array, limit = 1) {
1364
+ if (!Array.isArray(array) || array.length === 0 || limit < 1) {
1365
+ return [];
1366
+ }
1367
+ const freqMap = frequencies(array);
1368
+ const sorted = Array.from(freqMap.entries()).sort((a, b) => b[1] - a[1]);
1369
+ return sorted.slice(0, limit).map(([value]) => value);
1370
+ }
1371
+ function leastCommon(array, limit = 1) {
1372
+ if (!Array.isArray(array) || array.length === 0 || limit < 1) {
1373
+ return [];
1374
+ }
1375
+ const freqMap = frequencies(array);
1376
+ const sorted = Array.from(freqMap.entries()).sort((a, b) => a[1] - b[1]);
1377
+ return sorted.slice(0, limit).map(([value]) => value);
1378
+ }
1379
+ async function batchProcess(array, batchSize, callback) {
1380
+ if (!Array.isArray(array) || batchSize < 1) {
1381
+ return;
1382
+ }
1383
+ const batches = chunk(array, batchSize);
1384
+ for (let i = 0; i < batches.length; i++) {
1385
+ await callback(batches[i], i);
1386
+ }
1387
+ }
1388
+ async function batchProcessParallel(array, batchSize, concurrency, callback) {
1389
+ if (!Array.isArray(array) || batchSize < 1 || concurrency < 1) {
1390
+ return;
1391
+ }
1392
+ const batches = chunk(array, batchSize);
1393
+ const batchChunks = chunk(
1394
+ batches.map((batch2, index) => ({ batch: batch2, index })),
1395
+ concurrency
1396
+ );
1397
+ for (const batchChunk of batchChunks) {
1398
+ await Promise.all(
1399
+ batchChunk.map(({ batch: batch2, index }) => callback(batch2, index))
1400
+ );
1401
+ }
1402
+ }
1403
+ function transpose(matrix) {
1404
+ if (!Array.isArray(matrix) || matrix.length === 0) {
1405
+ return [];
1406
+ }
1407
+ const maxLength = Math.max(...matrix.map((row) => row.length));
1408
+ const result = [];
1409
+ for (let col = 0; col < maxLength; col++) {
1410
+ const column = [];
1411
+ for (let row = 0; row < matrix.length; row++) {
1412
+ if (col < matrix[row].length) {
1413
+ column.push(matrix[row][col]);
1414
+ }
1415
+ }
1416
+ result.push(column);
1417
+ }
1418
+ return result;
1419
+ }
1420
+ function isArrayEqual(array1, array2) {
1421
+ if (!Array.isArray(array1) || !Array.isArray(array2)) {
1422
+ return false;
1423
+ }
1424
+ if (array1.length !== array2.length) {
1425
+ return false;
1426
+ }
1427
+ for (let i = 0; i < array1.length; i++) {
1428
+ if (array1[i] !== array2[i]) {
1429
+ return false;
1430
+ }
1431
+ }
1432
+ return true;
1433
+ }
1434
+ function hasSameElements(array1, array2) {
1435
+ if (!Array.isArray(array1) || !Array.isArray(array2)) {
1436
+ return false;
1437
+ }
1438
+ if (array1.length !== array2.length) {
1439
+ return false;
1440
+ }
1441
+ const freq1 = frequencies(array1);
1442
+ const freq2 = frequencies(array2);
1443
+ if (freq1.size !== freq2.size) {
1444
+ return false;
1445
+ }
1446
+ for (const [key, count] of freq1) {
1447
+ if (freq2.get(key) !== count) {
1448
+ return false;
1449
+ }
1450
+ }
1451
+ return true;
1452
+ }
1453
+ function isSubset(array1, array2) {
1454
+ if (!Array.isArray(array1) || !Array.isArray(array2)) {
1455
+ return false;
1456
+ }
1457
+ const set2 = new Set(array2);
1458
+ return array1.every((item) => set2.has(item));
1459
+ }
1460
+ function isSuperset(array1, array2) {
1461
+ return isSubset(array2, array1);
1462
+ }
1463
+ function interleave(...arrays) {
1464
+ if (arrays.length === 0) {
1465
+ return [];
1466
+ }
1467
+ const maxLength = Math.max(...arrays.map((arr) => arr.length));
1468
+ const result = [];
1469
+ for (let i = 0; i < maxLength; i++) {
1470
+ for (const arr of arrays) {
1471
+ if (i < arr.length) {
1472
+ result.push(arr[i]);
1473
+ }
1474
+ }
1475
+ }
1476
+ return result;
1477
+ }
1478
+ function bifurcate(array, predicate) {
1479
+ const pass = [];
1480
+ const fail = [];
1481
+ if (!Array.isArray(array)) {
1482
+ return { pass, fail };
1483
+ }
1484
+ for (let i = 0; i < array.length; i++) {
1485
+ if (predicate(array[i], i)) {
1486
+ pass.push(array[i]);
1487
+ } else {
1488
+ fail.push(array[i]);
1489
+ }
1490
+ }
1491
+ return { pass, fail };
1492
+ }
1493
+ function generate(length, generator) {
1494
+ if (length < 0) {
1495
+ return [];
1496
+ }
1497
+ const result = [];
1498
+ for (let i = 0; i < length; i++) {
1499
+ result.push(generator(i));
1500
+ }
1501
+ return result;
1502
+ }
1503
+ function repeat(array, times) {
1504
+ if (!Array.isArray(array) || times < 0) {
1505
+ return [];
1506
+ }
1507
+ const result = [];
1508
+ for (let i = 0; i < times; i++) {
1509
+ result.push(...array);
1510
+ }
1511
+ return result;
1512
+ }
1513
+ function median(array) {
1514
+ if (!Array.isArray(array) || array.length === 0) {
1515
+ return void 0;
1516
+ }
1517
+ const sorted = [...array].sort((a, b) => a - b);
1518
+ const mid = Math.floor(sorted.length / 2);
1519
+ if (sorted.length % 2 === 0) {
1520
+ return (sorted[mid - 1] + sorted[mid]) / 2;
1521
+ }
1522
+ return sorted[mid];
1523
+ }
1524
+ function mode(array) {
1525
+ const common = mostCommon(array, 1);
1526
+ return common.length > 0 ? common[0] : void 0;
1527
+ }
1528
+ function without(array, ...values) {
1529
+ if (!Array.isArray(array)) {
1530
+ return [];
1531
+ }
1532
+ const excludeSet = new Set(values);
1533
+ return array.filter((item) => !excludeSet.has(item));
1534
+ }
1535
+ function differenceWith(array, ...others) {
1536
+ if (!Array.isArray(array)) {
1537
+ return [];
1538
+ }
1539
+ const excludeSet = new Set(others.flat());
1540
+ return array.filter((item) => !excludeSet.has(item));
1541
+ }
1542
+ function groupConsecutive(array) {
1543
+ if (!Array.isArray(array) || array.length === 0) {
1544
+ return [];
1545
+ }
1546
+ const result = [];
1547
+ let currentGroup = [array[0]];
1548
+ for (let i = 1; i < array.length; i++) {
1549
+ if (array[i] === array[i - 1]) {
1550
+ currentGroup.push(array[i]);
1551
+ } else {
1552
+ result.push(currentGroup);
1553
+ currentGroup = [array[i]];
1554
+ }
1555
+ }
1556
+ result.push(currentGroup);
1557
+ return result;
1558
+ }
1559
+ function dedupeConsecutive(array) {
1560
+ if (!Array.isArray(array) || array.length === 0) {
1561
+ return [];
1562
+ }
1563
+ const result = [array[0]];
1564
+ for (let i = 1; i < array.length; i++) {
1565
+ if (array[i] !== array[i - 1]) {
1566
+ result.push(array[i]);
1567
+ }
1568
+ }
1569
+ return result;
1570
+ }
1571
+ function rank(array, method = "standard") {
1572
+ if (!Array.isArray(array) || array.length === 0) {
1573
+ return [];
1574
+ }
1575
+ const indexed = array.map((value, index) => ({ value, index }));
1576
+ indexed.sort((a, b) => a.value - b.value);
1577
+ const ranks = new Array(array.length);
1578
+ if (method === "ordinal") {
1579
+ for (let i = 0; i < indexed.length; i++) {
1580
+ ranks[indexed[i].index] = i + 1;
1581
+ }
1582
+ } else if (method === "dense") {
1583
+ let denseRank = 1;
1584
+ ranks[indexed[0].index] = denseRank;
1585
+ for (let i = 1; i < indexed.length; i++) {
1586
+ if (indexed[i].value !== indexed[i - 1].value) {
1587
+ denseRank++;
1588
+ }
1589
+ ranks[indexed[i].index] = denseRank;
1590
+ }
1591
+ } else {
1592
+ let i = 0;
1593
+ while (i < indexed.length) {
1594
+ let j = i;
1595
+ while (j < indexed.length && indexed[j].value === indexed[i].value) {
1596
+ j++;
1597
+ }
1598
+ const rankValue = i + 1;
1599
+ for (let k = i; k < j; k++) {
1600
+ ranks[indexed[k].index] = rankValue;
1601
+ }
1602
+ i = j;
1603
+ }
1604
+ }
1605
+ return ranks;
1606
+ }
1607
+ function percentile(array, percentile2) {
1608
+ if (!Array.isArray(array) || array.length === 0) {
1609
+ return void 0;
1610
+ }
1611
+ if (percentile2 < 0 || percentile2 > 100) {
1612
+ return void 0;
1613
+ }
1614
+ const sorted = [...array].sort((a, b) => a - b);
1615
+ const index = percentile2 / 100 * (sorted.length - 1);
1616
+ const lower = Math.floor(index);
1617
+ const upper = Math.ceil(index);
1618
+ const weight = index - lower;
1619
+ if (lower === upper) {
1620
+ return sorted[lower];
1621
+ }
1622
+ return sorted[lower] * (1 - weight) + sorted[upper] * weight;
1623
+ }
1624
+ function quartiles(array) {
1625
+ if (!Array.isArray(array) || array.length === 0) {
1626
+ return void 0;
1627
+ }
1628
+ const q1 = percentile(array, 25);
1629
+ const q2 = percentile(array, 50);
1630
+ const q3 = percentile(array, 75);
1631
+ return {
1632
+ q1,
1633
+ q2,
1634
+ q3,
1635
+ iqr: q3 - q1
1636
+ };
1637
+ }
1638
+ function standardDeviation(array, sample2 = false) {
1639
+ if (!Array.isArray(array) || array.length === 0) {
1640
+ return void 0;
1641
+ }
1642
+ if (sample2 && array.length === 1) {
1643
+ return void 0;
1644
+ }
1645
+ const avg = array.reduce((sum, val) => sum + val, 0) / array.length;
1646
+ const squareDiffs = array.map((value) => Math.pow(value - avg, 2));
1647
+ const avgSquareDiff = squareDiffs.reduce((sum, val) => sum + val, 0) / (sample2 ? array.length - 1 : array.length);
1648
+ return Math.sqrt(avgSquareDiff);
1649
+ }
1650
+ function variance(array, sample2 = false) {
1651
+ const std = standardDeviation(array, sample2);
1652
+ return std !== void 0 ? Math.pow(std, 2) : void 0;
1653
+ }
1654
+ function normalize(array) {
1655
+ if (!Array.isArray(array) || array.length === 0) {
1656
+ return [];
1657
+ }
1658
+ const min = Math.min(...array);
1659
+ const max = Math.max(...array);
1660
+ const range2 = max - min;
1661
+ if (range2 === 0) {
1662
+ return array.map(() => 0);
1663
+ }
1664
+ return array.map((value) => (value - min) / range2);
1665
+ }
1666
+ function standardize(array) {
1667
+ if (!Array.isArray(array) || array.length === 0) {
1668
+ return [];
1669
+ }
1670
+ const avg = array.reduce((sum, val) => sum + val, 0) / array.length;
1671
+ const std = standardDeviation(array);
1672
+ if (std === void 0 || std === 0) {
1673
+ return array.map(() => 0);
1674
+ }
1675
+ return array.map((value) => (value - avg) / std);
1676
+ }
1677
+ function scan(array, fn, initial) {
1678
+ if (!Array.isArray(array)) {
1679
+ return [];
1680
+ }
1681
+ const result = [];
1682
+ let accumulator = initial;
1683
+ for (let i = 0; i < array.length; i++) {
1684
+ accumulator = fn(accumulator, array[i], i);
1685
+ result.push(accumulator);
1686
+ }
1687
+ return result;
1688
+ }
1689
+ function cumulativeSum(array) {
1690
+ return scan(array, (acc, x) => acc + x, 0);
1691
+ }
1692
+ function diff(array) {
1693
+ if (!Array.isArray(array) || array.length < 2) {
1694
+ return [];
1695
+ }
1696
+ const result = [];
1697
+ for (let i = 1; i < array.length; i++) {
1698
+ result.push(array[i] - array[i - 1]);
1699
+ }
1700
+ return result;
1701
+ }
1702
+ function pad(array, length, value, position = "end") {
1703
+ if (!Array.isArray(array) || length <= array.length) {
1704
+ return [...array];
1705
+ }
1706
+ const padding = new Array(length - array.length).fill(value);
1707
+ return position === "start" ? [...padding, ...array] : [...array, ...padding];
1708
+ }
1709
+ function trim(array, predicate) {
1710
+ if (!Array.isArray(array) || array.length === 0) {
1711
+ return [];
1712
+ }
1713
+ let start = 0;
1714
+ let end = array.length - 1;
1715
+ while (start <= end && predicate(array[start])) {
1716
+ start++;
1717
+ }
1718
+ while (end >= start && predicate(array[end])) {
1719
+ end--;
1720
+ }
1721
+ return array.slice(start, end + 1);
1722
+ }
1723
+ function pairwise(array) {
1724
+ if (!Array.isArray(array) || array.length < 2) {
1725
+ return [];
1726
+ }
1727
+ const result = [];
1728
+ for (let i = 0; i < array.length - 1; i++) {
1729
+ result.push([array[i], array[i + 1]]);
1730
+ }
1731
+ return result;
1732
+ }
1733
+ function enumerate(array) {
1734
+ if (!Array.isArray(array)) {
1735
+ return [];
1736
+ }
1737
+ return array.map((value, index) => [index, value]);
1738
+ }
1739
+ function applyByIndex(array, functions) {
1740
+ if (!Array.isArray(array)) {
1741
+ return [];
1742
+ }
1743
+ return array.map((item, index) => {
1744
+ const fn = functions[index % functions.length];
1745
+ return fn(item);
1746
+ });
1747
+ }
1748
+ function rotateLeft(array, n = 1) {
1749
+ if (!Array.isArray(array) || array.length === 0) {
1750
+ return [];
1751
+ }
1752
+ const len = array.length;
1753
+ const rotations = (n % len + len) % len;
1754
+ return [...array.slice(rotations), ...array.slice(0, rotations)];
1755
+ }
1756
+ function rotateRight(array, n = 1) {
1757
+ return rotateLeft(array, -n);
1758
+ }
1759
+ function swap(array, i, j) {
1760
+ if (!Array.isArray(array) || i < 0 || j < 0 || i >= array.length || j >= array.length) {
1761
+ return [...array];
1762
+ }
1763
+ const result = [...array];
1764
+ [result[i], result[j]] = [result[j], result[i]];
1765
+ return result;
1766
+ }
1767
+ function reverseSegment(array, start, end) {
1768
+ if (!Array.isArray(array) || start < 0 || end >= array.length || start >= end) {
1769
+ return [...array];
1770
+ }
1771
+ const result = [...array];
1772
+ const segment2 = result.slice(start, end + 1).reverse();
1773
+ result.splice(start, end - start + 1, ...segment2);
1774
+ return result;
1775
+ }
1776
+ function isSorted(array, compareFn) {
1777
+ if (!Array.isArray(array) || array.length <= 1) {
1778
+ return true;
1779
+ }
1780
+ const compare = compareFn || ((a, b) => a < b ? -1 : a > b ? 1 : 0);
1781
+ for (let i = 1; i < array.length; i++) {
1782
+ if (compare(array[i - 1], array[i]) > 0) {
1783
+ return false;
1784
+ }
1785
+ }
1786
+ return true;
1787
+ }
1788
+ function hasDuplicates(array) {
1789
+ if (!Array.isArray(array)) {
1790
+ return false;
1791
+ }
1792
+ return new Set(array).size !== array.length;
1793
+ }
1794
+ function pickMany(array, keys) {
1795
+ if (!Array.isArray(array)) {
1796
+ return [];
1797
+ }
1798
+ return array.map((obj) => {
1799
+ const result = {};
1800
+ for (const key of keys) {
1801
+ if (key in obj) {
1802
+ result[key] = obj[key];
1803
+ }
1804
+ }
1805
+ return result;
1806
+ });
1807
+ }
1808
+ function toObject(array, keySelector, valueSelector) {
1809
+ if (!Array.isArray(array)) {
1810
+ return {};
1811
+ }
1812
+ const result = {};
1813
+ for (let i = 0; i < array.length; i++) {
1814
+ const key = keySelector(array[i], i);
1815
+ const value = valueSelector ? valueSelector(array[i], i) : array[i];
1816
+ result[key] = value;
1817
+ }
1818
+ return result;
1819
+ }
1820
+ async function mapAsync(array, fn) {
1821
+ if (!Array.isArray(array)) {
1822
+ return [];
1823
+ }
1824
+ const result = [];
1825
+ for (let i = 0; i < array.length; i++) {
1826
+ result.push(await fn(array[i], i));
1827
+ }
1828
+ return result;
1829
+ }
1830
+ async function mapAsyncParallel(array, fn) {
1831
+ if (!Array.isArray(array)) {
1832
+ return [];
1833
+ }
1834
+ return Promise.all(array.map((item, index) => fn(item, index)));
1835
+ }
1836
+ async function filterAsync(array, predicate) {
1837
+ if (!Array.isArray(array)) {
1838
+ return [];
1839
+ }
1840
+ const result = [];
1841
+ for (let i = 0; i < array.length; i++) {
1842
+ if (await predicate(array[i], i)) {
1843
+ result.push(array[i]);
1844
+ }
1845
+ }
1846
+ return result;
1847
+ }
1848
+ async function reduceAsync(array, fn, initial) {
1849
+ if (!Array.isArray(array)) {
1850
+ return initial;
1851
+ }
1852
+ let accumulator = initial;
1853
+ for (let i = 0; i < array.length; i++) {
1854
+ accumulator = await fn(accumulator, array[i], i);
1855
+ }
1856
+ return accumulator;
1857
+ }
1858
+ async function findAsync(array, predicate) {
1859
+ if (!Array.isArray(array)) {
1860
+ return void 0;
1861
+ }
1862
+ for (let i = 0; i < array.length; i++) {
1863
+ if (await predicate(array[i], i)) {
1864
+ return array[i];
1865
+ }
1866
+ }
1867
+ return void 0;
1868
+ }
1869
+ async function someAsync(array, predicate) {
1870
+ if (!Array.isArray(array)) {
1871
+ return false;
1872
+ }
1873
+ for (let i = 0; i < array.length; i++) {
1874
+ if (await predicate(array[i], i)) {
1875
+ return true;
1876
+ }
1877
+ }
1878
+ return false;
1879
+ }
1880
+ async function everyAsync(array, predicate) {
1881
+ if (!Array.isArray(array)) {
1882
+ return true;
1883
+ }
1884
+ for (let i = 0; i < array.length; i++) {
1885
+ if (!await predicate(array[i], i)) {
1886
+ return false;
1887
+ }
1888
+ }
1889
+ return true;
1890
+ }
1891
+ function weightedAverage(array, valueSelector, weightSelector) {
1892
+ if (!Array.isArray(array) || array.length === 0) {
1893
+ return 0;
1894
+ }
1895
+ let totalWeight = 0;
1896
+ let weightedSum = 0;
1897
+ for (const item of array) {
1898
+ const value = typeof valueSelector === "function" ? valueSelector(item) : get(item, valueSelector);
1899
+ const weight = typeof weightSelector === "function" ? weightSelector(item) : get(item, weightSelector);
1900
+ if (typeof value === "number" && typeof weight === "number") {
1901
+ weightedSum += value * weight;
1902
+ totalWeight += weight;
1903
+ }
1904
+ }
1905
+ return totalWeight === 0 ? 0 : weightedSum / totalWeight;
1906
+ }
1907
+ function weightedSample(array, weightSelector, count = 1) {
1908
+ if (!Array.isArray(array) || array.length === 0 || count < 1) {
1909
+ return [];
1910
+ }
1911
+ const weights = [];
1912
+ let totalWeight = 0;
1913
+ for (const item of array) {
1914
+ const weight = typeof weightSelector === "function" ? weightSelector(item) : get(item, weightSelector);
1915
+ totalWeight += typeof weight === "number" && weight > 0 ? weight : 0;
1916
+ weights.push(totalWeight);
1917
+ }
1918
+ if (totalWeight === 0) {
1919
+ return [];
1920
+ }
1921
+ const result = [];
1922
+ for (let i = 0; i < count; i++) {
1923
+ const random = Math.random() * totalWeight;
1924
+ const index = weights.findIndex((w) => random < w);
1925
+ if (index !== -1) {
1926
+ result.push(array[index]);
1927
+ }
1928
+ }
1929
+ return result;
1930
+ }
1931
+ function segment(array, sizes) {
1932
+ if (!Array.isArray(array) || !Array.isArray(sizes)) {
1933
+ return [];
1934
+ }
1935
+ const result = [];
1936
+ let offset = 0;
1937
+ for (const size of sizes) {
1938
+ if (offset >= array.length) break;
1939
+ result.push(array.slice(offset, offset + size));
1940
+ offset += size;
1941
+ }
1942
+ return result;
1943
+ }
1944
+ function selectByCount(array, count) {
1945
+ if (!Array.isArray(array) || count < 1) {
1946
+ return [];
1947
+ }
1948
+ const freq = frequencies(array);
1949
+ const result = [];
1950
+ for (const item of array) {
1951
+ if (freq.get(item) === count) {
1952
+ result.push(item);
1953
+ }
1954
+ }
1955
+ return result;
1956
+ }
1957
+ function filterConsecutive(array, n, predicate) {
1958
+ if (!Array.isArray(array) || n < 1) {
1959
+ return [];
1960
+ }
1961
+ const result = [];
1962
+ let consecutiveCount = 0;
1963
+ const buffer = [];
1964
+ for (const item of array) {
1965
+ if (predicate(item)) {
1966
+ consecutiveCount++;
1967
+ buffer.push(item);
1968
+ if (consecutiveCount >= n) {
1969
+ result.push(...buffer.splice(0, buffer.length - n + 1));
1970
+ }
1971
+ } else {
1972
+ consecutiveCount = 0;
1973
+ buffer.length = 0;
1974
+ }
1975
+ }
1976
+ if (consecutiveCount >= n) {
1977
+ result.push(...buffer);
1978
+ }
1979
+ return result;
1980
+ }
1981
+ function mapWithContext(array, fn, initialContext) {
1982
+ if (!Array.isArray(array)) {
1983
+ return [];
1984
+ }
1985
+ const result = [];
1986
+ let context = initialContext;
1987
+ for (let i = 0; i < array.length; i++) {
1988
+ const { value, newContext } = fn(array[i], context, i);
1989
+ result.push(value);
1990
+ context = newContext;
1991
+ }
1992
+ return result;
1993
+ }
1994
+ function batch(array, batchSize) {
1995
+ return chunk(array, batchSize);
1996
+ }
1997
+ function zipWith(array1, array2, fn) {
1998
+ if (!Array.isArray(array1) || !Array.isArray(array2)) {
1999
+ return [];
2000
+ }
2001
+ const length = Math.min(array1.length, array2.length);
2002
+ const result = [];
2003
+ for (let i = 0; i < length; i++) {
2004
+ result.push(fn(array1[i], array2[i]));
2005
+ }
2006
+ return result;
2007
+ }
2008
+ function mergeArraysByKey(arrays, key, mergeStrategy = "last") {
2009
+ if (!Array.isArray(arrays) || arrays.length === 0) {
2010
+ return [];
2011
+ }
2012
+ const map = /* @__PURE__ */ new Map();
2013
+ for (const array of arrays) {
2014
+ if (!Array.isArray(array)) continue;
2015
+ for (const item of array) {
2016
+ const keyValue = get(item, key);
2017
+ if (mergeStrategy === "first") {
2018
+ if (!map.has(keyValue)) {
2019
+ map.set(keyValue, item);
2020
+ }
2021
+ } else if (mergeStrategy === "last") {
2022
+ map.set(keyValue, item);
2023
+ } else if (mergeStrategy === "concat") {
2024
+ const existing = map.get(keyValue);
2025
+ if (Array.isArray(existing)) {
2026
+ existing.push(item);
2027
+ } else if (existing) {
2028
+ map.set(keyValue, [existing, item]);
2029
+ } else {
2030
+ map.set(keyValue, item);
2031
+ }
2032
+ } else if (typeof mergeStrategy === "function") {
2033
+ const existing = map.get(keyValue);
2034
+ if (existing && !Array.isArray(existing)) {
2035
+ map.set(keyValue, mergeStrategy(existing, item));
2036
+ } else {
2037
+ map.set(keyValue, item);
2038
+ }
2039
+ }
2040
+ }
2041
+ }
2042
+ const result = [];
2043
+ for (const value of map.values()) {
2044
+ if (Array.isArray(value) && mergeStrategy === "concat") {
2045
+ result.push(...value);
2046
+ } else if (!Array.isArray(value)) {
2047
+ result.push(value);
2048
+ }
2049
+ }
2050
+ return result;
2051
+ }
2052
+ function indexBy(array, key) {
2053
+ return toObject(array, (item) => String(get(item, key)));
2054
+ }
2055
+ function binarySearch(array, target, compareFn) {
2056
+ if (!Array.isArray(array) || array.length === 0) {
2057
+ return -1;
2058
+ }
2059
+ const compare = compareFn || ((a, b) => a < b ? -1 : a > b ? 1 : 0);
2060
+ let left = 0;
2061
+ let right = array.length - 1;
2062
+ while (left <= right) {
2063
+ const mid = Math.floor((left + right) / 2);
2064
+ const comparison = compare(array[mid], target);
2065
+ if (comparison === 0) {
2066
+ return mid;
2067
+ } else if (comparison < 0) {
2068
+ left = mid + 1;
2069
+ } else {
2070
+ right = mid - 1;
2071
+ }
2072
+ }
2073
+ return -1;
2074
+ }
2075
+ function insertSorted(array, value, compareFn) {
2076
+ if (!Array.isArray(array)) {
2077
+ return [value];
2078
+ }
2079
+ const compare = compareFn || ((a, b) => a < b ? -1 : a > b ? 1 : 0);
2080
+ const result = [...array];
2081
+ let insertIndex = 0;
2082
+ while (insertIndex < result.length && compare(result[insertIndex], value) < 0) {
2083
+ insertIndex++;
2084
+ }
2085
+ result.splice(insertIndex, 0, value);
2086
+ return result;
2087
+ }
2088
+ export {
2089
+ applyByIndex,
2090
+ avgBy,
2091
+ batch,
2092
+ batchProcess,
2093
+ batchProcessParallel,
2094
+ bifurcate,
2095
+ binarySearch,
2096
+ cartesian,
2097
+ chunk,
2098
+ chunkBy,
2099
+ compact,
2100
+ countBy,
2101
+ cumulativeSum,
2102
+ dedupeConsecutive,
2103
+ deepCloneArray,
2104
+ diff,
2105
+ difference,
2106
+ differenceWith,
2107
+ drop,
2108
+ dropWhile,
2109
+ ensureArray,
2110
+ enumerate,
2111
+ everyAsync,
2112
+ fill,
2113
+ filterAsync,
2114
+ filterCompact,
2115
+ filterConsecutive,
2116
+ findAllIndices,
2117
+ findAsync,
2118
+ findIndex,
2119
+ findLastIndex,
2120
+ flatMap,
2121
+ flatten,
2122
+ flattenDeep,
2123
+ frequencies,
2124
+ generate,
2125
+ groupBy,
2126
+ groupConsecutive,
2127
+ hasDuplicates,
2128
+ hasSameElements,
2129
+ indexBy,
2130
+ insert,
2131
+ insertSorted,
2132
+ interleave,
2133
+ intersection,
2134
+ isArrayEqual,
2135
+ isEqual,
2136
+ isSorted,
2137
+ isSubset,
2138
+ isSuperset,
2139
+ keyBy,
2140
+ leastCommon,
2141
+ mapAsync,
2142
+ mapAsyncParallel,
2143
+ mapWithContext,
2144
+ maxBy,
2145
+ median,
2146
+ mergeArraysByKey,
2147
+ mergeByKey,
2148
+ minBy,
2149
+ mode,
2150
+ mostCommon,
2151
+ move,
2152
+ normalize,
2153
+ omit,
2154
+ pad,
2155
+ pairwise,
2156
+ partition,
2157
+ percentile,
2158
+ pick,
2159
+ pickMany,
2160
+ pluck,
2161
+ quartiles,
2162
+ range,
2163
+ rank,
2164
+ reduceAsync,
2165
+ reduceRight,
2166
+ remove,
2167
+ repeat,
2168
+ replace,
2169
+ reverseSegment,
2170
+ rotate,
2171
+ rotateLeft,
2172
+ rotateRight,
2173
+ sample,
2174
+ sampleSize,
2175
+ scan,
2176
+ segment,
2177
+ selectByCount,
2178
+ shuffle,
2179
+ slidingWindow,
2180
+ someAsync,
2181
+ sortBy,
2182
+ splitDuplicates,
2183
+ standardDeviation,
2184
+ standardize,
2185
+ sumBy,
2186
+ swap,
2187
+ take,
2188
+ takeLast,
2189
+ takeWhile,
2190
+ toObject,
2191
+ transpose,
2192
+ trim,
2193
+ union,
2194
+ unique,
2195
+ unzip,
2196
+ updateBy,
2197
+ variance,
2198
+ weightedAverage,
2199
+ weightedSample,
2200
+ without,
2201
+ wrap,
2202
+ zip,
2203
+ zipWith
2204
+ };