@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.
- package/dist/index.cjs +2858 -1
- package/dist/index.mjs +2838 -1
- package/dist/lib/array/advanced.cjs +2227 -1
- package/dist/lib/array/advanced.mjs +2204 -1
- package/dist/lib/array/array.cjs +57 -1
- package/dist/lib/array/array.mjs +36 -1
- package/dist/lib/array/index.cjs +2344 -1
- package/dist/lib/array/index.mjs +2322 -1
- package/dist/lib/array/utils.cjs +103 -1
- package/dist/lib/array/utils.mjs +82 -1
- package/dist/lib/color/color.cjs +2190 -1
- package/dist/lib/color/color.mjs +2167 -1
- package/dist/lib/color/constants.cjs +380 -1
- package/dist/lib/color/constants.mjs +359 -1
- package/dist/lib/color/conversions.cjs +629 -1
- package/dist/lib/color/conversions.mjs +608 -1
- package/dist/lib/color/helpers.cjs +2534 -1
- package/dist/lib/color/helpers.mjs +2511 -1
- package/dist/lib/color/index.cjs +2641 -1
- package/dist/lib/color/index.mjs +2619 -1
- package/dist/lib/color/types.cjs +18 -1
- package/dist/lib/color/utils.cjs +962 -1
- package/dist/lib/color/utils.mjs +939 -1
- package/dist/lib/compare/comparators.cjs +171 -1
- package/dist/lib/compare/comparators.mjs +150 -1
- package/dist/lib/compare/index.cjs +172 -1
- package/dist/lib/compare/index.mjs +152 -1
- package/dist/lib/crypto/hash.cjs +83 -1
- package/dist/lib/crypto/hash.mjs +62 -1
- package/dist/lib/crypto/index.cjs +85 -1
- package/dist/lib/crypto/index.mjs +62 -1
- package/dist/lib/dom/events.cjs +40 -1
- package/dist/lib/dom/events.mjs +19 -1
- package/dist/lib/dom/index.cjs +78 -1
- package/dist/lib/dom/index.mjs +56 -1
- package/dist/lib/dom/utils.cjs +57 -1
- package/dist/lib/dom/utils.mjs +36 -1
- package/dist/lib/functions/functions.cjs +366 -1
- package/dist/lib/functions/functions.mjs +345 -1
- package/dist/lib/functions/index.cjs +369 -1
- package/dist/lib/functions/index.mjs +347 -1
- package/dist/lib/functions/types.cjs +18 -1
- package/dist/lib/helpers.cjs +78 -1
- package/dist/lib/helpers.mjs +59 -1
- package/dist/lib/index.cjs +2857 -1
- package/dist/lib/index.mjs +2836 -1
- package/dist/lib/maths/constants.cjs +70 -1
- package/dist/lib/maths/constants.mjs +50 -1
- package/dist/lib/maths/fn/advanced.cjs +231 -1
- package/dist/lib/maths/fn/advanced.mjs +208 -1
- package/dist/lib/maths/fn/basic.cjs +212 -1
- package/dist/lib/maths/fn/basic.mjs +191 -1
- package/dist/lib/maths/fn/complex.cjs +268 -1
- package/dist/lib/maths/fn/complex.mjs +247 -1
- package/dist/lib/maths/fn/index.cjs +877 -1
- package/dist/lib/maths/fn/index.mjs +855 -1
- package/dist/lib/maths/fn/trigo.cjs +179 -1
- package/dist/lib/maths/fn/trigo.mjs +156 -1
- package/dist/lib/maths/fn/vector.cjs +728 -1
- package/dist/lib/maths/fn/vector.mjs +707 -1
- package/dist/lib/maths/formatter.cjs +61 -1
- package/dist/lib/maths/formatter.mjs +40 -1
- package/dist/lib/maths/guards.cjs +164 -1
- package/dist/lib/maths/guards.mjs +144 -1
- package/dist/lib/maths/index.cjs +1152 -1
- package/dist/lib/maths/index.mjs +1130 -1
- package/dist/lib/maths/parser.cjs +75 -1
- package/dist/lib/maths/parser.mjs +54 -1
- package/dist/lib/maths/random.cjs +49 -1
- package/dist/lib/maths/random.mjs +28 -1
- package/dist/lib/maths/types/advanced.cjs +18 -1
- package/dist/lib/maths/types/basic.cjs +18 -1
- package/dist/lib/maths/types/index.cjs +19 -1
- package/dist/lib/maths/types/index.mjs +1 -0
- package/dist/lib/maths/types/negative.cjs +18 -1
- package/dist/lib/maths/types/operations.cjs +18 -1
- package/dist/lib/object/clone.cjs +88 -1
- package/dist/lib/object/clone.mjs +65 -1
- package/dist/lib/object/diff.cjs +573 -1
- package/dist/lib/object/diff.mjs +550 -1
- package/dist/lib/object/getter-setter.cjs +2351 -1
- package/dist/lib/object/getter-setter.mjs +2330 -1
- package/dist/lib/object/index.cjs +3956 -6
- package/dist/lib/object/index.mjs +3936 -6
- package/dist/lib/object/merge.cjs +1029 -1
- package/dist/lib/object/merge.mjs +1006 -1
- package/dist/lib/object/object.cjs +280 -1
- package/dist/lib/object/object.mjs +257 -1
- package/dist/lib/object/omit.cjs +2022 -1
- package/dist/lib/object/omit.mjs +1999 -1
- package/dist/lib/object/reconcile.cjs +126 -1
- package/dist/lib/object/reconcile.mjs +105 -1
- package/dist/lib/object/selector.cjs +303 -1
- package/dist/lib/object/selector.mjs +282 -1
- package/dist/lib/object/sort.cjs +209 -1
- package/dist/lib/object/sort.mjs +186 -1
- package/dist/lib/object/transform.cjs +2211 -1
- package/dist/lib/object/transform.mjs +2190 -1
- package/dist/lib/object/types.cjs +18 -1
- package/dist/lib/object/utils.cjs +326 -6
- package/dist/lib/object/utils.mjs +305 -6
- package/dist/lib/primitive/boolean/boolean.cjs +407 -1
- package/dist/lib/primitive/boolean/boolean.mjs +386 -1
- package/dist/lib/primitive/boolean/index.cjs +382 -1
- package/dist/lib/primitive/boolean/index.mjs +359 -1
- package/dist/lib/primitive/boolean/types.cjs +18 -1
- package/dist/lib/primitive/date/date.cjs +1126 -1
- package/dist/lib/primitive/date/date.mjs +1105 -1
- package/dist/lib/primitive/date/index.cjs +1128 -1
- package/dist/lib/primitive/date/index.mjs +1105 -1
- package/dist/lib/primitive/date/types.cjs +18 -1
- package/dist/lib/primitive/index.cjs +2338 -5
- package/dist/lib/primitive/index.mjs +2316 -5
- package/dist/lib/primitive/string/index.cjs +875 -5
- package/dist/lib/primitive/string/index.mjs +852 -5
- package/dist/lib/primitive/string/parser-2.cjs +543 -8
- package/dist/lib/primitive/string/parser-2.mjs +522 -8
- package/dist/lib/primitive/string/parser.cjs +236 -3
- package/dist/lib/primitive/string/parser.mjs +215 -3
- package/dist/lib/primitive/string/string.cjs +926 -5
- package/dist/lib/primitive/string/string.mjs +903 -5
- package/dist/lib/primitive/string/types.cjs +18 -1
- package/dist/lib/primitive/types.cjs +18 -1
- package/dist/lib/url/index.cjs +327 -1
- package/dist/lib/url/index.mjs +304 -1
- package/dist/lib/url/parser.cjs +325 -1
- package/dist/lib/url/parser.mjs +304 -1
- package/dist/lib/url/types.cjs +18 -1
- package/package.json +5 -5
package/dist/lib/index.cjs
CHANGED
|
@@ -1 +1,2857 @@
|
|
|
1
|
-
"use strict";var V=Object.defineProperty;var le=Object.getOwnPropertyDescriptor;var ce=Object.getOwnPropertyNames;var ye=Object.prototype.hasOwnProperty;var pe=(e,n)=>{for(var t in n)V(e,t,{get:n[t],enumerable:!0})},de=(e,n,t,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of ce(n))!ye.call(e,i)&&i!==t&&V(e,i,{get:()=>n[i],enumerable:!(r=le(n,i))||r.enumerable});return e};var Te=e=>de(V({},"__esModule",{value:!0}),e);var vr={};pe(vr,{aenu:()=>Ht,after:()=>Ar,applyByIndex:()=>pt,ary:()=>cr,at:()=>Me,avgBy:()=>Un,batch:()=>Et,batchProcess:()=>Nn,batchProcessParallel:()=>Bn,before:()=>gr,bifurcate:()=>_n,binarySearch:()=>Ct,bind:()=>fr,btoa:()=>Dt,cartesian:()=>Rn,chunk:()=>I,chunkBy:()=>Fn,compact:()=>on,compareWithHash:()=>Qt,compose:()=>se,countBy:()=>_e,createHash:()=>Jt,cumulativeSum:()=>at,curry:()=>ir,debounce:()=>ie,dedupeConsecutive:()=>nt,deepCloneArray:()=>hn,defer:()=>pr,delay:()=>dr,diff:()=>ut,difference:()=>Ze,differenceWith:()=>Yn,drop:()=>rn,dropWhile:()=>sn,ensureArray:()=>Q,enumerate:()=>yt,everyAsync:()=>Ot,fill:()=>xn,filterAsync:()=>St,filterCompact:()=>Pn,filterConsecutive:()=>Ft,findAllIndices:()=>In,findAsync:()=>wt,findIndex:()=>cn,findLastIndex:()=>yn,first:()=>Fe,flatMap:()=>gn,flatten:()=>ze,flattenArray:()=>Ve,flattenDeep:()=>_,flip:()=>lr,flow:()=>xr,flowRight:()=>hr,frequencies:()=>P,generate:()=>Jn,generateID:()=>Le,generateUUID:()=>Be,getKind:()=>Ne,groupArrayBy:()=>Ee,groupBy:()=>He,groupConsecutive:()=>et,hasDuplicates:()=>mt,hasSameElements:()=>Dn,hash:()=>C,hashStringPromise:()=>Zt,indexBy:()=>$t,insert:()=>wn,insertSorted:()=>Ut,interleave:()=>Hn,intersection:()=>Ge,isAddRemoveListenerTarget:()=>Lt,isArray:()=>Se,isArrayEqual:()=>qn,isArrayLike:()=>Ke,isArrayOfBoolean:()=>xe,isArrayOfNumber:()=>me,isArrayOfObject:()=>he,isArrayOfString:()=>Ae,isAsyncFunction:()=>Yt,isDOMEventTarget:()=>Wt,isDefined:()=>We,isDoubleArray:()=>we,isEmptyArray:()=>Oe,isEqual:()=>kn,isFunction:()=>re,isIterable:()=>B,isNodeEventEmitter:()=>Nt,isNonEmptyArray:()=>Pe,isNull:()=>$e,isObjectArray:()=>be,isOnOffTarget:()=>Bt,isPrimitive:()=>D,isPromise:()=>Xt,isReadonlyArray:()=>Ie,isSorted:()=>At,isStaticArray:()=>ve,isSubset:()=>X,isSuperset:()=>zn,isTypedArray:()=>Re,isUndefined:()=>Ce,isUndefinedOrNull:()=>Ue,keyBy:()=>Je,last:()=>ke,leastCommon:()=>Wn,mapAsync:()=>ht,mapAsyncParallel:()=>bt,mapWithContext:()=>jt,maxBy:()=>Cn,median:()=>Zn,memoize:()=>er,memoizeWithTTL:()=>Tr,mergeArraysByKey:()=>Mt,mergeByKey:()=>bn,minBy:()=>$n,mode:()=>Gn,mostCommon:()=>G,move:()=>Sn,negate:()=>sr,normalize:()=>st,omit:()=>Tn,once:()=>tr,overArgs:()=>or,pad:()=>ft,pairwise:()=>ct,partial:()=>ar,partialRight:()=>ur,partition:()=>Ye,percentile:()=>E,pick:()=>dn,pickMany:()=>xt,pipe:()=>oe,pluck:()=>pn,quartiles:()=>rt,range:()=>mn,rank:()=>tt,rearg:()=>rr,reduceAsync:()=>vt,reduceRight:()=>An,remove:()=>Kn,repeat:()=>Qn,replace:()=>On,retry:()=>br,reverseSegment:()=>gt,rotate:()=>vn,rotateLeft:()=>ee,rotateRight:()=>dt,sample:()=>fn,sampleSize:()=>ln,scan:()=>Y,segment:()=>It,selectByCount:()=>kt,shuffle:()=>J,slidingWindow:()=>Mn,someAsync:()=>Kt,sortBy:()=>Qe,splitDuplicates:()=>En,standardDeviation:()=>$,standardize:()=>ot,string_hash:()=>Gt,sumBy:()=>Z,swap:()=>Tt,take:()=>en,takeLast:()=>nn,takeWhile:()=>tn,throttle:()=>nr,toArray:()=>je,toArrayString:()=>ge,toObject:()=>ne,transpose:()=>Ln,trim:()=>lt,tryCatch:()=>mr,uena:()=>zt,unary:()=>yr,union:()=>Xe,unique:()=>j,unzip:()=>un,updateBy:()=>jn,updateQueryStringParameter:()=>_t,variance:()=>it,weightedAverage:()=>Pt,weightedSample:()=>Rt,windowObject:()=>qt,withTimeout:()=>Sr,without:()=>Xn,wrap:()=>Vn,zip:()=>an,zipWith:()=>Vt});module.exports=Te(vr);var ge=e=>{if(Array.isArray(e))return e;if(typeof e=="string")if(e.startsWith("[")&&e.endsWith("]"))try{return JSON.parse(e)}catch{return[]}else return[e];return[]};function Ae(e){return Array.isArray(e)&&e.every(n=>typeof n=="string")}function me(e){return Array.isArray(e)&&e.every(n=>typeof n=="number")}function xe(e){return Array.isArray(e)&&e.every(n=>typeof n=="boolean")}function he(e){return Array.isArray(e)&&e.every(n=>typeof n=="object")}var N=require("@fluixi/utils/object"),be=e=>Array.isArray(e)&&e.every(n=>(0,N.isObject)(n));function Se(e){return Array.isArray(e)}function ve(e){return Array.isArray(e)}function we(e){return Array.isArray(e)&&e.every(n=>Array.isArray(n)&&n.length===2)}function B(e){return e!=null&&typeof e[Symbol.iterator]=="function"}function Ke(e){return e!=null&&typeof e=="object"&&"length"in e&&typeof e.length=="number"&&e.length>=0&&(e.length===0||e.length-1 in e)}function Oe(e){return Array.isArray(e)&&e.length===0}function Pe(e){return Array.isArray(e)&&e.length>0}function Re(e){return ArrayBuffer.isView(e)&&!(e instanceof DataView)}function Ie(e){return Array.isArray(e)}function ke(e){return e.length>0?e[e.length-1]:void 0}function Fe(e){return e.length>0?e[0]:void 0}function je(e){return Array.isArray(e)?[...e]:B(e)?[...e]:Array.from(e)}function Ee(e,n){return e.reduce((t,r)=>{let i=n(r);return t[i]||(t[i]=[]),t[i].push(r),t},{})}function Ve(e){return e.flat()}function Me(e,n){let t=n<0?e.length+n:n;return e[t]}var m=e=>e==null||Array.isArray(e)||typeof e=="function"||e instanceof Date||e instanceof RegExp||e instanceof Map||e instanceof Set||e instanceof Error?!1:typeof e=="object";var S=(e,n,t,r)=>{if(t>r)return;if(n.length===0)return e;let i=n[0],s=n.slice(1);if(i.type==="descendant"){let a=S(e,s,t+1,r);if(a!==void 0)return a;if(e&&typeof e=="object")if(Array.isArray(e)){let o=[];for(let u=0;u<e.length;u++){let f=S(e[u],n,t+1,r);f!==void 0&&(o[u]=f)}return o.length>0?o:void 0}else{let o={};for(let u in e)if(e.hasOwnProperty(u)){let f=S(e[u],n,t+1,r);f!==void 0&&(o[u]=f)}return Object.keys(o).length>0?o:void 0}return}switch(i.type){case"property":if(m(e)&&i.value&&String(i.value)in e){let a=e[String(i.value)],o=S(a,s,t+1,r);if(o!==void 0)return{[String(i.value)]:o}}break;case"index":if(Array.isArray(e)){let a=i.value;if(a>=0&&a<e.length){let o=S(e[a],s,t+1,r);if(o!==void 0){let u=new Array(e.length).filter(f=>f!==void 0);return u[a]=o,u}}}else if(e&&typeof e=="object"){let a=String(i.value);if(a in e){let o=S(e[a],s,t+1,r);if(o!==void 0)return{[a]:o}}}break;case"wildcard":if(e&&typeof e=="object")if(Array.isArray(e)){let a=[],o=!1;for(let u=0;u<e.length;u++){let f=S(e[u],s,t+1,r);f!==void 0&&(a[u]=f,o=!0)}return o?a:void 0}else{let a={},o=!1;for(let u in e)if(e.hasOwnProperty(u)){let f=S(e[u],s,t+1,r);f!==void 0&&(a[u]=f,o=!0)}return o?a:void 0}break;case"slice":if(Array.isArray(e)){let[a,o]=i.value,u=Math.max(0,a),f=Math.min(e.length,o===1/0?e.length:o),y=[],T=!1;for(let p=u;p<f;p++){let b=S(e[p],s,t+1,r);b!==void 0&&(y[p]=b,T=!0)}return T?y:void 0}break;case"union":if(Array.isArray(e)){let a=i.value,o=[],u=!1;for(let f of a)if(f>=0&&f<e.length){let y=S(e[f],s,t+1,r);y!==void 0&&(o[f]=y,u=!0)}return u?o:void 0}break;case"filter":if(Array.isArray(e)){let a=i.value,o=[],u=!1;for(let f=0;f<e.length;f++)if(a(e[f])){let y=S(e[f],s,t+1,r);y!==void 0&&(o[f]=y,u=!0)}return u?o:void 0}break}};var K=(e,n)=>{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 t=new Map;return e.forEach((r,i)=>{(!n||!n.some(s=>s.toString()===i.toString()))&&t.set(i,K(r))}),t}if(e instanceof Set){let t=new Set;return e.forEach(r=>{t.add(K(r))}),t}if(Array.isArray(e))return Array.from(e).map(t=>K(t));if(m(e)){let t={};for(let i in e)Object.prototype.hasOwnProperty.call(e,i)&&(!n||!n.some(s=>s.toString()===i.toString()))&&(t[i]=K(e[i]));let r=Object.getOwnPropertySymbols(e);for(let i of r)(!n||!n.some(s=>s.toString()===i.toString()))&&(t[i]=K(e[i]));return t}return e};var M=require("@fluixi/utils/primitive"),F=require("@fluixi/utils/object"),L=require("@fluixi/utils/array"),q=require("@fluixi/utils/functions");function $e(e){return e===null}function Ce(e){return e===void 0}var Ue=e=>typeof e>"u"||e===null;function D(e){let n=typeof e;return e===null||n==="string"||n==="number"||n==="boolean"||n==="symbol"||n==="bigint"||n==="undefined"||(0,M.isDate)(e)}function We(e){return e!=null}function Ne(e){return e===null?"null":e===void 0?"undefined":(0,M.isDate)(e)?"date":(0,F.isClass)(e)?"class":(0,q.isFunction)(e)?"function":(0,L.isArray)(e)?"array":D(e)?"primitive":(0,F.isObject)(e)?"object":"primitive"}var Be=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){let n=Math.random()*16|0;return(e==="x"?n:n&3|8).toString(16)}),Le=()=>"xxyxxxxxxy-4xx8".replace(/[xy]/g,function(e){let n=Math.random()*16|0;return(e==="x"?n:n&3|8).toString(16)});var R=(e,n={})=>{let{type:t="auto",throwOnError:r=!1}=n;if(!e||typeof e!="string")return[];let i=[],s="",a=!1,o=!1,u="",f="",y=0,p=t==="auto"?(l=>l.includes("..")?"descendant":l.includes("[?(")?"filter":l.includes("[:")||l.includes("[0:")?"slice":l.includes("[,")||l.includes("[0,1]")?"union":l.includes("[*]")||l.includes(".*.")?"wildcard":l.includes("[]")?"array-wildcard":l.includes("[")&&l.includes("]")?"bracket":"dot")(e):t,b=l=>{let c=l.trim();if(c==="*"||c==="")return{type:"wildcard",value:c===""?"[]":"*",raw:c===""?"[]":l};if(c==="[]")return{type:"wildcard",value:"[]",raw:l};if(/^-?\d+$/.test(c))return{type:"index",value:parseInt(c,10),raw:l};if(c.includes(":")){let g=c.split(":").map(O=>O.trim()),x=g[0]===""?0:parseInt(g[0],10),h=g[1]===""?1/0:parseInt(g[1],10);if(isNaN(x)||isNaN(h)){if(r)throw new Error(`Invalid slice notation: ${l}`);return{type:"wildcard",value:"*",raw:l}}return{type:"slice",value:[x,h],raw:l}}if(c.includes(",")){let g=c.split(",").map(x=>{let h=parseInt(x.trim(),10);return isNaN(h)?-1:h}).filter(x=>x>=0);if(g.length===0){if(r)throw new Error(`Invalid union notation: ${l}`);return{type:"wildcard",value:"*",raw:l}}return{type:"union",value:g,raw:l}}if(c.startsWith("?(")&&c.endsWith(")")){let g=c.slice(2,-1);try{return{type:"filter",value:qe(g),raw:l}}catch(x){if(r)throw x;return{type:"wildcard",value:"*",raw:l}}}return c.startsWith('"')&&c.endsWith('"')||c.startsWith("'")&&c.endsWith("'")?{type:"property",value:c.slice(1,-1),raw:l}:{type:"property",value:c,raw:l}};for(let l=0;l<e.length;l++){let c=e[l],g=e[l+1];if((c==='"'||c==="'")&&!o){o=!0,u=c;continue}else if(c===u&&o){o=!1,u="",c==='"'||c==="'"||(a?f+=c:s+=c);continue}if(o){a?f+=c:s+=c;continue}if(c==="["&&!a){s&&(i.push({type:"property",value:s,raw:s}),s=""),a=!0,f="";continue}if(c==="]"&&a&&!o){a=!1;let h=b(f);i.push(h);continue}let x=i.length>0?i[i.length-1]:null;if(c==="."&&!a&&!o){if(g==="."){let h=e.split("..")[0];i.push({type:"property",value:h,raw:h}),i.push({type:"descendant",value:"..",raw:".."}),l++}else s&&(s==="*"?i.push({type:"wildcard",value:s,raw:s}):i.push({type:"property",value:s,raw:s}),s="");continue}if(a)f+=c;else if(x&&x.type!=="descendant")s+=c;else{let h=e.split(x?.raw)[1];h!==void 0?s=h:s+=c}}return s&&i.push({type:"property",value:s,raw:s}),i.map(l=>{if(l.type==="property"&&typeof l.value=="string"&&/^-?\d+$/.test(l.value)){let c=parseInt(l.value,10);if(!isNaN(c))return{...l,type:"index",value:c}}return l})},qe=e=>{let n=e.replace(/@\.([a-zA-Z_$][\w$]*)/g,(t,r)=>`item.${r}`).replace(/@/g,"item");try{return new Function("item",`return ${n}`)}catch{throw new Error(`Invalid filter expression: ${e}`)}};var z=(e,n,t)=>{let r=R(n),i=e;for(let s=0;s<r.length;s++){let a=r[s],o=s===r.length-1;switch(a.type){case"property":if(o)i[String(a.value)]=t;else{if(!i[String(a.value)]){let f=r[s+1];i[String(a.value)]=f.type==="index"||f.type==="slice"||f.type==="union"||f.type==="wildcard"?[]:{}}i=i[String(a.value)]}break;case"index":Array.isArray(i)||(i=[]);let u=a.value;if(o){if(u>=i.length)for(let f=i.length;f<=u;f++)i.push(void 0);i[u]=t}else{if(!i[u]){let f=r[s+1];i[u]=f.type==="index"||f.type==="slice"||f.type==="union"||f.type==="wildcard"?[]:{}}i=i[u]}break;case"wildcard":if(Array.isArray(i))if(o)for(let f=0;f<i.length;f++)i[f]=t;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,n,t={}){let{preserveStructure:r,multiple:i,throwOnError:s=!1,defaultValue:a,maxDepth:o=20}=t;if(!e||typeof e!="object")return a;if(!n)return e;if(Array.isArray(n))if(r){let y={};for(let T of n){let p=d(e,T,{...t,preserveStructure:!1});p!==void 0&&z(y,T,p)}return y}else return n.map(y=>d(e,y,{...t,preserveStructure:!1}));let u=R(n,{...t,throwOnError:s});if(u.length===0)return e;if(typeof r>"u"||r===!1){let y=De(e,n);return i===!1&&Array.isArray(y)?y[0]:y===void 0&&a!==void 0?a:y}let f=S(e,u,0,o);return f===void 0&&a!==void 0?a:f}function De(e,n,t={}){let{createMissing:r=!1,add:i=!1,debug:s=!1}=t,a=R(n),o=e,u=!1,f="",y=n;if(typeof o=="object"&&!Array.isArray(o)&&y.length>0&&o[y])return o=o[y],o;for(let T=0;T<a.length;T++){let p=a[T],b=a.length>1?T===a.length-1:!1;if(o===null&&!r)return;let l=a[T+1];switch(p.type){case"property":if(o&&typeof o=="object")if(Array.isArray(o)){if(typeof p.value=="number"){let c=p.value;if(r&&c>=o.length)for(let g=o.length;g<=c;g++)o.push(void 0);if(r&&(o[c]===null||o[c]===void 0)&&(!b||u)&&(l?o[c]=l.type==="index"||l.type==="slice"||l.type==="union"||l.type==="wildcard"?[]:{}:o[c]=null,u=!1),o=o[c],l){u=!0;continue}}else i?o.push({[String(p.value)]:null}):o=o.map(c=>c[String(p.value)]);if(l)continue;return H(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||u)&&(l?o[String(p.value)]=l.type==="index"||l.type==="slice"||l.type==="union"||l.type==="wildcard"?[]:{}:o[String(p.value)]=null,u=!1,o=o[String(p.value)],l)){u=!0;continue}if(o?(!o[String(p.value)]&&r&&(o[String(p.value)]=null),o=o[String(p.value)]):o={[String(p.value)]:null},l)continue}else if(r)o={},o[String(p.value)]=l.type==="index"||l.type==="slice"||l.type==="union"||l.type==="wildcard"||t.type==="array"?[]:{},o=o[String(p.value)];else return;break;case"index":case"wildcard":if(Array.isArray(o)){if(p.type==="index"){let c=p.value;if(c<0){o=o[o.length-Math.abs(c)];continue}if(r&&(c>=o.length||o[c]==null||o[c]==null)&&!b){for(let g=o.length;g<=c;g++)o.push(void 0);l&&(o[c]=l.type==="index"||l.type==="slice"||l.type==="union"||l.type==="wildcard"?[]:{})}o=o[c]}else if(!b)continue}else if(r){let c=a[T+1];o=[];let g=p.value;for(let x=0;x<=g;x++)o.push(void 0);o[g]=c.type==="index"||c.type==="slice"||c.type==="union"||c.type==="wildcard"||t.type==="array"?[]:{},o=o[g]}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 H(o)}function H(e){return Array.isArray(e)?e.filter(n=>typeof n<"u"):e}function I(e,n){if(!Array.isArray(e)||n<1)return[];let t=[];for(let r=0;r<e.length;r+=n)t.push(e.slice(r,r+n));return t}function ze(e){return e.reduce((n,t)=>n.concat(t),[])}function _(e,n=1/0){return n<1?e.slice():e.reduce((t,r)=>(Array.isArray(r)?t.push(..._(r,n-1)):t.push(r),t),[])}function j(e,n){if(!Array.isArray(e))return[];if(!n)return[...new Set(e)];let t=new Set;return e.filter(r=>{let i=typeof n=="function"?n(r):m(r)?d(r,n):r;return t.has(i)?!1:(t.add(i),!0)})}function He(e,n){return Array.isArray(e)?e.reduce((t,r)=>{let i;return typeof n=="function"?i=String(n(r)):i=String(m(r)?d(r,n):r),t[i]||(t[i]=[]),t[i].push(r),t},{}):{}}function _e(e,n){return Array.isArray(e)?e.reduce((t,r)=>{let i;return typeof n=="function"?i=String(n(r)):n?i=String(m(r)?d(r,n):r):i=String(r),t[i]=(t[i]||0)+1,t},{}):{}}function Je(e,n,t){return Array.isArray(e)?e.reduce((r,i)=>{let s;typeof n=="function"?s=String(n(i)):s=String(m(i)?d(i,n):i);let a;return t?typeof t=="function"?a=t(i):a=d(i,t):a=i,r[s]=a,r},{}):{}}function Qe(e,n){if(!Array.isArray(e)||e.length===0)return[];let t=[...e],i=(Array.isArray(n)?n:[n]).map(s=>typeof s=="object"&&"key"in s?{key:s.key,dir:s.dir||"asc"}:{key:s,dir:"asc"});return t.sort((s,a)=>{for(let{key:o,dir:u}of i){let f=m(s)?d(s,o):s,y=m(a)?d(a,o):a;if(f===y)continue;let T=f<y?-1:1;return u==="asc"?T:-T}return 0}),t}function Ze(e,n,t){if(!Array.isArray(e))return[];if(!Array.isArray(n))return e;if(!t){let i=new Set(n);return e.filter(s=>!i.has(s))}let r=new Set(n.map(i=>m(i)?d(i,t):i));return e.filter(i=>{let s=m(i)?d(i,t):i;return!r.has(s)})}function Ge(e,n,t){if(!Array.isArray(e)||!Array.isArray(n))return[];if(!t){let i=new Set(n);return e.filter(s=>i.has(s))}let r=new Set(n.map(i=>m(i)?d(i,t):i));return e.filter(i=>{let s=m(i)?d(i,t):i;return r.has(s)})}function Xe(e,n,t){return!Array.isArray(e)&&!Array.isArray(n)?[]:Array.isArray(e)?Array.isArray(n)?j([...e,...n],t):j(e,t):j(n,t)}function Ye(e,n){return Array.isArray(e)?e.reduce((t,r,i)=>(t[n(r,i)?0:1].push(r),t),[[],[]]):[[],[]]}function en(e,n){return!Array.isArray(e)||n<=0?[]:e.slice(0,n)}function nn(e,n){return!Array.isArray(e)||n<=0?[]:e.slice(-n)}function tn(e,n){if(!Array.isArray(e))return[];let t=[];for(let r=0;r<e.length&&n(e[r],r);r++)t.push(e[r]);return t}function rn(e,n){return!Array.isArray(e)||n<=0?e?[...e]:[]:e.slice(n)}function sn(e,n){if(!Array.isArray(e))return[];let t=0;for(;t<e.length&&n(e[t],t);)t++;return e.slice(t)}function on(e){return Array.isArray(e)?e.filter(Boolean):[]}function an(...e){if(e.length===0)return[];let n=Math.max(...e.map(r=>Array.isArray(r)?r.length:0)),t=[];for(let r=0;r<n;r++){let i=[];for(let s of e)i.push(Array.isArray(s)?s[r]:void 0);t.push(i)}return t}function un(e){if(!Array.isArray(e)||e.length===0)return[];let n=Math.max(...e.map(r=>Array.isArray(r)?r.length:0)),t=[];for(let r=0;r<n;r++){let i=[];for(let s of e)Array.isArray(s)&&i.push(s[r]);t.push(i)}return t}function J(e){if(!Array.isArray(e))return[];let n=[...e];for(let t=n.length-1;t>0;t--){let r=Math.floor(Math.random()*(t+1));[n[t],n[r]]=[n[r],n[t]]}return n}function fn(e){if(!(!Array.isArray(e)||e.length===0))return e[Math.floor(Math.random()*e.length)]}function ln(e,n){return!Array.isArray(e)||n<=0?[]:J(e).slice(0,Math.min(n,e.length))}function cn(e,n,t=0){if(!Array.isArray(e))return-1;for(let r=t;r<e.length;r++)if(n(e[r],r))return r;return-1}function yn(e,n,t){if(!Array.isArray(e))return-1;let r=t!==void 0?t:e.length-1;for(let i=r;i>=0;i--)if(n(e[i],i))return i;return-1}function pn(e,n){return Array.isArray(e)?e.map(t=>d(t,n)):[]}function dn(e,n){return!Array.isArray(e)||!Array.isArray(n)?[]:e.map(t=>{let r={};for(let i of n)i in t&&(r[i]=t[i]);return r})}function Tn(e,n){return!Array.isArray(e)||!Array.isArray(n)?[]:e.map(t=>{let r={...t};for(let i of n)delete r[i];return r})}function gn(e,n){return Array.isArray(e)?e.reduce((t,r,i)=>{let s=n(r,i);return t.concat(s)},[]):[]}function An(e,n,t){if(!Array.isArray(e))return t;let r=t;for(let i=e.length-1;i>=0;i--)r=n(r,e[i],i);return r}function mn(e,n,t=1){if(t===0)return[];let r=[];if(t>0)for(let i=e;i<n;i+=t)r.push(i);else for(let i=e;i>n;i+=t)r.push(i);return r}function xn(e,n,t=0,r){if(!Array.isArray(e))return[];let i=[...e],s=r===void 0?i.length:r;for(let a=t;a<s&&a<i.length;a++)i[a]=n;return i}function hn(e){return Array.isArray(e)?K(e):[]}function bn(e,n,...t){let r,i;if(typeof n=="string")r=n,i=[e];else{let a=t[t.length-1];typeof a=="string"?(r=a,i=[e,n,...t.slice(0,-1).filter(Array.isArray)]):(r="id",i=[e,n,...t.filter(Array.isArray)])}if(i.length===0)return[];let s=new Map;for(let a of i)if(Array.isArray(a))for(let o of a){let u=m(o)?d(o,r):void 0;if(u!==void 0){let f=s.get(u);s.set(u,f?{...f,...o}:o)}}return Array.from(s.values())}function Sn(e,n,t){if(!Array.isArray(e)||n===t)return e?[...e]:[];let r=[...e],[i]=r.splice(n,1);return r.splice(t,0,i),r}function vn(e,n){if(!Array.isArray(e)||e.length===0||n===0)return e?[...e]:[];let t=e.length,r=(n%t+t)%t;return[...e.slice(-r),...e.slice(0,-r)]}function wn(e,n,...t){if(!Array.isArray(e))return t;let r=[...e];return r.splice(n,0,...t),r}function Kn(e,n,t=1){if(!Array.isArray(e))return[];let r=[...e];return r.splice(n,t),r}function On(e,n,t){if(!Array.isArray(e))return[];let r=[...e];return r[n]=t,r}function Pn(e,n){if(!Array.isArray(e))return[];let t=e.filter(r=>r!=null);return n?t.filter(n):t}function Rn(...e){return e.length===0?[[]]:e.length===1?e[0].map(n=>[n]):e.reduce((n,t)=>n.flatMap(r=>t.map(i=>[...r,i])),[[]])}function In(e,n){if(!Array.isArray(e))return[];let t=[];for(let r=0;r<e.length;r++)n(e[r],r)&&t.push(r);return t}function kn(e,n,t=!0){if(!Array.isArray(e)||!Array.isArray(n)||e.length!==n.length)return!1;for(let r=0;r<e.length;r++)if(t&&m(e[r])&&m(n[r])){if(JSON.stringify(e[r])!==JSON.stringify(n[r]))return!1}else if(e[r]!==n[r])return!1;return!0}function Fn(e,n){if(!Array.isArray(e)||e.length===0)return[];let t=[],r=[e[0]],i=n(e[0],0);for(let s=1;s<e.length;s++){let a=n(e[s],s);a===i?r.push(e[s]):(t.push(r),r=[e[s]],i=a)}return t.push(r),t}function jn(e,n,t,r){if(!Array.isArray(e))return[];let i=typeof n=="function",s=i?t:r;return e.map(a=>{let o=!1;return i?o=n(a):o=(m(a)?d(a,n):a)===t,o?{...a,...s}:a})}function En(e,n){if(!Array.isArray(e))return{unique:[],duplicates:[]};let t=new Set,r=[],i=[];for(let s of e){let a=n&&m(s)?d(s,n):s;t.has(a)?i.push(s):(t.add(a),r.push(s))}return{unique:r,duplicates:i}}function Q(e){return Array.isArray(e)?e:e==null?[]:[e]}function Vn(e){return Q(e)}function Mn(e,n,t=1){if(!Array.isArray(e)||n<1||t<1)return[];let r=[];for(let i=0;i<=e.length-n;i+=t)r.push(e.slice(i,i+n));return r}function $n(e,n){if(!Array.isArray(e)||e.length===0)return;let t=e[0],r=typeof n=="function"?n(t):d(t,n);for(let i=1;i<e.length;i++){let s=e[i],a=typeof n=="function"?n(s):d(s,n);a<r&&(r=a,t=s)}return t}function Cn(e,n){if(!Array.isArray(e)||e.length===0)return;let t=e[0],r=typeof n=="function"?n(t):d(t,n);for(let i=1;i<e.length;i++){let s=e[i],a=typeof n=="function"?n(s):d(s,n);a>r&&(r=a,t=s)}return t}function Z(e,n){if(!Array.isArray(e)||e.length===0)return 0;let t=0;for(let r of e){let i=typeof n=="function"?n(r):d(r,n);typeof i=="number"&&!isNaN(i)&&(t+=i)}return t}function Un(e,n){return!Array.isArray(e)||e.length===0?0:Z(e,n)/e.length}function P(e){let n=new Map;if(!Array.isArray(e))return n;for(let t of e)n.set(t,(n.get(t)||0)+1);return n}function G(e,n=1){if(!Array.isArray(e)||e.length===0||n<1)return[];let t=P(e);return Array.from(t.entries()).sort((i,s)=>s[1]-i[1]).slice(0,n).map(([i])=>i)}function Wn(e,n=1){if(!Array.isArray(e)||e.length===0||n<1)return[];let t=P(e);return Array.from(t.entries()).sort((i,s)=>i[1]-s[1]).slice(0,n).map(([i])=>i)}async function Nn(e,n,t){if(!Array.isArray(e)||n<1)return;let r=I(e,n);for(let i=0;i<r.length;i++)await t(r[i],i)}async function Bn(e,n,t,r){if(!Array.isArray(e)||n<1||t<1)return;let i=I(e,n),s=I(i.map((a,o)=>({batch:a,index:o})),t);for(let a of s)await Promise.all(a.map(({batch:o,index:u})=>r(o,u)))}function Ln(e){if(!Array.isArray(e)||e.length===0)return[];let n=Math.max(...e.map(r=>r.length)),t=[];for(let r=0;r<n;r++){let i=[];for(let s=0;s<e.length;s++)r<e[s].length&&i.push(e[s][r]);t.push(i)}return t}function qn(e,n){if(!Array.isArray(e)||!Array.isArray(n)||e.length!==n.length)return!1;for(let t=0;t<e.length;t++)if(e[t]!==n[t])return!1;return!0}function Dn(e,n){if(!Array.isArray(e)||!Array.isArray(n)||e.length!==n.length)return!1;let t=P(e),r=P(n);if(t.size!==r.size)return!1;for(let[i,s]of t)if(r.get(i)!==s)return!1;return!0}function X(e,n){if(!Array.isArray(e)||!Array.isArray(n))return!1;let t=new Set(n);return e.every(r=>t.has(r))}function zn(e,n){return X(n,e)}function Hn(...e){if(e.length===0)return[];let n=Math.max(...e.map(r=>r.length)),t=[];for(let r=0;r<n;r++)for(let i of e)r<i.length&&t.push(i[r]);return t}function _n(e,n){let t=[],r=[];if(!Array.isArray(e))return{pass:t,fail:r};for(let i=0;i<e.length;i++)n(e[i],i)?t.push(e[i]):r.push(e[i]);return{pass:t,fail:r}}function Jn(e,n){if(e<0)return[];let t=[];for(let r=0;r<e;r++)t.push(n(r));return t}function Qn(e,n){if(!Array.isArray(e)||n<0)return[];let t=[];for(let r=0;r<n;r++)t.push(...e);return t}function Zn(e){if(!Array.isArray(e)||e.length===0)return;let n=[...e].sort((r,i)=>r-i),t=Math.floor(n.length/2);return n.length%2===0?(n[t-1]+n[t])/2:n[t]}function Gn(e){let n=G(e,1);return n.length>0?n[0]:void 0}function Xn(e,...n){if(!Array.isArray(e))return[];let t=new Set(n);return e.filter(r=>!t.has(r))}function Yn(e,...n){if(!Array.isArray(e))return[];let t=new Set(n.flat());return e.filter(r=>!t.has(r))}function et(e){if(!Array.isArray(e)||e.length===0)return[];let n=[],t=[e[0]];for(let r=1;r<e.length;r++)e[r]===e[r-1]?t.push(e[r]):(n.push(t),t=[e[r]]);return n.push(t),n}function nt(e){if(!Array.isArray(e)||e.length===0)return[];let n=[e[0]];for(let t=1;t<e.length;t++)e[t]!==e[t-1]&&n.push(e[t]);return n}function tt(e,n="standard"){if(!Array.isArray(e)||e.length===0)return[];let t=e.map((i,s)=>({value:i,index:s}));t.sort((i,s)=>i.value-s.value);let r=new Array(e.length);if(n==="ordinal")for(let i=0;i<t.length;i++)r[t[i].index]=i+1;else if(n==="dense"){let i=1;r[t[0].index]=i;for(let s=1;s<t.length;s++)t[s].value!==t[s-1].value&&i++,r[t[s].index]=i}else{let i=0;for(;i<t.length;){let s=i;for(;s<t.length&&t[s].value===t[i].value;)s++;let a=i+1;for(let o=i;o<s;o++)r[t[o].index]=a;i=s}}return r}function E(e,n){if(!Array.isArray(e)||e.length===0||n<0||n>100)return;let t=[...e].sort((o,u)=>o-u),r=n/100*(t.length-1),i=Math.floor(r),s=Math.ceil(r),a=r-i;return i===s?t[i]:t[i]*(1-a)+t[s]*a}function rt(e){if(!Array.isArray(e)||e.length===0)return;let n=E(e,25),t=E(e,50),r=E(e,75);return{q1:n,q2:t,q3:r,iqr:r-n}}function $(e,n=!1){if(!Array.isArray(e)||e.length===0||n&&e.length===1)return;let t=e.reduce((s,a)=>s+a,0)/e.length,i=e.map(s=>Math.pow(s-t,2)).reduce((s,a)=>s+a,0)/(n?e.length-1:e.length);return Math.sqrt(i)}function it(e,n=!1){let t=$(e,n);return t!==void 0?Math.pow(t,2):void 0}function st(e){if(!Array.isArray(e)||e.length===0)return[];let n=Math.min(...e),r=Math.max(...e)-n;return r===0?e.map(()=>0):e.map(i=>(i-n)/r)}function ot(e){if(!Array.isArray(e)||e.length===0)return[];let n=e.reduce((r,i)=>r+i,0)/e.length,t=$(e);return t===void 0||t===0?e.map(()=>0):e.map(r=>(r-n)/t)}function Y(e,n,t){if(!Array.isArray(e))return[];let r=[],i=t;for(let s=0;s<e.length;s++)i=n(i,e[s],s),r.push(i);return r}function at(e){return Y(e,(n,t)=>n+t,0)}function ut(e){if(!Array.isArray(e)||e.length<2)return[];let n=[];for(let t=1;t<e.length;t++)n.push(e[t]-e[t-1]);return n}function ft(e,n,t,r="end"){if(!Array.isArray(e)||n<=e.length)return[...e];let i=new Array(n-e.length).fill(t);return r==="start"?[...i,...e]:[...e,...i]}function lt(e,n){if(!Array.isArray(e)||e.length===0)return[];let t=0,r=e.length-1;for(;t<=r&&n(e[t]);)t++;for(;r>=t&&n(e[r]);)r--;return e.slice(t,r+1)}function ct(e){if(!Array.isArray(e)||e.length<2)return[];let n=[];for(let t=0;t<e.length-1;t++)n.push([e[t],e[t+1]]);return n}function yt(e){return Array.isArray(e)?e.map((n,t)=>[t,n]):[]}function pt(e,n){return Array.isArray(e)?e.map((t,r)=>{let i=n[r%n.length];return i(t)}):[]}function ee(e,n=1){if(!Array.isArray(e)||e.length===0)return[];let t=e.length,r=(n%t+t)%t;return[...e.slice(r),...e.slice(0,r)]}function dt(e,n=1){return ee(e,-n)}function Tt(e,n,t){if(!Array.isArray(e)||n<0||t<0||n>=e.length||t>=e.length)return[...e];let r=[...e];return[r[n],r[t]]=[r[t],r[n]],r}function gt(e,n,t){if(!Array.isArray(e)||n<0||t>=e.length||n>=t)return[...e];let r=[...e],i=r.slice(n,t+1).reverse();return r.splice(n,t-n+1,...i),r}function At(e,n){if(!Array.isArray(e)||e.length<=1)return!0;let t=n||((r,i)=>r<i?-1:r>i?1:0);for(let r=1;r<e.length;r++)if(t(e[r-1],e[r])>0)return!1;return!0}function mt(e){return Array.isArray(e)?new Set(e).size!==e.length:!1}function xt(e,n){return Array.isArray(e)?e.map(t=>{let r={};for(let i of n)i in t&&(r[i]=t[i]);return r}):[]}function ne(e,n,t){if(!Array.isArray(e))return{};let r={};for(let i=0;i<e.length;i++){let s=n(e[i],i),a=t?t(e[i],i):e[i];r[s]=a}return r}async function ht(e,n){if(!Array.isArray(e))return[];let t=[];for(let r=0;r<e.length;r++)t.push(await n(e[r],r));return t}async function bt(e,n){return Array.isArray(e)?Promise.all(e.map((t,r)=>n(t,r))):[]}async function St(e,n){if(!Array.isArray(e))return[];let t=[];for(let r=0;r<e.length;r++)await n(e[r],r)&&t.push(e[r]);return t}async function vt(e,n,t){if(!Array.isArray(e))return t;let r=t;for(let i=0;i<e.length;i++)r=await n(r,e[i],i);return r}async function wt(e,n){if(Array.isArray(e)){for(let t=0;t<e.length;t++)if(await n(e[t],t))return e[t]}}async function Kt(e,n){if(!Array.isArray(e))return!1;for(let t=0;t<e.length;t++)if(await n(e[t],t))return!0;return!1}async function Ot(e,n){if(!Array.isArray(e))return!0;for(let t=0;t<e.length;t++)if(!await n(e[t],t))return!1;return!0}function Pt(e,n,t){if(!Array.isArray(e)||e.length===0)return 0;let r=0,i=0;for(let s of e){let a=typeof n=="function"?n(s):d(s,n),o=typeof t=="function"?t(s):d(s,t);typeof a=="number"&&typeof o=="number"&&(i+=a*o,r+=o)}return r===0?0:i/r}function Rt(e,n,t=1){if(!Array.isArray(e)||e.length===0||t<1)return[];let r=[],i=0;for(let a of e){let o=typeof n=="function"?n(a):d(a,n);i+=typeof o=="number"&&o>0?o:0,r.push(i)}if(i===0)return[];let s=[];for(let a=0;a<t;a++){let o=Math.random()*i,u=r.findIndex(f=>o<f);u!==-1&&s.push(e[u])}return s}function It(e,n){if(!Array.isArray(e)||!Array.isArray(n))return[];let t=[],r=0;for(let i of n){if(r>=e.length)break;t.push(e.slice(r,r+i)),r+=i}return t}function kt(e,n){if(!Array.isArray(e)||n<1)return[];let t=P(e),r=[];for(let i of e)t.get(i)===n&&r.push(i);return r}function Ft(e,n,t){if(!Array.isArray(e)||n<1)return[];let r=[],i=0,s=[];for(let a of e)t(a)?(i++,s.push(a),i>=n&&r.push(...s.splice(0,s.length-n+1))):(i=0,s.length=0);return i>=n&&r.push(...s),r}function jt(e,n,t){if(!Array.isArray(e))return[];let r=[],i=t;for(let s=0;s<e.length;s++){let{value:a,newContext:o}=n(e[s],i,s);r.push(a),i=o}return r}function Et(e,n){return I(e,n)}function Vt(e,n,t){if(!Array.isArray(e)||!Array.isArray(n))return[];let r=Math.min(e.length,n.length),i=[];for(let s=0;s<r;s++)i.push(t(e[s],n[s]));return i}function Mt(e,n,t="last"){if(!Array.isArray(e)||e.length===0)return[];let r=new Map;for(let s of e)if(Array.isArray(s))for(let a of s){let o=d(a,n);if(t==="first")r.has(o)||r.set(o,a);else if(t==="last")r.set(o,a);else if(t==="concat"){let u=r.get(o);Array.isArray(u)?u.push(a):u?r.set(o,[u,a]):r.set(o,a)}else if(typeof t=="function"){let u=r.get(o);u&&!Array.isArray(u)?r.set(o,t(u,a)):r.set(o,a)}}let i=[];for(let s of r.values())Array.isArray(s)&&t==="concat"?i.push(...s):Array.isArray(s)||i.push(s);return i}function $t(e,n){return ne(e,t=>String(d(t,n)))}function Ct(e,n,t){if(!Array.isArray(e)||e.length===0)return-1;let r=t||((a,o)=>a<o?-1:a>o?1:0),i=0,s=e.length-1;for(;i<=s;){let a=Math.floor((i+s)/2),o=r(e[a],n);if(o===0)return a;o<0?i=a+1:s=a-1}return-1}function Ut(e,n,t){if(!Array.isArray(e))return[n];let r=t||((a,o)=>a<o?-1:a>o?1:0),i=[...e],s=0;for(;s<i.length&&r(i[s],n)<0;)s++;return i.splice(s,0,n),i}function Wt(e){return e&&typeof e.addEventListener=="function"}function Nt(e){return e&&typeof e.addEventListener=="function"&&typeof e.removeEventListener=="function"}function Bt(e){return e&&typeof e.on=="function"&&typeof e.off=="function"}function Lt(e){return e&&typeof e.addListener=="function"&&typeof e.removeListener=="function"}function qt(){return typeof globalThis=="object"?globalThis:typeof window=="object"?window:typeof self=="object"?self:typeof global=="object"?global:null}function Dt(e){return Buffer.from(e).toString("base64")}function zt(e){return Buffer.from(e).toString("base64")}function Ht(e){return decodeURIComponent(Buffer.from(e,"base64").toString("utf-8"))}var _t=(e,n,t)=>{let r=t,i=new RegExp("([?&])"+n+"=.*?(&|$)","i"),s=e.includes("?")?"&":"?";n==="country"&&(r=JSON.parse(r).alpha_2),n==="phone"&&(r=r.trim().replace(/\s/g,""));let a=e.match(i);return typeof a<"u"&&a!==null?e.replace(i,"$1"+n+"="+r+"$2"):e+s+n+"="+r};var Jt=async(e,n="SHA-1")=>{if(typeof window>"u")return null;let{subtle:t}=window.globalThis.crypto,r=await t.generateKey({name:"HMAC",hash:n,length:256},!0,["sign","verify"]),s=new TextEncoder().encode(e),a=await t.sign({name:"HMAC"},r,s);return[...new Uint8Array(a)].map(u=>u.toString(16).padStart(2,"0")).join("")},C=async(e,n="SHA-256")=>{let r=new TextEncoder().encode(e),i=await crypto.subtle.digest(n,r);return Array.from(new Uint8Array(i)).map(o=>o.toString(16).padStart(2,"0")).join("")},Qt=async(e,n,t="SHA-256")=>{let r=await C(e,t),i=await C(n,t);return r===i};async function Zt(e,n="SHA-256"){let r=new TextEncoder().encode(e),i=await crypto.subtle.digest(n,r);return Array.from(new Uint8Array(i)).map(o=>o.toString(16).padStart(2,"0")).join("")}var Gt=e=>{let n=0;for(let t=0;t<e.length;t++){let r=e.charCodeAt(t);n=(n<<5)-n+r,n=n&n}return n.toString(16)};var te=require("@fluixi/utils/object");function re(e){return typeof e=="function"&&!(0,te.isClass)(e)}function Xt(e){return e instanceof Promise||!!e&&(typeof e=="object"||typeof e=="function")&&"then"in e}function Yt(e){return re(e)&&e.constructor.name==="AsyncFunction"}function er(e,n){let t=new Map,r=function(...i){let s=n?n(...i):JSON.stringify(i);if(t.has(s))return t.get(s);let a=e.apply(this,i);return t.set(s,a),a};return r.cache=t,r}function ie(e,n,t={}){let{leading:r=!1,trailing:i=!0,maxWait:s}=t,a,o,u,f=0,y,T,p;function b(A){let v=y,w=T;return y=T=void 0,f=A,p=e.apply(w,v),p}function l(A,v){return setTimeout(A,v)}function c(A){A!==void 0&&clearTimeout(A)}function g(A){return f=A,a=l(O,n),r?b(A):p}function x(A){let v=A-u,w=A-f,W=n-v;return s!==void 0?Math.min(W,s-w):W}function h(A){let v=A-u,w=A-f;return u===void 0||v>=n||v<0||s!==void 0&&w>=s}function O(){let A=Date.now();if(h(A)){U(A);return}a=l(O,x(A))}function U(A){return a=void 0,i&&y?b(A):(y=T=void 0,p)}function ae(){c(a),c(o),f=0,y=u=T=a=o=void 0}function ue(){return a===void 0?p:U(Date.now())}function fe(){return a!==void 0}function k(...A){let v=Date.now(),w=h(v);if(y=A,T=this,u=v,w){if(a===void 0)return g(u);if(s!==void 0)return a=l(O,n),b(u)}return a===void 0&&(a=l(O,n)),p}return k.cancel=ae,k.flush=ue,k.pending=fe,k}function nr(e,n,t={}){let{leading:r=!0,trailing:i=!0}=t;return ie(e,n,{leading:r,trailing:i,maxWait:n})}function tr(e){let n=!1,t,r=function(...i){return n||(n=!0,t=e.apply(this,i)),t};return Object.defineProperty(r,"called",{get(){return n}}),r}function rr(e,...n){return function(...t){let r=n.map(i=>t[i]);return e.apply(this,r)}}function ir(e,n=e.length){return function t(...r){return r.length>=n?e.apply(this,r):function(...i){return t.apply(this,[...r,...i])}}}function se(...e){return e.reduceRight((n,t)=>r=>t(n(r)),n=>n)}function oe(...e){return e.reduce((n,t)=>r=>t(n(r)),n=>n)}function sr(e){return function(...n){return!e.apply(this,n)}}function or(e,...n){return function(...t){let r=t.map((i,s)=>n[s]?n[s](i):i);return e.apply(this,r)}}function ar(e,...n){return function(...t){return e.apply(this,[...n,...t])}}function ur(e,...n){return function(...t){return e.apply(this,[...t,...n])}}function fr(e,n,...t){return function(...r){return e.apply(n,[...t,...r])}}function lr(e){return function(...n){return e.apply(this,n.reverse())}}function cr(e,n){return function(...t){return e.apply(this,t.slice(0,n))}}function yr(e){return function(n){return e.call(this,n)}}function pr(e,...n){return setTimeout(e,1,...n)}function dr(e,n,...t){return setTimeout(e,n,...t)}function Tr(e,n,t){let r=new Map,i=function(...s){let a=t?t(...s):JSON.stringify(s),o=Date.now(),u=r.get(a);if(u&&u.expires>o)return u.value;let f=e.apply(this,s);r.set(a,{value:f,expires:o+n});for(let[y,T]of r.entries())T.expires<=o&&r.delete(y);return f};return i.cache=r,i}function gr(e,n){let t,r=0;return function(...i){return++r<n&&(t=e.apply(this,i)),r>=n&&(e=void 0),t}}function Ar(e,n){let t=0;return function(...r){if(++t>=n)return e.apply(this,r)}}function mr(e,n){return function(...t){try{return e.apply(this,t)}catch(r){return n(r,...t)}}}function xr(...e){return oe(...e)}function hr(...e){return se(...e)}function br(e,n={}){let{retries:t=3,delay:r=1e3,backoff:i=2,onRetry:s}=n;return async function(...a){let o,u=r;for(let f=0;f<=t;f++)try{return await e.apply(this,a)}catch(y){o=y,f<t&&(s&&s(o,f+1),await new Promise(T=>setTimeout(T,u)),u*=i)}throw o}}function Sr(e,n,t){return async function(...r){return Promise.race([e.apply(this,r),new Promise((i,s)=>setTimeout(()=>{t&&t(),s(new Error(`Function timed out after ${n}ms`))},n))])}}
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/lib/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
aenu: () => aenu,
|
|
24
|
+
after: () => after,
|
|
25
|
+
applyByIndex: () => applyByIndex,
|
|
26
|
+
ary: () => ary,
|
|
27
|
+
at: () => at,
|
|
28
|
+
avgBy: () => avgBy,
|
|
29
|
+
batch: () => batch,
|
|
30
|
+
batchProcess: () => batchProcess,
|
|
31
|
+
batchProcessParallel: () => batchProcessParallel,
|
|
32
|
+
before: () => before,
|
|
33
|
+
bifurcate: () => bifurcate,
|
|
34
|
+
binarySearch: () => binarySearch,
|
|
35
|
+
bind: () => bind,
|
|
36
|
+
btoa: () => btoa,
|
|
37
|
+
cartesian: () => cartesian,
|
|
38
|
+
chunk: () => chunk,
|
|
39
|
+
chunkBy: () => chunkBy,
|
|
40
|
+
compact: () => compact,
|
|
41
|
+
compareWithHash: () => compareWithHash,
|
|
42
|
+
compose: () => compose,
|
|
43
|
+
countBy: () => countBy,
|
|
44
|
+
createHash: () => createHash,
|
|
45
|
+
cumulativeSum: () => cumulativeSum,
|
|
46
|
+
curry: () => curry,
|
|
47
|
+
debounce: () => debounce,
|
|
48
|
+
dedupeConsecutive: () => dedupeConsecutive,
|
|
49
|
+
deepCloneArray: () => deepCloneArray,
|
|
50
|
+
defer: () => defer,
|
|
51
|
+
delay: () => delay,
|
|
52
|
+
diff: () => diff,
|
|
53
|
+
difference: () => difference,
|
|
54
|
+
differenceWith: () => differenceWith,
|
|
55
|
+
drop: () => drop,
|
|
56
|
+
dropWhile: () => dropWhile,
|
|
57
|
+
ensureArray: () => ensureArray,
|
|
58
|
+
enumerate: () => enumerate,
|
|
59
|
+
everyAsync: () => everyAsync,
|
|
60
|
+
fill: () => fill,
|
|
61
|
+
filterAsync: () => filterAsync,
|
|
62
|
+
filterCompact: () => filterCompact,
|
|
63
|
+
filterConsecutive: () => filterConsecutive,
|
|
64
|
+
findAllIndices: () => findAllIndices,
|
|
65
|
+
findAsync: () => findAsync,
|
|
66
|
+
findIndex: () => findIndex,
|
|
67
|
+
findLastIndex: () => findLastIndex,
|
|
68
|
+
first: () => first,
|
|
69
|
+
flatMap: () => flatMap,
|
|
70
|
+
flatten: () => flatten,
|
|
71
|
+
flattenArray: () => flattenArray,
|
|
72
|
+
flattenDeep: () => flattenDeep,
|
|
73
|
+
flip: () => flip,
|
|
74
|
+
flow: () => flow,
|
|
75
|
+
flowRight: () => flowRight,
|
|
76
|
+
frequencies: () => frequencies,
|
|
77
|
+
generate: () => generate,
|
|
78
|
+
generateID: () => generateID,
|
|
79
|
+
generateUUID: () => generateUUID,
|
|
80
|
+
getKind: () => getKind,
|
|
81
|
+
groupArrayBy: () => groupArrayBy,
|
|
82
|
+
groupBy: () => groupBy,
|
|
83
|
+
groupConsecutive: () => groupConsecutive,
|
|
84
|
+
hasDuplicates: () => hasDuplicates,
|
|
85
|
+
hasSameElements: () => hasSameElements,
|
|
86
|
+
hash: () => hash,
|
|
87
|
+
hashStringPromise: () => hashStringPromise,
|
|
88
|
+
indexBy: () => indexBy,
|
|
89
|
+
insert: () => insert,
|
|
90
|
+
insertSorted: () => insertSorted,
|
|
91
|
+
interleave: () => interleave,
|
|
92
|
+
intersection: () => intersection,
|
|
93
|
+
isAddRemoveListenerTarget: () => isAddRemoveListenerTarget,
|
|
94
|
+
isArray: () => isArray,
|
|
95
|
+
isArrayEqual: () => isArrayEqual,
|
|
96
|
+
isArrayLike: () => isArrayLike,
|
|
97
|
+
isArrayOfBoolean: () => isArrayOfBoolean,
|
|
98
|
+
isArrayOfNumber: () => isArrayOfNumber,
|
|
99
|
+
isArrayOfObject: () => isArrayOfObject,
|
|
100
|
+
isArrayOfString: () => isArrayOfString,
|
|
101
|
+
isAsyncFunction: () => isAsyncFunction,
|
|
102
|
+
isDOMEventTarget: () => isDOMEventTarget,
|
|
103
|
+
isDefined: () => isDefined,
|
|
104
|
+
isDoubleArray: () => isDoubleArray,
|
|
105
|
+
isEmptyArray: () => isEmptyArray,
|
|
106
|
+
isEqual: () => isEqual,
|
|
107
|
+
isFunction: () => isFunction2,
|
|
108
|
+
isIterable: () => isIterable,
|
|
109
|
+
isNodeEventEmitter: () => isNodeEventEmitter,
|
|
110
|
+
isNonEmptyArray: () => isNonEmptyArray,
|
|
111
|
+
isNull: () => isNull,
|
|
112
|
+
isObjectArray: () => isObjectArray,
|
|
113
|
+
isOnOffTarget: () => isOnOffTarget,
|
|
114
|
+
isPrimitive: () => isPrimitive,
|
|
115
|
+
isPromise: () => isPromise,
|
|
116
|
+
isReadonlyArray: () => isReadonlyArray,
|
|
117
|
+
isSorted: () => isSorted,
|
|
118
|
+
isStaticArray: () => isStaticArray,
|
|
119
|
+
isSubset: () => isSubset,
|
|
120
|
+
isSuperset: () => isSuperset,
|
|
121
|
+
isTypedArray: () => isTypedArray,
|
|
122
|
+
isUndefined: () => isUndefined,
|
|
123
|
+
isUndefinedOrNull: () => isUndefinedOrNull,
|
|
124
|
+
keyBy: () => keyBy,
|
|
125
|
+
last: () => last,
|
|
126
|
+
leastCommon: () => leastCommon,
|
|
127
|
+
mapAsync: () => mapAsync,
|
|
128
|
+
mapAsyncParallel: () => mapAsyncParallel,
|
|
129
|
+
mapWithContext: () => mapWithContext,
|
|
130
|
+
maxBy: () => maxBy,
|
|
131
|
+
median: () => median,
|
|
132
|
+
memoize: () => memoize,
|
|
133
|
+
memoizeWithTTL: () => memoizeWithTTL,
|
|
134
|
+
mergeArraysByKey: () => mergeArraysByKey,
|
|
135
|
+
mergeByKey: () => mergeByKey,
|
|
136
|
+
minBy: () => minBy,
|
|
137
|
+
mode: () => mode,
|
|
138
|
+
mostCommon: () => mostCommon,
|
|
139
|
+
move: () => move,
|
|
140
|
+
negate: () => negate,
|
|
141
|
+
normalize: () => normalize,
|
|
142
|
+
omit: () => omit,
|
|
143
|
+
once: () => once,
|
|
144
|
+
overArgs: () => overArgs,
|
|
145
|
+
pad: () => pad,
|
|
146
|
+
pairwise: () => pairwise,
|
|
147
|
+
partial: () => partial,
|
|
148
|
+
partialRight: () => partialRight,
|
|
149
|
+
partition: () => partition,
|
|
150
|
+
percentile: () => percentile,
|
|
151
|
+
pick: () => pick,
|
|
152
|
+
pickMany: () => pickMany,
|
|
153
|
+
pipe: () => pipe,
|
|
154
|
+
pluck: () => pluck,
|
|
155
|
+
quartiles: () => quartiles,
|
|
156
|
+
range: () => range,
|
|
157
|
+
rank: () => rank,
|
|
158
|
+
rearg: () => rearg,
|
|
159
|
+
reduceAsync: () => reduceAsync,
|
|
160
|
+
reduceRight: () => reduceRight,
|
|
161
|
+
remove: () => remove,
|
|
162
|
+
repeat: () => repeat,
|
|
163
|
+
replace: () => replace,
|
|
164
|
+
retry: () => retry,
|
|
165
|
+
reverseSegment: () => reverseSegment,
|
|
166
|
+
rotate: () => rotate,
|
|
167
|
+
rotateLeft: () => rotateLeft,
|
|
168
|
+
rotateRight: () => rotateRight,
|
|
169
|
+
sample: () => sample,
|
|
170
|
+
sampleSize: () => sampleSize,
|
|
171
|
+
scan: () => scan,
|
|
172
|
+
segment: () => segment,
|
|
173
|
+
selectByCount: () => selectByCount,
|
|
174
|
+
shuffle: () => shuffle,
|
|
175
|
+
slidingWindow: () => slidingWindow,
|
|
176
|
+
someAsync: () => someAsync,
|
|
177
|
+
sortBy: () => sortBy,
|
|
178
|
+
splitDuplicates: () => splitDuplicates,
|
|
179
|
+
standardDeviation: () => standardDeviation,
|
|
180
|
+
standardize: () => standardize,
|
|
181
|
+
string_hash: () => string_hash,
|
|
182
|
+
sumBy: () => sumBy,
|
|
183
|
+
swap: () => swap,
|
|
184
|
+
take: () => take,
|
|
185
|
+
takeLast: () => takeLast,
|
|
186
|
+
takeWhile: () => takeWhile,
|
|
187
|
+
throttle: () => throttle,
|
|
188
|
+
toArray: () => toArray,
|
|
189
|
+
toArrayString: () => toArrayString,
|
|
190
|
+
toObject: () => toObject,
|
|
191
|
+
transpose: () => transpose,
|
|
192
|
+
trim: () => trim,
|
|
193
|
+
tryCatch: () => tryCatch,
|
|
194
|
+
uena: () => uena,
|
|
195
|
+
unary: () => unary,
|
|
196
|
+
union: () => union,
|
|
197
|
+
unique: () => unique,
|
|
198
|
+
unzip: () => unzip,
|
|
199
|
+
updateBy: () => updateBy,
|
|
200
|
+
updateQueryStringParameter: () => updateQueryStringParameter,
|
|
201
|
+
variance: () => variance,
|
|
202
|
+
weightedAverage: () => weightedAverage,
|
|
203
|
+
weightedSample: () => weightedSample,
|
|
204
|
+
windowObject: () => windowObject,
|
|
205
|
+
withTimeout: () => withTimeout,
|
|
206
|
+
without: () => without,
|
|
207
|
+
wrap: () => wrap,
|
|
208
|
+
zip: () => zip,
|
|
209
|
+
zipWith: () => zipWith
|
|
210
|
+
});
|
|
211
|
+
module.exports = __toCommonJS(index_exports);
|
|
212
|
+
|
|
213
|
+
// src/lib/array/array.ts
|
|
214
|
+
var toArrayString = (value) => {
|
|
215
|
+
if (Array.isArray(value)) {
|
|
216
|
+
return value;
|
|
217
|
+
} else if (typeof value === "string") {
|
|
218
|
+
if (value.startsWith("[") && value.endsWith("]")) {
|
|
219
|
+
try {
|
|
220
|
+
return JSON.parse(value);
|
|
221
|
+
} catch (err) {
|
|
222
|
+
return [];
|
|
223
|
+
}
|
|
224
|
+
} else {
|
|
225
|
+
return [value];
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return [];
|
|
229
|
+
};
|
|
230
|
+
function isArrayOfString(value) {
|
|
231
|
+
return Array.isArray(value) && value.every((item) => typeof item === "string");
|
|
232
|
+
}
|
|
233
|
+
function isArrayOfNumber(value) {
|
|
234
|
+
return Array.isArray(value) && value.every((item) => typeof item === "number");
|
|
235
|
+
}
|
|
236
|
+
function isArrayOfBoolean(value) {
|
|
237
|
+
return Array.isArray(value) && value.every((item) => typeof item === "boolean");
|
|
238
|
+
}
|
|
239
|
+
function isArrayOfObject(value) {
|
|
240
|
+
return Array.isArray(value) && value.every((item) => typeof item === "object");
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// src/lib/array/utils.ts
|
|
244
|
+
var import_object = require("@fluixi/utils/object");
|
|
245
|
+
var isObjectArray = (value) => {
|
|
246
|
+
return Array.isArray(value) && value.every((item) => (0, import_object.isObject)(item));
|
|
247
|
+
};
|
|
248
|
+
function isArray(v) {
|
|
249
|
+
return Array.isArray(v);
|
|
250
|
+
}
|
|
251
|
+
function isStaticArray(v) {
|
|
252
|
+
return Array.isArray(v);
|
|
253
|
+
}
|
|
254
|
+
function isDoubleArray(v) {
|
|
255
|
+
return Array.isArray(v) && v.every((item) => Array.isArray(item) && item.length === 2);
|
|
256
|
+
}
|
|
257
|
+
function isIterable(v) {
|
|
258
|
+
return v != null && typeof v[Symbol.iterator] === "function";
|
|
259
|
+
}
|
|
260
|
+
function isArrayLike(v) {
|
|
261
|
+
return v != null && typeof v === "object" && "length" in v && typeof v.length === "number" && v.length >= 0 && (v.length === 0 || v.length - 1 in v);
|
|
262
|
+
}
|
|
263
|
+
function isEmptyArray(v) {
|
|
264
|
+
return Array.isArray(v) && v.length === 0;
|
|
265
|
+
}
|
|
266
|
+
function isNonEmptyArray(v) {
|
|
267
|
+
return Array.isArray(v) && v.length > 0;
|
|
268
|
+
}
|
|
269
|
+
function isTypedArray(v) {
|
|
270
|
+
return ArrayBuffer.isView(v) && !(v instanceof DataView);
|
|
271
|
+
}
|
|
272
|
+
function isReadonlyArray(v) {
|
|
273
|
+
return Array.isArray(v);
|
|
274
|
+
}
|
|
275
|
+
function last(arr) {
|
|
276
|
+
return arr.length > 0 ? arr[arr.length - 1] : void 0;
|
|
277
|
+
}
|
|
278
|
+
function first(arr) {
|
|
279
|
+
return arr.length > 0 ? arr[0] : void 0;
|
|
280
|
+
}
|
|
281
|
+
function toArray(iterable) {
|
|
282
|
+
if (Array.isArray(iterable)) {
|
|
283
|
+
return [...iterable];
|
|
284
|
+
}
|
|
285
|
+
if (isIterable(iterable)) {
|
|
286
|
+
return [...iterable];
|
|
287
|
+
}
|
|
288
|
+
return Array.from(iterable);
|
|
289
|
+
}
|
|
290
|
+
function groupArrayBy(arr, keyFn) {
|
|
291
|
+
return arr.reduce((groups, item) => {
|
|
292
|
+
const key = keyFn(item);
|
|
293
|
+
if (!groups[key]) {
|
|
294
|
+
groups[key] = [];
|
|
295
|
+
}
|
|
296
|
+
groups[key].push(item);
|
|
297
|
+
return groups;
|
|
298
|
+
}, {});
|
|
299
|
+
}
|
|
300
|
+
function flattenArray(arr) {
|
|
301
|
+
return arr.flat();
|
|
302
|
+
}
|
|
303
|
+
function at(arr, index) {
|
|
304
|
+
const normalizedIndex = index < 0 ? arr.length + index : index;
|
|
305
|
+
return arr[normalizedIndex];
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// src/lib/object/utils.ts
|
|
309
|
+
var isObject2 = (value) => {
|
|
310
|
+
if (value == null) return false;
|
|
311
|
+
if (Array.isArray(value)) return false;
|
|
312
|
+
if (typeof value === "function") return false;
|
|
313
|
+
if (value instanceof Date) return false;
|
|
314
|
+
if (value instanceof RegExp) return false;
|
|
315
|
+
if (value instanceof Map) return false;
|
|
316
|
+
if (value instanceof Set) return false;
|
|
317
|
+
if (value instanceof Error) return false;
|
|
318
|
+
return typeof value === "object";
|
|
319
|
+
};
|
|
320
|
+
var traverseStructure = (current, segments, depth, maxDepth) => {
|
|
321
|
+
if (depth > maxDepth) return void 0;
|
|
322
|
+
if (segments.length === 0) return current;
|
|
323
|
+
const segment2 = segments[0];
|
|
324
|
+
const remaining = segments.slice(1);
|
|
325
|
+
if (segment2.type === "descendant") {
|
|
326
|
+
const result = traverseStructure(current, remaining, depth + 1, maxDepth);
|
|
327
|
+
if (result !== void 0) {
|
|
328
|
+
return result;
|
|
329
|
+
}
|
|
330
|
+
if (current && typeof current === "object") {
|
|
331
|
+
if (Array.isArray(current)) {
|
|
332
|
+
const arrResult = [];
|
|
333
|
+
for (let i = 0; i < current.length; i++) {
|
|
334
|
+
const itemResult = traverseStructure(
|
|
335
|
+
current[i],
|
|
336
|
+
segments,
|
|
337
|
+
depth + 1,
|
|
338
|
+
maxDepth
|
|
339
|
+
);
|
|
340
|
+
if (itemResult !== void 0) {
|
|
341
|
+
arrResult[i] = itemResult;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
return arrResult.length > 0 ? arrResult : void 0;
|
|
345
|
+
} else {
|
|
346
|
+
const objResult = {};
|
|
347
|
+
for (const key in current) {
|
|
348
|
+
if (current.hasOwnProperty(key)) {
|
|
349
|
+
const itemResult = traverseStructure(
|
|
350
|
+
current[key],
|
|
351
|
+
segments,
|
|
352
|
+
depth + 1,
|
|
353
|
+
maxDepth
|
|
354
|
+
);
|
|
355
|
+
if (itemResult !== void 0) {
|
|
356
|
+
objResult[key] = itemResult;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
return Object.keys(objResult).length > 0 ? objResult : void 0;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
return void 0;
|
|
364
|
+
}
|
|
365
|
+
switch (segment2.type) {
|
|
366
|
+
case "property":
|
|
367
|
+
if (isObject2(current) && segment2.value && String(segment2.value) in current) {
|
|
368
|
+
const next = current[String(segment2.value)];
|
|
369
|
+
const result = traverseStructure(next, remaining, depth + 1, maxDepth);
|
|
370
|
+
if (result !== void 0) {
|
|
371
|
+
return { [String(segment2.value)]: result };
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
break;
|
|
375
|
+
case "index":
|
|
376
|
+
if (Array.isArray(current)) {
|
|
377
|
+
const index = segment2.value;
|
|
378
|
+
if (index >= 0 && index < current.length) {
|
|
379
|
+
const result = traverseStructure(
|
|
380
|
+
current[index],
|
|
381
|
+
remaining,
|
|
382
|
+
depth + 1,
|
|
383
|
+
maxDepth
|
|
384
|
+
);
|
|
385
|
+
if (result !== void 0) {
|
|
386
|
+
const arr = new Array(current.length).filter(
|
|
387
|
+
(a) => a !== void 0
|
|
388
|
+
);
|
|
389
|
+
arr[index] = result;
|
|
390
|
+
return arr;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
} else if (current && typeof current === "object") {
|
|
394
|
+
const key = String(segment2.value);
|
|
395
|
+
if (key in current) {
|
|
396
|
+
const result = traverseStructure(
|
|
397
|
+
current[key],
|
|
398
|
+
remaining,
|
|
399
|
+
depth + 1,
|
|
400
|
+
maxDepth
|
|
401
|
+
);
|
|
402
|
+
if (result !== void 0) {
|
|
403
|
+
return { [key]: result };
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
break;
|
|
408
|
+
case "wildcard":
|
|
409
|
+
if (current && typeof current === "object") {
|
|
410
|
+
if (Array.isArray(current)) {
|
|
411
|
+
const arrResult = [];
|
|
412
|
+
let hasResults = false;
|
|
413
|
+
for (let i = 0; i < current.length; i++) {
|
|
414
|
+
const result = traverseStructure(
|
|
415
|
+
current[i],
|
|
416
|
+
remaining,
|
|
417
|
+
depth + 1,
|
|
418
|
+
maxDepth
|
|
419
|
+
);
|
|
420
|
+
if (result !== void 0) {
|
|
421
|
+
arrResult[i] = result;
|
|
422
|
+
hasResults = true;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
return hasResults ? arrResult : void 0;
|
|
426
|
+
} else {
|
|
427
|
+
const objResult = {};
|
|
428
|
+
let hasResults = false;
|
|
429
|
+
for (const key in current) {
|
|
430
|
+
if (current.hasOwnProperty(key)) {
|
|
431
|
+
const result = traverseStructure(
|
|
432
|
+
current[key],
|
|
433
|
+
remaining,
|
|
434
|
+
depth + 1,
|
|
435
|
+
maxDepth
|
|
436
|
+
);
|
|
437
|
+
if (result !== void 0) {
|
|
438
|
+
objResult[key] = result;
|
|
439
|
+
hasResults = true;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
return hasResults ? objResult : void 0;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
break;
|
|
447
|
+
case "slice":
|
|
448
|
+
if (Array.isArray(current)) {
|
|
449
|
+
const [start, end] = segment2.value;
|
|
450
|
+
const actualStart = Math.max(0, start);
|
|
451
|
+
const actualEnd = Math.min(
|
|
452
|
+
current.length,
|
|
453
|
+
end === Infinity ? current.length : end
|
|
454
|
+
);
|
|
455
|
+
const arrResult = [];
|
|
456
|
+
let hasResults = false;
|
|
457
|
+
for (let i = actualStart; i < actualEnd; i++) {
|
|
458
|
+
const result = traverseStructure(
|
|
459
|
+
current[i],
|
|
460
|
+
remaining,
|
|
461
|
+
depth + 1,
|
|
462
|
+
maxDepth
|
|
463
|
+
);
|
|
464
|
+
if (result !== void 0) {
|
|
465
|
+
arrResult[i] = result;
|
|
466
|
+
hasResults = true;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
return hasResults ? arrResult : void 0;
|
|
470
|
+
}
|
|
471
|
+
break;
|
|
472
|
+
case "union":
|
|
473
|
+
if (Array.isArray(current)) {
|
|
474
|
+
const indices = segment2.value;
|
|
475
|
+
const arrResult = [];
|
|
476
|
+
let hasResults = false;
|
|
477
|
+
for (const index of indices) {
|
|
478
|
+
if (index >= 0 && index < current.length) {
|
|
479
|
+
const result = traverseStructure(
|
|
480
|
+
current[index],
|
|
481
|
+
remaining,
|
|
482
|
+
depth + 1,
|
|
483
|
+
maxDepth
|
|
484
|
+
);
|
|
485
|
+
if (result !== void 0) {
|
|
486
|
+
arrResult[index] = result;
|
|
487
|
+
hasResults = true;
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
return hasResults ? arrResult : void 0;
|
|
492
|
+
}
|
|
493
|
+
break;
|
|
494
|
+
case "filter":
|
|
495
|
+
if (Array.isArray(current)) {
|
|
496
|
+
const filterFn = segment2.value;
|
|
497
|
+
const arrResult = [];
|
|
498
|
+
let hasResults = false;
|
|
499
|
+
for (let i = 0; i < current.length; i++) {
|
|
500
|
+
if (filterFn(current[i])) {
|
|
501
|
+
const result = traverseStructure(
|
|
502
|
+
current[i],
|
|
503
|
+
remaining,
|
|
504
|
+
depth + 1,
|
|
505
|
+
maxDepth
|
|
506
|
+
);
|
|
507
|
+
if (result !== void 0) {
|
|
508
|
+
arrResult[i] = result;
|
|
509
|
+
hasResults = true;
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
return hasResults ? arrResult : void 0;
|
|
514
|
+
}
|
|
515
|
+
break;
|
|
516
|
+
}
|
|
517
|
+
return void 0;
|
|
518
|
+
};
|
|
519
|
+
|
|
520
|
+
// src/lib/object/clone.ts
|
|
521
|
+
var deepClone = (obj, skipKeys) => {
|
|
522
|
+
if (obj == null || typeof obj !== "object") {
|
|
523
|
+
return obj;
|
|
524
|
+
}
|
|
525
|
+
if (obj instanceof Date) {
|
|
526
|
+
return new Date(obj.getTime());
|
|
527
|
+
}
|
|
528
|
+
if (obj instanceof RegExp) {
|
|
529
|
+
return new RegExp(obj.source, obj.flags);
|
|
530
|
+
}
|
|
531
|
+
if (obj instanceof Map) {
|
|
532
|
+
const clone = /* @__PURE__ */ new Map();
|
|
533
|
+
obj.forEach((value, key) => {
|
|
534
|
+
if (!skipKeys || !skipKeys.some((k) => k.toString() === key.toString())) {
|
|
535
|
+
clone.set(key, deepClone(value));
|
|
536
|
+
}
|
|
537
|
+
});
|
|
538
|
+
return clone;
|
|
539
|
+
}
|
|
540
|
+
if (obj instanceof Set) {
|
|
541
|
+
const clone = /* @__PURE__ */ new Set();
|
|
542
|
+
obj.forEach((value) => {
|
|
543
|
+
clone.add(deepClone(value));
|
|
544
|
+
});
|
|
545
|
+
return clone;
|
|
546
|
+
}
|
|
547
|
+
if (Array.isArray(obj)) {
|
|
548
|
+
return Array.from(obj).map((item) => deepClone(item));
|
|
549
|
+
}
|
|
550
|
+
if (isObject2(obj)) {
|
|
551
|
+
const clone = {};
|
|
552
|
+
for (const key in obj) {
|
|
553
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
554
|
+
if (!skipKeys || !skipKeys.some((k) => k.toString() === key.toString())) {
|
|
555
|
+
clone[key] = deepClone(obj[key]);
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
const symbols = Object.getOwnPropertySymbols(obj);
|
|
560
|
+
for (const symbol of symbols) {
|
|
561
|
+
if (!skipKeys || !skipKeys.some((s) => s.toString() === symbol.toString())) {
|
|
562
|
+
clone[symbol] = deepClone(obj[symbol]);
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
return clone;
|
|
566
|
+
}
|
|
567
|
+
return obj;
|
|
568
|
+
};
|
|
569
|
+
|
|
570
|
+
// src/lib/helpers.ts
|
|
571
|
+
var import_primitive = require("@fluixi/utils/primitive");
|
|
572
|
+
var import_object2 = require("@fluixi/utils/object");
|
|
573
|
+
var import_array = require("@fluixi/utils/array");
|
|
574
|
+
var import_functions = require("@fluixi/utils/functions");
|
|
575
|
+
function isNull(v) {
|
|
576
|
+
return v === null;
|
|
577
|
+
}
|
|
578
|
+
function isUndefined(v) {
|
|
579
|
+
return v === void 0;
|
|
580
|
+
}
|
|
581
|
+
var isUndefinedOrNull = (element) => {
|
|
582
|
+
if (typeof element === "undefined" || element === null) return true;
|
|
583
|
+
return false;
|
|
584
|
+
};
|
|
585
|
+
function isPrimitive(v) {
|
|
586
|
+
const type = typeof v;
|
|
587
|
+
return v === null || type === "string" || type === "number" || type === "boolean" || type === "symbol" || type === "bigint" || type === "undefined" || (0, import_primitive.isDate)(v);
|
|
588
|
+
}
|
|
589
|
+
function isDefined(obj) {
|
|
590
|
+
return obj !== void 0 && obj !== null;
|
|
591
|
+
}
|
|
592
|
+
function getKind(obj) {
|
|
593
|
+
if (obj === null) return "null";
|
|
594
|
+
if (obj === void 0) return "undefined";
|
|
595
|
+
if ((0, import_primitive.isDate)(obj)) return "date";
|
|
596
|
+
if ((0, import_object2.isClass)(obj)) return "class";
|
|
597
|
+
if ((0, import_functions.isFunction)(obj)) return "function";
|
|
598
|
+
if ((0, import_array.isArray)(obj)) return "array";
|
|
599
|
+
if (isPrimitive(obj)) return "primitive";
|
|
600
|
+
if ((0, import_object2.isObject)(obj)) return "object";
|
|
601
|
+
return "primitive";
|
|
602
|
+
}
|
|
603
|
+
var generateUUID = () => {
|
|
604
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
|
605
|
+
let r = Math.random() * 16 | 0;
|
|
606
|
+
let v = c === "x" ? r : r & 3 | 8;
|
|
607
|
+
return v.toString(16);
|
|
608
|
+
});
|
|
609
|
+
};
|
|
610
|
+
var generateID = () => {
|
|
611
|
+
return "xxyxxxxxxy-4xx8".replace(/[xy]/g, function(c) {
|
|
612
|
+
let r = Math.random() * 16 | 0;
|
|
613
|
+
let v = c === "x" ? r : r & 3 | 8;
|
|
614
|
+
return v.toString(16);
|
|
615
|
+
});
|
|
616
|
+
};
|
|
617
|
+
|
|
618
|
+
// src/lib/object/selector.ts
|
|
619
|
+
var parseSelector = (selector, options = {}) => {
|
|
620
|
+
const { type = "auto", throwOnError = false } = options;
|
|
621
|
+
if (!selector || typeof selector !== "string") {
|
|
622
|
+
return [];
|
|
623
|
+
}
|
|
624
|
+
const segments = [];
|
|
625
|
+
let current = "";
|
|
626
|
+
let inBrackets = false;
|
|
627
|
+
let inQuotes = false;
|
|
628
|
+
let quoteChar = "";
|
|
629
|
+
let bracketContent = "";
|
|
630
|
+
let bracketDepth = 0;
|
|
631
|
+
const detectType = (str) => {
|
|
632
|
+
if (str.includes("..")) return "descendant";
|
|
633
|
+
if (str.includes("[?(")) return "filter";
|
|
634
|
+
if (str.includes("[:") || str.includes("[0:")) return "slice";
|
|
635
|
+
if (str.includes("[,") || str.includes("[0,1]")) return "union";
|
|
636
|
+
if (str.includes("[*]") || str.includes(".*.")) return "wildcard";
|
|
637
|
+
if (str.includes("[]")) return "array-wildcard";
|
|
638
|
+
if (str.includes("[") && str.includes("]")) return "bracket";
|
|
639
|
+
return "dot";
|
|
640
|
+
};
|
|
641
|
+
const actualType = type === "auto" ? detectType(selector) : type;
|
|
642
|
+
const parseBracketContent = (content) => {
|
|
643
|
+
const trimmed = content.trim();
|
|
644
|
+
if (trimmed === "*" || trimmed === "") {
|
|
645
|
+
return {
|
|
646
|
+
type: "wildcard",
|
|
647
|
+
value: trimmed === "" ? "[]" : "*",
|
|
648
|
+
raw: trimmed === "" ? "[]" : content
|
|
649
|
+
};
|
|
650
|
+
}
|
|
651
|
+
if (trimmed === "[]") {
|
|
652
|
+
return { type: "wildcard", value: "[]", raw: content };
|
|
653
|
+
}
|
|
654
|
+
if (/^-?\d+$/.test(trimmed)) {
|
|
655
|
+
return { type: "index", value: parseInt(trimmed, 10), raw: content };
|
|
656
|
+
}
|
|
657
|
+
if (trimmed.includes(":")) {
|
|
658
|
+
const parts = trimmed.split(":").map((p) => p.trim());
|
|
659
|
+
const start = parts[0] === "" ? 0 : parseInt(parts[0], 10);
|
|
660
|
+
const end = parts[1] === "" ? Infinity : parseInt(parts[1], 10);
|
|
661
|
+
if (isNaN(start) || isNaN(end)) {
|
|
662
|
+
if (throwOnError) throw new Error(`Invalid slice notation: ${content}`);
|
|
663
|
+
return { type: "wildcard", value: "*", raw: content };
|
|
664
|
+
}
|
|
665
|
+
return { type: "slice", value: [start, end], raw: content };
|
|
666
|
+
}
|
|
667
|
+
if (trimmed.includes(",")) {
|
|
668
|
+
const indices = trimmed.split(",").map((p) => {
|
|
669
|
+
const num = parseInt(p.trim(), 10);
|
|
670
|
+
return isNaN(num) ? -1 : num;
|
|
671
|
+
}).filter((n) => n >= 0);
|
|
672
|
+
if (indices.length === 0) {
|
|
673
|
+
if (throwOnError) throw new Error(`Invalid union notation: ${content}`);
|
|
674
|
+
return { type: "wildcard", value: "*", raw: content };
|
|
675
|
+
}
|
|
676
|
+
return { type: "union", value: indices, raw: content };
|
|
677
|
+
}
|
|
678
|
+
if (trimmed.startsWith("?(") && trimmed.endsWith(")")) {
|
|
679
|
+
const expr = trimmed.slice(2, -1);
|
|
680
|
+
try {
|
|
681
|
+
const filterFn = createFilterFunction(expr);
|
|
682
|
+
return { type: "filter", value: filterFn, raw: content };
|
|
683
|
+
} catch (error) {
|
|
684
|
+
if (throwOnError) throw error;
|
|
685
|
+
return { type: "wildcard", value: "*", raw: content };
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
if (trimmed.startsWith('"') && trimmed.endsWith('"') || trimmed.startsWith("'") && trimmed.endsWith("'")) {
|
|
689
|
+
return { type: "property", value: trimmed.slice(1, -1), raw: content };
|
|
690
|
+
}
|
|
691
|
+
return { type: "property", value: trimmed, raw: content };
|
|
692
|
+
};
|
|
693
|
+
for (let i = 0; i < selector.length; i++) {
|
|
694
|
+
const char = selector[i];
|
|
695
|
+
const nextChar = selector[i + 1];
|
|
696
|
+
if ((char === '"' || char === "'") && !inQuotes) {
|
|
697
|
+
inQuotes = true;
|
|
698
|
+
quoteChar = char;
|
|
699
|
+
continue;
|
|
700
|
+
} else if (char === quoteChar && inQuotes) {
|
|
701
|
+
inQuotes = false;
|
|
702
|
+
quoteChar = "";
|
|
703
|
+
if (!(char === '"' || char === "'")) {
|
|
704
|
+
if (inBrackets) {
|
|
705
|
+
bracketContent += char;
|
|
706
|
+
} else {
|
|
707
|
+
current += char;
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
continue;
|
|
711
|
+
}
|
|
712
|
+
if (inQuotes) {
|
|
713
|
+
if (inBrackets) {
|
|
714
|
+
bracketContent += char;
|
|
715
|
+
} else {
|
|
716
|
+
current += char;
|
|
717
|
+
}
|
|
718
|
+
continue;
|
|
719
|
+
}
|
|
720
|
+
if (char === "[" && !inBrackets) {
|
|
721
|
+
if (current) {
|
|
722
|
+
segments.push({ type: "property", value: current, raw: current });
|
|
723
|
+
current = "";
|
|
724
|
+
}
|
|
725
|
+
inBrackets = true;
|
|
726
|
+
bracketContent = "";
|
|
727
|
+
continue;
|
|
728
|
+
}
|
|
729
|
+
if (char === "]" && inBrackets && !inQuotes) {
|
|
730
|
+
inBrackets = false;
|
|
731
|
+
const segment2 = parseBracketContent(bracketContent);
|
|
732
|
+
segments.push(segment2);
|
|
733
|
+
continue;
|
|
734
|
+
}
|
|
735
|
+
let lastDot = segments.length > 0 ? segments[segments.length - 1] : null;
|
|
736
|
+
if (char === "." && !inBrackets && !inQuotes) {
|
|
737
|
+
if (nextChar === ".") {
|
|
738
|
+
const l = selector.split("..")[0];
|
|
739
|
+
segments.push({ type: "property", value: l, raw: l });
|
|
740
|
+
segments.push({ type: "descendant", value: "..", raw: ".." });
|
|
741
|
+
i++;
|
|
742
|
+
} else if (current) {
|
|
743
|
+
if (current === "*") {
|
|
744
|
+
segments.push({ type: "wildcard", value: current, raw: current });
|
|
745
|
+
} else {
|
|
746
|
+
segments.push({ type: "property", value: current, raw: current });
|
|
747
|
+
}
|
|
748
|
+
current = "";
|
|
749
|
+
}
|
|
750
|
+
continue;
|
|
751
|
+
}
|
|
752
|
+
if (inBrackets) {
|
|
753
|
+
bracketContent += char;
|
|
754
|
+
} else {
|
|
755
|
+
if (lastDot && lastDot.type !== "descendant") {
|
|
756
|
+
current += char;
|
|
757
|
+
} else {
|
|
758
|
+
const l = selector.split(lastDot?.raw)[1];
|
|
759
|
+
if (l !== void 0) {
|
|
760
|
+
current = l;
|
|
761
|
+
} else {
|
|
762
|
+
current += char;
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
if (current) {
|
|
768
|
+
segments.push({ type: "property", value: current, raw: current });
|
|
769
|
+
}
|
|
770
|
+
return segments.map((segment2) => {
|
|
771
|
+
if (segment2.type === "property" && typeof segment2.value === "string") {
|
|
772
|
+
if (/^-?\d+$/.test(segment2.value)) {
|
|
773
|
+
const num = parseInt(segment2.value, 10);
|
|
774
|
+
if (!isNaN(num)) {
|
|
775
|
+
return { ...segment2, type: "index", value: num };
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
return segment2;
|
|
780
|
+
});
|
|
781
|
+
};
|
|
782
|
+
var createFilterFunction = (expr) => {
|
|
783
|
+
const safeExpr = expr.replace(/@\.([a-zA-Z_$][\w$]*)/g, (_, prop) => `item.${prop}`).replace(/@/g, "item");
|
|
784
|
+
try {
|
|
785
|
+
return new Function("item", `return ${safeExpr}`);
|
|
786
|
+
} catch (error) {
|
|
787
|
+
throw new Error(`Invalid filter expression: ${expr}`);
|
|
788
|
+
}
|
|
789
|
+
};
|
|
790
|
+
|
|
791
|
+
// src/lib/object/merge.ts
|
|
792
|
+
var mergeIntoStructure = (target, selector, value) => {
|
|
793
|
+
const segments = parseSelector(selector);
|
|
794
|
+
let current = target;
|
|
795
|
+
for (let i = 0; i < segments.length; i++) {
|
|
796
|
+
const segment2 = segments[i];
|
|
797
|
+
const isLast = i === segments.length - 1;
|
|
798
|
+
switch (segment2.type) {
|
|
799
|
+
case "property":
|
|
800
|
+
if (isLast) {
|
|
801
|
+
current[String(segment2.value)] = value;
|
|
802
|
+
} else {
|
|
803
|
+
if (!current[String(segment2.value)]) {
|
|
804
|
+
const nextSegment = segments[i + 1];
|
|
805
|
+
current[String(segment2.value)] = nextSegment.type === "index" || nextSegment.type === "slice" || nextSegment.type === "union" || nextSegment.type === "wildcard" ? [] : {};
|
|
806
|
+
}
|
|
807
|
+
current = current[String(segment2.value)];
|
|
808
|
+
}
|
|
809
|
+
break;
|
|
810
|
+
case "index":
|
|
811
|
+
if (!Array.isArray(current)) {
|
|
812
|
+
current = [];
|
|
813
|
+
}
|
|
814
|
+
const index = segment2.value;
|
|
815
|
+
if (isLast) {
|
|
816
|
+
if (index >= current.length) {
|
|
817
|
+
for (let j = current.length; j <= index; j++) {
|
|
818
|
+
current.push(void 0);
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
current[index] = value;
|
|
822
|
+
} else {
|
|
823
|
+
if (!current[index]) {
|
|
824
|
+
const nextSegment = segments[i + 1];
|
|
825
|
+
current[index] = nextSegment.type === "index" || nextSegment.type === "slice" || nextSegment.type === "union" || nextSegment.type === "wildcard" ? [] : {};
|
|
826
|
+
}
|
|
827
|
+
current = current[index];
|
|
828
|
+
}
|
|
829
|
+
break;
|
|
830
|
+
case "wildcard":
|
|
831
|
+
if (Array.isArray(current)) {
|
|
832
|
+
if (isLast) {
|
|
833
|
+
for (let j = 0; j < current.length; j++) {
|
|
834
|
+
current[j] = value;
|
|
835
|
+
}
|
|
836
|
+
} else {
|
|
837
|
+
const nextSegment = segments[i + 1];
|
|
838
|
+
for (let j = 0; j < current.length; j++) {
|
|
839
|
+
if (!current[j]) {
|
|
840
|
+
current[j] = nextSegment.type === "index" || nextSegment.type === "slice" || nextSegment.type === "union" || nextSegment.type === "wildcard" ? [] : {};
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
if (current.length > 0) {
|
|
844
|
+
current = current[0];
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
break;
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
};
|
|
852
|
+
|
|
853
|
+
// src/lib/object/getter-setter.ts
|
|
854
|
+
function get(obj, selector, options = {}) {
|
|
855
|
+
const {
|
|
856
|
+
preserveStructure,
|
|
857
|
+
multiple,
|
|
858
|
+
throwOnError = false,
|
|
859
|
+
defaultValue,
|
|
860
|
+
maxDepth = 20
|
|
861
|
+
} = options;
|
|
862
|
+
if (!obj || typeof obj !== "object") {
|
|
863
|
+
return defaultValue;
|
|
864
|
+
}
|
|
865
|
+
if (!selector) {
|
|
866
|
+
return obj;
|
|
867
|
+
}
|
|
868
|
+
if (Array.isArray(selector)) {
|
|
869
|
+
if (preserveStructure) {
|
|
870
|
+
const result2 = {};
|
|
871
|
+
for (const sel of selector) {
|
|
872
|
+
const value = get(obj, sel, { ...options, preserveStructure: false });
|
|
873
|
+
if (value !== void 0) {
|
|
874
|
+
mergeIntoStructure(result2, sel, value);
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
return result2;
|
|
878
|
+
} else {
|
|
879
|
+
return selector.map(
|
|
880
|
+
(sel) => get(obj, sel, { ...options, preserveStructure: false })
|
|
881
|
+
);
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
const segments = parseSelector(selector, { ...options, throwOnError });
|
|
885
|
+
if (segments.length === 0) {
|
|
886
|
+
return obj;
|
|
887
|
+
}
|
|
888
|
+
if (typeof preserveStructure === "undefined" || preserveStructure === false) {
|
|
889
|
+
const v = ValueOfKey(obj, selector);
|
|
890
|
+
if (multiple === false && Array.isArray(v)) {
|
|
891
|
+
return v[0];
|
|
892
|
+
}
|
|
893
|
+
if (v === void 0 && defaultValue !== void 0) {
|
|
894
|
+
return defaultValue;
|
|
895
|
+
}
|
|
896
|
+
return v;
|
|
897
|
+
}
|
|
898
|
+
const result = traverseStructure(obj, segments, 0, maxDepth);
|
|
899
|
+
if (result === void 0 && defaultValue !== void 0) {
|
|
900
|
+
return defaultValue;
|
|
901
|
+
}
|
|
902
|
+
return result;
|
|
903
|
+
}
|
|
904
|
+
function ValueOfKey(obj, selector, options = {}) {
|
|
905
|
+
const { createMissing = false, add = false, debug = false } = options;
|
|
906
|
+
const segments = parseSelector(selector);
|
|
907
|
+
let current = obj;
|
|
908
|
+
let updateEvenIfNotlast = false;
|
|
909
|
+
let chained_property = "";
|
|
910
|
+
const stringify = selector;
|
|
911
|
+
if (typeof current === "object" && !Array.isArray(current) && stringify.length > 0) {
|
|
912
|
+
if (current[stringify]) {
|
|
913
|
+
current = current[stringify];
|
|
914
|
+
return current;
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
for (let i = 0; i < segments.length; i++) {
|
|
918
|
+
const segment2 = segments[i];
|
|
919
|
+
const isLast = segments.length > 1 ? i === segments.length - 1 : false;
|
|
920
|
+
if (current === null && !createMissing) {
|
|
921
|
+
return void 0;
|
|
922
|
+
}
|
|
923
|
+
const nextSegment = segments[i + 1];
|
|
924
|
+
switch (segment2.type) {
|
|
925
|
+
case "property":
|
|
926
|
+
if (current && typeof current === "object") {
|
|
927
|
+
if (Array.isArray(current)) {
|
|
928
|
+
if (typeof segment2.value === "number") {
|
|
929
|
+
const index = segment2.value;
|
|
930
|
+
if (createMissing && index >= current.length) {
|
|
931
|
+
for (let j = current.length; j <= index; j++) {
|
|
932
|
+
current.push(void 0);
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
if (createMissing && (current[index] === null || current[index] === void 0) && (!isLast || updateEvenIfNotlast)) {
|
|
936
|
+
if (nextSegment) {
|
|
937
|
+
current[index] = nextSegment.type === "index" || nextSegment.type === "slice" || nextSegment.type === "union" || nextSegment.type === "wildcard" ? [] : {};
|
|
938
|
+
} else {
|
|
939
|
+
current[index] = null;
|
|
940
|
+
}
|
|
941
|
+
updateEvenIfNotlast = false;
|
|
942
|
+
}
|
|
943
|
+
current = current[index];
|
|
944
|
+
if (nextSegment) {
|
|
945
|
+
updateEvenIfNotlast = true;
|
|
946
|
+
continue;
|
|
947
|
+
}
|
|
948
|
+
} else if (add) {
|
|
949
|
+
current.push({
|
|
950
|
+
[String(segment2.value)]: null
|
|
951
|
+
});
|
|
952
|
+
} else {
|
|
953
|
+
current = current.map((item) => item[String(segment2.value)]);
|
|
954
|
+
}
|
|
955
|
+
if (nextSegment) {
|
|
956
|
+
continue;
|
|
957
|
+
}
|
|
958
|
+
return filterDefined(current);
|
|
959
|
+
} else {
|
|
960
|
+
if (current[chained_property] && chained_property.split(".").length >= 2) {
|
|
961
|
+
current = current[chained_property];
|
|
962
|
+
continue;
|
|
963
|
+
}
|
|
964
|
+
if (createMissing && (current[String(segment2.value)] === null || current[String(segment2.value)] === void 0) && (!isLast || updateEvenIfNotlast)) {
|
|
965
|
+
if (nextSegment) {
|
|
966
|
+
current[String(segment2.value)] = nextSegment.type === "index" || nextSegment.type === "slice" || nextSegment.type === "union" || nextSegment.type === "wildcard" ? [] : {};
|
|
967
|
+
} else {
|
|
968
|
+
current[String(segment2.value)] = null;
|
|
969
|
+
}
|
|
970
|
+
updateEvenIfNotlast = false;
|
|
971
|
+
current = current[String(segment2.value)];
|
|
972
|
+
if (nextSegment) {
|
|
973
|
+
updateEvenIfNotlast = true;
|
|
974
|
+
continue;
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
if (!current) {
|
|
978
|
+
current = { [String(segment2.value)]: null };
|
|
979
|
+
} else {
|
|
980
|
+
if (!current[String(segment2.value)] && createMissing) {
|
|
981
|
+
current[String(segment2.value)] = null;
|
|
982
|
+
}
|
|
983
|
+
current = current[String(segment2.value)];
|
|
984
|
+
}
|
|
985
|
+
if (nextSegment) {
|
|
986
|
+
continue;
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
} else if (createMissing) {
|
|
990
|
+
current = {};
|
|
991
|
+
current[String(segment2.value)] = nextSegment.type === "index" || nextSegment.type === "slice" || nextSegment.type === "union" || nextSegment.type === "wildcard" || options.type === "array" ? [] : {};
|
|
992
|
+
current = current[String(segment2.value)];
|
|
993
|
+
} else {
|
|
994
|
+
return void 0;
|
|
995
|
+
}
|
|
996
|
+
break;
|
|
997
|
+
case "index":
|
|
998
|
+
case "wildcard":
|
|
999
|
+
if (Array.isArray(current)) {
|
|
1000
|
+
if (segment2.type === "index") {
|
|
1001
|
+
const index = segment2.value;
|
|
1002
|
+
if (index < 0) {
|
|
1003
|
+
current = current[current.length - Math.abs(index)];
|
|
1004
|
+
continue;
|
|
1005
|
+
}
|
|
1006
|
+
if (createMissing && (index >= current.length || current[index] == null || current[index] == void 0) && !isLast) {
|
|
1007
|
+
for (let j = current.length; j <= index; j++) {
|
|
1008
|
+
current.push(void 0);
|
|
1009
|
+
}
|
|
1010
|
+
if (nextSegment) {
|
|
1011
|
+
current[index] = nextSegment.type === "index" || nextSegment.type === "slice" || nextSegment.type === "union" || nextSegment.type === "wildcard" ? [] : {};
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
current = current[index];
|
|
1015
|
+
} else {
|
|
1016
|
+
if (!isLast) {
|
|
1017
|
+
continue;
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
} else if (createMissing) {
|
|
1021
|
+
const nextSegment2 = segments[i + 1];
|
|
1022
|
+
current = [];
|
|
1023
|
+
const index = segment2.value;
|
|
1024
|
+
for (let j = 0; j <= index; j++) {
|
|
1025
|
+
current.push(void 0);
|
|
1026
|
+
}
|
|
1027
|
+
current[index] = nextSegment2.type === "index" || nextSegment2.type === "slice" || nextSegment2.type === "union" || nextSegment2.type === "wildcard" || options.type === "array" ? [] : {};
|
|
1028
|
+
current = current[index];
|
|
1029
|
+
} else {
|
|
1030
|
+
if (segment2.type === "index" && typeof current === "object") {
|
|
1031
|
+
if (current && current[String(segment2.value)] !== void 0) {
|
|
1032
|
+
current = current[String(segment2.value)];
|
|
1033
|
+
continue;
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
if (typeof current === "object") {
|
|
1037
|
+
const values = Object.values(current);
|
|
1038
|
+
current = values;
|
|
1039
|
+
continue;
|
|
1040
|
+
}
|
|
1041
|
+
return void 0;
|
|
1042
|
+
}
|
|
1043
|
+
break;
|
|
1044
|
+
default:
|
|
1045
|
+
return void 0;
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
return filterDefined(current);
|
|
1049
|
+
}
|
|
1050
|
+
function filterDefined(obj) {
|
|
1051
|
+
if (Array.isArray(obj)) {
|
|
1052
|
+
return obj.filter((item) => typeof item !== "undefined");
|
|
1053
|
+
}
|
|
1054
|
+
return obj;
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1057
|
+
// src/lib/array/advanced.ts
|
|
1058
|
+
function chunk(array, size) {
|
|
1059
|
+
if (!Array.isArray(array) || size < 1) {
|
|
1060
|
+
return [];
|
|
1061
|
+
}
|
|
1062
|
+
const chunks = [];
|
|
1063
|
+
for (let i = 0; i < array.length; i += size) {
|
|
1064
|
+
chunks.push(array.slice(i, i + size));
|
|
1065
|
+
}
|
|
1066
|
+
return chunks;
|
|
1067
|
+
}
|
|
1068
|
+
function flatten(array) {
|
|
1069
|
+
return array.reduce((acc, val) => {
|
|
1070
|
+
return acc.concat(val);
|
|
1071
|
+
}, []);
|
|
1072
|
+
}
|
|
1073
|
+
function flattenDeep(array, depth = Infinity) {
|
|
1074
|
+
if (depth < 1) {
|
|
1075
|
+
return array.slice();
|
|
1076
|
+
}
|
|
1077
|
+
return array.reduce((acc, val) => {
|
|
1078
|
+
if (Array.isArray(val)) {
|
|
1079
|
+
acc.push(...flattenDeep(val, depth - 1));
|
|
1080
|
+
} else {
|
|
1081
|
+
acc.push(val);
|
|
1082
|
+
}
|
|
1083
|
+
return acc;
|
|
1084
|
+
}, []);
|
|
1085
|
+
}
|
|
1086
|
+
function unique(array, selector) {
|
|
1087
|
+
if (!Array.isArray(array)) {
|
|
1088
|
+
return [];
|
|
1089
|
+
}
|
|
1090
|
+
if (!selector) {
|
|
1091
|
+
return [...new Set(array)];
|
|
1092
|
+
}
|
|
1093
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1094
|
+
return array.filter((item) => {
|
|
1095
|
+
const value = typeof selector === "function" ? selector(item) : isObject2(item) ? get(item, selector) : item;
|
|
1096
|
+
if (seen.has(value)) {
|
|
1097
|
+
return false;
|
|
1098
|
+
}
|
|
1099
|
+
seen.add(value);
|
|
1100
|
+
return true;
|
|
1101
|
+
});
|
|
1102
|
+
}
|
|
1103
|
+
function groupBy(array, keyOrFn) {
|
|
1104
|
+
if (!Array.isArray(array)) {
|
|
1105
|
+
return {};
|
|
1106
|
+
}
|
|
1107
|
+
return array.reduce((acc, item) => {
|
|
1108
|
+
let key;
|
|
1109
|
+
if (typeof keyOrFn === "function") {
|
|
1110
|
+
key = String(keyOrFn(item));
|
|
1111
|
+
} else {
|
|
1112
|
+
key = String(isObject2(item) ? get(item, keyOrFn) : item);
|
|
1113
|
+
}
|
|
1114
|
+
if (!acc[key]) {
|
|
1115
|
+
acc[key] = [];
|
|
1116
|
+
}
|
|
1117
|
+
acc[key].push(item);
|
|
1118
|
+
return acc;
|
|
1119
|
+
}, {});
|
|
1120
|
+
}
|
|
1121
|
+
function countBy(array, key) {
|
|
1122
|
+
if (!Array.isArray(array)) {
|
|
1123
|
+
return {};
|
|
1124
|
+
}
|
|
1125
|
+
return array.reduce((acc, item) => {
|
|
1126
|
+
let countKey;
|
|
1127
|
+
if (typeof key === "function") {
|
|
1128
|
+
countKey = String(key(item));
|
|
1129
|
+
} else if (key) {
|
|
1130
|
+
countKey = String(
|
|
1131
|
+
isObject2(item) ? get(item, key) : item
|
|
1132
|
+
);
|
|
1133
|
+
} else {
|
|
1134
|
+
countKey = String(item);
|
|
1135
|
+
}
|
|
1136
|
+
acc[countKey] = (acc[countKey] || 0) + 1;
|
|
1137
|
+
return acc;
|
|
1138
|
+
}, {});
|
|
1139
|
+
}
|
|
1140
|
+
function keyBy(array, keyFn, valueFn) {
|
|
1141
|
+
if (!Array.isArray(array)) {
|
|
1142
|
+
return {};
|
|
1143
|
+
}
|
|
1144
|
+
return array.reduce((acc, item) => {
|
|
1145
|
+
let key;
|
|
1146
|
+
if (typeof keyFn === "function") {
|
|
1147
|
+
key = String(keyFn(item));
|
|
1148
|
+
} else {
|
|
1149
|
+
key = String(isObject2(item) ? get(item, keyFn) : item);
|
|
1150
|
+
}
|
|
1151
|
+
let value;
|
|
1152
|
+
if (valueFn) {
|
|
1153
|
+
if (typeof valueFn === "function") {
|
|
1154
|
+
value = valueFn(item);
|
|
1155
|
+
} else {
|
|
1156
|
+
value = get(item, valueFn);
|
|
1157
|
+
}
|
|
1158
|
+
} else {
|
|
1159
|
+
value = item;
|
|
1160
|
+
}
|
|
1161
|
+
acc[key] = value;
|
|
1162
|
+
return acc;
|
|
1163
|
+
}, {});
|
|
1164
|
+
}
|
|
1165
|
+
function sortBy(array, keys) {
|
|
1166
|
+
if (!Array.isArray(array) || array.length === 0) {
|
|
1167
|
+
return [];
|
|
1168
|
+
}
|
|
1169
|
+
const sorted = [...array];
|
|
1170
|
+
const keysArray = Array.isArray(keys) ? keys : [keys];
|
|
1171
|
+
const normalizedKeys = keysArray.map((k) => {
|
|
1172
|
+
if (typeof k === "object" && "key" in k) {
|
|
1173
|
+
return { key: k.key, dir: k.dir || "asc" };
|
|
1174
|
+
}
|
|
1175
|
+
return { key: k, dir: "asc" };
|
|
1176
|
+
});
|
|
1177
|
+
sorted.sort((a, b) => {
|
|
1178
|
+
for (const { key, dir } of normalizedKeys) {
|
|
1179
|
+
const aVal = isObject2(a) ? get(a, key) : a;
|
|
1180
|
+
const bVal = isObject2(b) ? get(b, key) : b;
|
|
1181
|
+
if (aVal === bVal) continue;
|
|
1182
|
+
const comparison = aVal < bVal ? -1 : 1;
|
|
1183
|
+
return dir === "asc" ? comparison : -comparison;
|
|
1184
|
+
}
|
|
1185
|
+
return 0;
|
|
1186
|
+
});
|
|
1187
|
+
return sorted;
|
|
1188
|
+
}
|
|
1189
|
+
function difference(array1, array2, key) {
|
|
1190
|
+
if (!Array.isArray(array1)) return [];
|
|
1191
|
+
if (!Array.isArray(array2)) return array1;
|
|
1192
|
+
if (!key) {
|
|
1193
|
+
const set2 = new Set(array2);
|
|
1194
|
+
return array1.filter((item) => !set2.has(item));
|
|
1195
|
+
}
|
|
1196
|
+
const values2 = new Set(
|
|
1197
|
+
array2.map(
|
|
1198
|
+
(item) => isObject2(item) ? get(item, key) : item
|
|
1199
|
+
)
|
|
1200
|
+
);
|
|
1201
|
+
return array1.filter((item) => {
|
|
1202
|
+
const value = isObject2(item) ? get(item, key) : item;
|
|
1203
|
+
return !values2.has(value);
|
|
1204
|
+
});
|
|
1205
|
+
}
|
|
1206
|
+
function intersection(array1, array2, key) {
|
|
1207
|
+
if (!Array.isArray(array1) || !Array.isArray(array2)) {
|
|
1208
|
+
return [];
|
|
1209
|
+
}
|
|
1210
|
+
if (!key) {
|
|
1211
|
+
const set2 = new Set(array2);
|
|
1212
|
+
return array1.filter((item) => set2.has(item));
|
|
1213
|
+
}
|
|
1214
|
+
const values2 = new Set(
|
|
1215
|
+
array2.map(
|
|
1216
|
+
(item) => isObject2(item) ? get(item, key) : item
|
|
1217
|
+
)
|
|
1218
|
+
);
|
|
1219
|
+
return array1.filter((item) => {
|
|
1220
|
+
const value = isObject2(item) ? get(item, key) : item;
|
|
1221
|
+
return values2.has(value);
|
|
1222
|
+
});
|
|
1223
|
+
}
|
|
1224
|
+
function union(array1, array2, key) {
|
|
1225
|
+
if (!Array.isArray(array1) && !Array.isArray(array2)) {
|
|
1226
|
+
return [];
|
|
1227
|
+
}
|
|
1228
|
+
if (!Array.isArray(array1)) return unique(array2, key);
|
|
1229
|
+
if (!Array.isArray(array2)) return unique(array1, key);
|
|
1230
|
+
return unique([...array1, ...array2], key);
|
|
1231
|
+
}
|
|
1232
|
+
function partition(array, predicate) {
|
|
1233
|
+
if (!Array.isArray(array)) {
|
|
1234
|
+
return [[], []];
|
|
1235
|
+
}
|
|
1236
|
+
return array.reduce(
|
|
1237
|
+
(acc, item, index) => {
|
|
1238
|
+
acc[predicate(item, index) ? 0 : 1].push(item);
|
|
1239
|
+
return acc;
|
|
1240
|
+
},
|
|
1241
|
+
[[], []]
|
|
1242
|
+
);
|
|
1243
|
+
}
|
|
1244
|
+
function take(array, n) {
|
|
1245
|
+
if (!Array.isArray(array) || n <= 0) {
|
|
1246
|
+
return [];
|
|
1247
|
+
}
|
|
1248
|
+
return array.slice(0, n);
|
|
1249
|
+
}
|
|
1250
|
+
function takeLast(array, n) {
|
|
1251
|
+
if (!Array.isArray(array) || n <= 0) {
|
|
1252
|
+
return [];
|
|
1253
|
+
}
|
|
1254
|
+
return array.slice(-n);
|
|
1255
|
+
}
|
|
1256
|
+
function takeWhile(array, predicate) {
|
|
1257
|
+
if (!Array.isArray(array)) {
|
|
1258
|
+
return [];
|
|
1259
|
+
}
|
|
1260
|
+
const result = [];
|
|
1261
|
+
for (let i = 0; i < array.length; i++) {
|
|
1262
|
+
if (!predicate(array[i], i)) break;
|
|
1263
|
+
result.push(array[i]);
|
|
1264
|
+
}
|
|
1265
|
+
return result;
|
|
1266
|
+
}
|
|
1267
|
+
function drop(array, n) {
|
|
1268
|
+
if (!Array.isArray(array) || n <= 0) {
|
|
1269
|
+
return array ? [...array] : [];
|
|
1270
|
+
}
|
|
1271
|
+
return array.slice(n);
|
|
1272
|
+
}
|
|
1273
|
+
function dropWhile(array, predicate) {
|
|
1274
|
+
if (!Array.isArray(array)) {
|
|
1275
|
+
return [];
|
|
1276
|
+
}
|
|
1277
|
+
let index = 0;
|
|
1278
|
+
while (index < array.length && predicate(array[index], index)) {
|
|
1279
|
+
index++;
|
|
1280
|
+
}
|
|
1281
|
+
return array.slice(index);
|
|
1282
|
+
}
|
|
1283
|
+
function compact(array) {
|
|
1284
|
+
if (!Array.isArray(array)) {
|
|
1285
|
+
return [];
|
|
1286
|
+
}
|
|
1287
|
+
return array.filter(Boolean);
|
|
1288
|
+
}
|
|
1289
|
+
function zip(...arrays) {
|
|
1290
|
+
if (arrays.length === 0) return [];
|
|
1291
|
+
const maxLength = Math.max(
|
|
1292
|
+
...arrays.map((arr) => Array.isArray(arr) ? arr.length : 0)
|
|
1293
|
+
);
|
|
1294
|
+
const result = [];
|
|
1295
|
+
for (let i = 0; i < maxLength; i++) {
|
|
1296
|
+
const tuple = [];
|
|
1297
|
+
for (const array of arrays) {
|
|
1298
|
+
tuple.push(Array.isArray(array) ? array[i] : void 0);
|
|
1299
|
+
}
|
|
1300
|
+
result.push(tuple);
|
|
1301
|
+
}
|
|
1302
|
+
return result;
|
|
1303
|
+
}
|
|
1304
|
+
function unzip(array) {
|
|
1305
|
+
if (!Array.isArray(array) || array.length === 0) {
|
|
1306
|
+
return [];
|
|
1307
|
+
}
|
|
1308
|
+
const maxLength = Math.max(
|
|
1309
|
+
...array.map((arr) => Array.isArray(arr) ? arr.length : 0)
|
|
1310
|
+
);
|
|
1311
|
+
const result = [];
|
|
1312
|
+
for (let i = 0; i < maxLength; i++) {
|
|
1313
|
+
const tuple = [];
|
|
1314
|
+
for (const arr of array) {
|
|
1315
|
+
if (Array.isArray(arr)) {
|
|
1316
|
+
tuple.push(arr[i]);
|
|
1317
|
+
}
|
|
1318
|
+
}
|
|
1319
|
+
result.push(tuple);
|
|
1320
|
+
}
|
|
1321
|
+
return result;
|
|
1322
|
+
}
|
|
1323
|
+
function shuffle(array) {
|
|
1324
|
+
if (!Array.isArray(array)) {
|
|
1325
|
+
return [];
|
|
1326
|
+
}
|
|
1327
|
+
const result = [...array];
|
|
1328
|
+
for (let i = result.length - 1; i > 0; i--) {
|
|
1329
|
+
const j = Math.floor(Math.random() * (i + 1));
|
|
1330
|
+
[result[i], result[j]] = [result[j], result[i]];
|
|
1331
|
+
}
|
|
1332
|
+
return result;
|
|
1333
|
+
}
|
|
1334
|
+
function sample(array) {
|
|
1335
|
+
if (!Array.isArray(array) || array.length === 0) {
|
|
1336
|
+
return void 0;
|
|
1337
|
+
}
|
|
1338
|
+
return array[Math.floor(Math.random() * array.length)];
|
|
1339
|
+
}
|
|
1340
|
+
function sampleSize(array, n) {
|
|
1341
|
+
if (!Array.isArray(array) || n <= 0) {
|
|
1342
|
+
return [];
|
|
1343
|
+
}
|
|
1344
|
+
const shuffled = shuffle(array);
|
|
1345
|
+
return shuffled.slice(0, Math.min(n, array.length));
|
|
1346
|
+
}
|
|
1347
|
+
function findIndex(array, predicate, fromIndex = 0) {
|
|
1348
|
+
if (!Array.isArray(array)) {
|
|
1349
|
+
return -1;
|
|
1350
|
+
}
|
|
1351
|
+
for (let i = fromIndex; i < array.length; i++) {
|
|
1352
|
+
if (predicate(array[i], i)) {
|
|
1353
|
+
return i;
|
|
1354
|
+
}
|
|
1355
|
+
}
|
|
1356
|
+
return -1;
|
|
1357
|
+
}
|
|
1358
|
+
function findLastIndex(array, predicate, fromIndex) {
|
|
1359
|
+
if (!Array.isArray(array)) {
|
|
1360
|
+
return -1;
|
|
1361
|
+
}
|
|
1362
|
+
const startIndex = fromIndex !== void 0 ? fromIndex : array.length - 1;
|
|
1363
|
+
for (let i = startIndex; i >= 0; i--) {
|
|
1364
|
+
if (predicate(array[i], i)) {
|
|
1365
|
+
return i;
|
|
1366
|
+
}
|
|
1367
|
+
}
|
|
1368
|
+
return -1;
|
|
1369
|
+
}
|
|
1370
|
+
function pluck(array, path) {
|
|
1371
|
+
if (!Array.isArray(array)) {
|
|
1372
|
+
return [];
|
|
1373
|
+
}
|
|
1374
|
+
return array.map((item) => get(item, path));
|
|
1375
|
+
}
|
|
1376
|
+
function pick(array, keys) {
|
|
1377
|
+
if (!Array.isArray(array) || !Array.isArray(keys)) {
|
|
1378
|
+
return [];
|
|
1379
|
+
}
|
|
1380
|
+
return array.map((item) => {
|
|
1381
|
+
const result = {};
|
|
1382
|
+
for (const key of keys) {
|
|
1383
|
+
if (key in item) {
|
|
1384
|
+
result[key] = item[key];
|
|
1385
|
+
}
|
|
1386
|
+
}
|
|
1387
|
+
return result;
|
|
1388
|
+
});
|
|
1389
|
+
}
|
|
1390
|
+
function omit(array, keys) {
|
|
1391
|
+
if (!Array.isArray(array) || !Array.isArray(keys)) {
|
|
1392
|
+
return [];
|
|
1393
|
+
}
|
|
1394
|
+
return array.map((item) => {
|
|
1395
|
+
const result = { ...item };
|
|
1396
|
+
for (const key of keys) {
|
|
1397
|
+
delete result[key];
|
|
1398
|
+
}
|
|
1399
|
+
return result;
|
|
1400
|
+
});
|
|
1401
|
+
}
|
|
1402
|
+
function flatMap(array, callback) {
|
|
1403
|
+
if (!Array.isArray(array)) {
|
|
1404
|
+
return [];
|
|
1405
|
+
}
|
|
1406
|
+
return array.reduce((acc, item, index) => {
|
|
1407
|
+
const result = callback(item, index);
|
|
1408
|
+
return acc.concat(result);
|
|
1409
|
+
}, []);
|
|
1410
|
+
}
|
|
1411
|
+
function reduceRight(array, callback, initialValue) {
|
|
1412
|
+
if (!Array.isArray(array)) {
|
|
1413
|
+
return initialValue;
|
|
1414
|
+
}
|
|
1415
|
+
let accumulator = initialValue;
|
|
1416
|
+
for (let i = array.length - 1; i >= 0; i--) {
|
|
1417
|
+
accumulator = callback(accumulator, array[i], i);
|
|
1418
|
+
}
|
|
1419
|
+
return accumulator;
|
|
1420
|
+
}
|
|
1421
|
+
function range(start, end, step = 1) {
|
|
1422
|
+
if (step === 0) {
|
|
1423
|
+
return [];
|
|
1424
|
+
}
|
|
1425
|
+
const result = [];
|
|
1426
|
+
if (step > 0) {
|
|
1427
|
+
for (let i = start; i < end; i += step) {
|
|
1428
|
+
result.push(i);
|
|
1429
|
+
}
|
|
1430
|
+
} else {
|
|
1431
|
+
for (let i = start; i > end; i += step) {
|
|
1432
|
+
result.push(i);
|
|
1433
|
+
}
|
|
1434
|
+
}
|
|
1435
|
+
return result;
|
|
1436
|
+
}
|
|
1437
|
+
function fill(array, value, start = 0, end) {
|
|
1438
|
+
if (!Array.isArray(array)) {
|
|
1439
|
+
return [];
|
|
1440
|
+
}
|
|
1441
|
+
const result = [...array];
|
|
1442
|
+
const actualEnd = end === void 0 ? result.length : end;
|
|
1443
|
+
for (let i = start; i < actualEnd && i < result.length; i++) {
|
|
1444
|
+
result[i] = value;
|
|
1445
|
+
}
|
|
1446
|
+
return result;
|
|
1447
|
+
}
|
|
1448
|
+
function deepCloneArray(array) {
|
|
1449
|
+
if (!Array.isArray(array)) {
|
|
1450
|
+
return [];
|
|
1451
|
+
}
|
|
1452
|
+
return deepClone(array);
|
|
1453
|
+
}
|
|
1454
|
+
function mergeByKey(arr1, arr2, ...keyOrMore) {
|
|
1455
|
+
let key;
|
|
1456
|
+
let arrays;
|
|
1457
|
+
if (typeof arr2 === "string") {
|
|
1458
|
+
key = arr2;
|
|
1459
|
+
arrays = [arr1];
|
|
1460
|
+
} else {
|
|
1461
|
+
const lastArg = keyOrMore[keyOrMore.length - 1];
|
|
1462
|
+
if (typeof lastArg === "string") {
|
|
1463
|
+
key = lastArg;
|
|
1464
|
+
arrays = [
|
|
1465
|
+
arr1,
|
|
1466
|
+
arr2,
|
|
1467
|
+
...keyOrMore.slice(0, -1).filter(Array.isArray)
|
|
1468
|
+
];
|
|
1469
|
+
} else {
|
|
1470
|
+
key = "id";
|
|
1471
|
+
arrays = [arr1, arr2, ...keyOrMore.filter(Array.isArray)];
|
|
1472
|
+
}
|
|
1473
|
+
}
|
|
1474
|
+
if (arrays.length === 0) {
|
|
1475
|
+
return [];
|
|
1476
|
+
}
|
|
1477
|
+
const map = /* @__PURE__ */ new Map();
|
|
1478
|
+
for (const array of arrays) {
|
|
1479
|
+
if (Array.isArray(array)) {
|
|
1480
|
+
for (const item of array) {
|
|
1481
|
+
const keyValue = isObject2(item) ? get(item, key) : void 0;
|
|
1482
|
+
if (keyValue !== void 0) {
|
|
1483
|
+
const existing = map.get(keyValue);
|
|
1484
|
+
map.set(keyValue, existing ? { ...existing, ...item } : item);
|
|
1485
|
+
}
|
|
1486
|
+
}
|
|
1487
|
+
}
|
|
1488
|
+
}
|
|
1489
|
+
return Array.from(map.values());
|
|
1490
|
+
}
|
|
1491
|
+
function move(array, fromIndex, toIndex) {
|
|
1492
|
+
if (!Array.isArray(array) || fromIndex === toIndex) {
|
|
1493
|
+
return array ? [...array] : [];
|
|
1494
|
+
}
|
|
1495
|
+
const result = [...array];
|
|
1496
|
+
const [removed] = result.splice(fromIndex, 1);
|
|
1497
|
+
result.splice(toIndex, 0, removed);
|
|
1498
|
+
return result;
|
|
1499
|
+
}
|
|
1500
|
+
function rotate(array, n) {
|
|
1501
|
+
if (!Array.isArray(array) || array.length === 0 || n === 0) {
|
|
1502
|
+
return array ? [...array] : [];
|
|
1503
|
+
}
|
|
1504
|
+
const len = array.length;
|
|
1505
|
+
const rotations = (n % len + len) % len;
|
|
1506
|
+
return [...array.slice(-rotations), ...array.slice(0, -rotations)];
|
|
1507
|
+
}
|
|
1508
|
+
function insert(array, index, ...items) {
|
|
1509
|
+
if (!Array.isArray(array)) {
|
|
1510
|
+
return items;
|
|
1511
|
+
}
|
|
1512
|
+
const result = [...array];
|
|
1513
|
+
result.splice(index, 0, ...items);
|
|
1514
|
+
return result;
|
|
1515
|
+
}
|
|
1516
|
+
function remove(array, index, count = 1) {
|
|
1517
|
+
if (!Array.isArray(array)) {
|
|
1518
|
+
return [];
|
|
1519
|
+
}
|
|
1520
|
+
const result = [...array];
|
|
1521
|
+
result.splice(index, count);
|
|
1522
|
+
return result;
|
|
1523
|
+
}
|
|
1524
|
+
function replace(array, index, item) {
|
|
1525
|
+
if (!Array.isArray(array)) {
|
|
1526
|
+
return [];
|
|
1527
|
+
}
|
|
1528
|
+
const result = [...array];
|
|
1529
|
+
result[index] = item;
|
|
1530
|
+
return result;
|
|
1531
|
+
}
|
|
1532
|
+
function filterCompact(array, predicate) {
|
|
1533
|
+
if (!Array.isArray(array)) {
|
|
1534
|
+
return [];
|
|
1535
|
+
}
|
|
1536
|
+
const filtered = array.filter((item) => item != null);
|
|
1537
|
+
return predicate ? filtered.filter(predicate) : filtered;
|
|
1538
|
+
}
|
|
1539
|
+
function cartesian(...arrays) {
|
|
1540
|
+
if (arrays.length === 0) return [[]];
|
|
1541
|
+
if (arrays.length === 1) return arrays[0].map((item) => [item]);
|
|
1542
|
+
return arrays.reduce(
|
|
1543
|
+
(acc, array) => {
|
|
1544
|
+
return acc.flatMap((x) => array.map((y) => [...x, y]));
|
|
1545
|
+
},
|
|
1546
|
+
[[]]
|
|
1547
|
+
);
|
|
1548
|
+
}
|
|
1549
|
+
function findAllIndices(array, predicate) {
|
|
1550
|
+
if (!Array.isArray(array)) {
|
|
1551
|
+
return [];
|
|
1552
|
+
}
|
|
1553
|
+
const indices = [];
|
|
1554
|
+
for (let i = 0; i < array.length; i++) {
|
|
1555
|
+
if (predicate(array[i], i)) {
|
|
1556
|
+
indices.push(i);
|
|
1557
|
+
}
|
|
1558
|
+
}
|
|
1559
|
+
return indices;
|
|
1560
|
+
}
|
|
1561
|
+
function isEqual(array1, array2, deep = true) {
|
|
1562
|
+
if (!Array.isArray(array1) || !Array.isArray(array2)) {
|
|
1563
|
+
return false;
|
|
1564
|
+
}
|
|
1565
|
+
if (array1.length !== array2.length) {
|
|
1566
|
+
return false;
|
|
1567
|
+
}
|
|
1568
|
+
for (let i = 0; i < array1.length; i++) {
|
|
1569
|
+
if (deep && isObject2(array1[i]) && isObject2(array2[i])) {
|
|
1570
|
+
if (JSON.stringify(array1[i]) !== JSON.stringify(array2[i])) {
|
|
1571
|
+
return false;
|
|
1572
|
+
}
|
|
1573
|
+
} else if (array1[i] !== array2[i]) {
|
|
1574
|
+
return false;
|
|
1575
|
+
}
|
|
1576
|
+
}
|
|
1577
|
+
return true;
|
|
1578
|
+
}
|
|
1579
|
+
function chunkBy(array, predicate) {
|
|
1580
|
+
if (!Array.isArray(array) || array.length === 0) {
|
|
1581
|
+
return [];
|
|
1582
|
+
}
|
|
1583
|
+
const result = [];
|
|
1584
|
+
let currentChunk = [array[0]];
|
|
1585
|
+
let currentKey = predicate(array[0], 0);
|
|
1586
|
+
for (let i = 1; i < array.length; i++) {
|
|
1587
|
+
const key = predicate(array[i], i);
|
|
1588
|
+
if (key === currentKey) {
|
|
1589
|
+
currentChunk.push(array[i]);
|
|
1590
|
+
} else {
|
|
1591
|
+
result.push(currentChunk);
|
|
1592
|
+
currentChunk = [array[i]];
|
|
1593
|
+
currentKey = key;
|
|
1594
|
+
}
|
|
1595
|
+
}
|
|
1596
|
+
result.push(currentChunk);
|
|
1597
|
+
return result;
|
|
1598
|
+
}
|
|
1599
|
+
function updateBy(array, predicate, updates, updatesOrUndefined) {
|
|
1600
|
+
if (!Array.isArray(array)) {
|
|
1601
|
+
return [];
|
|
1602
|
+
}
|
|
1603
|
+
const isPredicate = typeof predicate === "function";
|
|
1604
|
+
const actualUpdates = isPredicate ? updates : updatesOrUndefined;
|
|
1605
|
+
return array.map((item) => {
|
|
1606
|
+
let shouldUpdate = false;
|
|
1607
|
+
if (isPredicate) {
|
|
1608
|
+
shouldUpdate = predicate(item);
|
|
1609
|
+
} else {
|
|
1610
|
+
const itemValue = isObject2(item) ? get(item, predicate) : item;
|
|
1611
|
+
shouldUpdate = itemValue === updates;
|
|
1612
|
+
}
|
|
1613
|
+
if (shouldUpdate) {
|
|
1614
|
+
return { ...item, ...actualUpdates };
|
|
1615
|
+
}
|
|
1616
|
+
return item;
|
|
1617
|
+
});
|
|
1618
|
+
}
|
|
1619
|
+
function splitDuplicates(array, key) {
|
|
1620
|
+
if (!Array.isArray(array)) {
|
|
1621
|
+
return { unique: [], duplicates: [] };
|
|
1622
|
+
}
|
|
1623
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1624
|
+
const unique2 = [];
|
|
1625
|
+
const duplicates = [];
|
|
1626
|
+
for (const item of array) {
|
|
1627
|
+
const value = key && isObject2(item) ? get(item, key) : item;
|
|
1628
|
+
if (seen.has(value)) {
|
|
1629
|
+
duplicates.push(item);
|
|
1630
|
+
} else {
|
|
1631
|
+
seen.add(value);
|
|
1632
|
+
unique2.push(item);
|
|
1633
|
+
}
|
|
1634
|
+
}
|
|
1635
|
+
return { unique: unique2, duplicates };
|
|
1636
|
+
}
|
|
1637
|
+
function ensureArray(value) {
|
|
1638
|
+
if (Array.isArray(value)) {
|
|
1639
|
+
return value;
|
|
1640
|
+
}
|
|
1641
|
+
return value === void 0 || value === null ? [] : [value];
|
|
1642
|
+
}
|
|
1643
|
+
function wrap(value) {
|
|
1644
|
+
return ensureArray(value);
|
|
1645
|
+
}
|
|
1646
|
+
function slidingWindow(array, size, step = 1) {
|
|
1647
|
+
if (!Array.isArray(array) || size < 1 || step < 1) {
|
|
1648
|
+
return [];
|
|
1649
|
+
}
|
|
1650
|
+
const windows = [];
|
|
1651
|
+
for (let i = 0; i <= array.length - size; i += step) {
|
|
1652
|
+
windows.push(array.slice(i, i + size));
|
|
1653
|
+
}
|
|
1654
|
+
return windows;
|
|
1655
|
+
}
|
|
1656
|
+
function minBy(array, selector) {
|
|
1657
|
+
if (!Array.isArray(array) || array.length === 0) {
|
|
1658
|
+
return void 0;
|
|
1659
|
+
}
|
|
1660
|
+
let minItem = array[0];
|
|
1661
|
+
let minValue = typeof selector === "function" ? selector(minItem) : get(minItem, selector);
|
|
1662
|
+
for (let i = 1; i < array.length; i++) {
|
|
1663
|
+
const item = array[i];
|
|
1664
|
+
const value = typeof selector === "function" ? selector(item) : get(item, selector);
|
|
1665
|
+
if (value < minValue) {
|
|
1666
|
+
minValue = value;
|
|
1667
|
+
minItem = item;
|
|
1668
|
+
}
|
|
1669
|
+
}
|
|
1670
|
+
return minItem;
|
|
1671
|
+
}
|
|
1672
|
+
function maxBy(array, selector) {
|
|
1673
|
+
if (!Array.isArray(array) || array.length === 0) {
|
|
1674
|
+
return void 0;
|
|
1675
|
+
}
|
|
1676
|
+
let maxItem = array[0];
|
|
1677
|
+
let maxValue = typeof selector === "function" ? selector(maxItem) : get(maxItem, selector);
|
|
1678
|
+
for (let i = 1; i < array.length; i++) {
|
|
1679
|
+
const item = array[i];
|
|
1680
|
+
const value = typeof selector === "function" ? selector(item) : get(item, selector);
|
|
1681
|
+
if (value > maxValue) {
|
|
1682
|
+
maxValue = value;
|
|
1683
|
+
maxItem = item;
|
|
1684
|
+
}
|
|
1685
|
+
}
|
|
1686
|
+
return maxItem;
|
|
1687
|
+
}
|
|
1688
|
+
function sumBy(array, selector) {
|
|
1689
|
+
if (!Array.isArray(array) || array.length === 0) {
|
|
1690
|
+
return 0;
|
|
1691
|
+
}
|
|
1692
|
+
let sum = 0;
|
|
1693
|
+
for (const item of array) {
|
|
1694
|
+
const value = typeof selector === "function" ? selector(item) : get(item, selector);
|
|
1695
|
+
if (typeof value === "number" && !isNaN(value)) {
|
|
1696
|
+
sum += value;
|
|
1697
|
+
}
|
|
1698
|
+
}
|
|
1699
|
+
return sum;
|
|
1700
|
+
}
|
|
1701
|
+
function avgBy(array, selector) {
|
|
1702
|
+
if (!Array.isArray(array) || array.length === 0) {
|
|
1703
|
+
return 0;
|
|
1704
|
+
}
|
|
1705
|
+
const sum = sumBy(array, selector);
|
|
1706
|
+
return sum / array.length;
|
|
1707
|
+
}
|
|
1708
|
+
function frequencies(array) {
|
|
1709
|
+
const freqMap = /* @__PURE__ */ new Map();
|
|
1710
|
+
if (!Array.isArray(array)) {
|
|
1711
|
+
return freqMap;
|
|
1712
|
+
}
|
|
1713
|
+
for (const item of array) {
|
|
1714
|
+
freqMap.set(item, (freqMap.get(item) || 0) + 1);
|
|
1715
|
+
}
|
|
1716
|
+
return freqMap;
|
|
1717
|
+
}
|
|
1718
|
+
function mostCommon(array, limit = 1) {
|
|
1719
|
+
if (!Array.isArray(array) || array.length === 0 || limit < 1) {
|
|
1720
|
+
return [];
|
|
1721
|
+
}
|
|
1722
|
+
const freqMap = frequencies(array);
|
|
1723
|
+
const sorted = Array.from(freqMap.entries()).sort((a, b) => b[1] - a[1]);
|
|
1724
|
+
return sorted.slice(0, limit).map(([value]) => value);
|
|
1725
|
+
}
|
|
1726
|
+
function leastCommon(array, limit = 1) {
|
|
1727
|
+
if (!Array.isArray(array) || array.length === 0 || limit < 1) {
|
|
1728
|
+
return [];
|
|
1729
|
+
}
|
|
1730
|
+
const freqMap = frequencies(array);
|
|
1731
|
+
const sorted = Array.from(freqMap.entries()).sort((a, b) => a[1] - b[1]);
|
|
1732
|
+
return sorted.slice(0, limit).map(([value]) => value);
|
|
1733
|
+
}
|
|
1734
|
+
async function batchProcess(array, batchSize, callback) {
|
|
1735
|
+
if (!Array.isArray(array) || batchSize < 1) {
|
|
1736
|
+
return;
|
|
1737
|
+
}
|
|
1738
|
+
const batches = chunk(array, batchSize);
|
|
1739
|
+
for (let i = 0; i < batches.length; i++) {
|
|
1740
|
+
await callback(batches[i], i);
|
|
1741
|
+
}
|
|
1742
|
+
}
|
|
1743
|
+
async function batchProcessParallel(array, batchSize, concurrency, callback) {
|
|
1744
|
+
if (!Array.isArray(array) || batchSize < 1 || concurrency < 1) {
|
|
1745
|
+
return;
|
|
1746
|
+
}
|
|
1747
|
+
const batches = chunk(array, batchSize);
|
|
1748
|
+
const batchChunks = chunk(
|
|
1749
|
+
batches.map((batch2, index) => ({ batch: batch2, index })),
|
|
1750
|
+
concurrency
|
|
1751
|
+
);
|
|
1752
|
+
for (const batchChunk of batchChunks) {
|
|
1753
|
+
await Promise.all(
|
|
1754
|
+
batchChunk.map(({ batch: batch2, index }) => callback(batch2, index))
|
|
1755
|
+
);
|
|
1756
|
+
}
|
|
1757
|
+
}
|
|
1758
|
+
function transpose(matrix) {
|
|
1759
|
+
if (!Array.isArray(matrix) || matrix.length === 0) {
|
|
1760
|
+
return [];
|
|
1761
|
+
}
|
|
1762
|
+
const maxLength = Math.max(...matrix.map((row) => row.length));
|
|
1763
|
+
const result = [];
|
|
1764
|
+
for (let col = 0; col < maxLength; col++) {
|
|
1765
|
+
const column = [];
|
|
1766
|
+
for (let row = 0; row < matrix.length; row++) {
|
|
1767
|
+
if (col < matrix[row].length) {
|
|
1768
|
+
column.push(matrix[row][col]);
|
|
1769
|
+
}
|
|
1770
|
+
}
|
|
1771
|
+
result.push(column);
|
|
1772
|
+
}
|
|
1773
|
+
return result;
|
|
1774
|
+
}
|
|
1775
|
+
function isArrayEqual(array1, array2) {
|
|
1776
|
+
if (!Array.isArray(array1) || !Array.isArray(array2)) {
|
|
1777
|
+
return false;
|
|
1778
|
+
}
|
|
1779
|
+
if (array1.length !== array2.length) {
|
|
1780
|
+
return false;
|
|
1781
|
+
}
|
|
1782
|
+
for (let i = 0; i < array1.length; i++) {
|
|
1783
|
+
if (array1[i] !== array2[i]) {
|
|
1784
|
+
return false;
|
|
1785
|
+
}
|
|
1786
|
+
}
|
|
1787
|
+
return true;
|
|
1788
|
+
}
|
|
1789
|
+
function hasSameElements(array1, array2) {
|
|
1790
|
+
if (!Array.isArray(array1) || !Array.isArray(array2)) {
|
|
1791
|
+
return false;
|
|
1792
|
+
}
|
|
1793
|
+
if (array1.length !== array2.length) {
|
|
1794
|
+
return false;
|
|
1795
|
+
}
|
|
1796
|
+
const freq1 = frequencies(array1);
|
|
1797
|
+
const freq2 = frequencies(array2);
|
|
1798
|
+
if (freq1.size !== freq2.size) {
|
|
1799
|
+
return false;
|
|
1800
|
+
}
|
|
1801
|
+
for (const [key, count] of freq1) {
|
|
1802
|
+
if (freq2.get(key) !== count) {
|
|
1803
|
+
return false;
|
|
1804
|
+
}
|
|
1805
|
+
}
|
|
1806
|
+
return true;
|
|
1807
|
+
}
|
|
1808
|
+
function isSubset(array1, array2) {
|
|
1809
|
+
if (!Array.isArray(array1) || !Array.isArray(array2)) {
|
|
1810
|
+
return false;
|
|
1811
|
+
}
|
|
1812
|
+
const set2 = new Set(array2);
|
|
1813
|
+
return array1.every((item) => set2.has(item));
|
|
1814
|
+
}
|
|
1815
|
+
function isSuperset(array1, array2) {
|
|
1816
|
+
return isSubset(array2, array1);
|
|
1817
|
+
}
|
|
1818
|
+
function interleave(...arrays) {
|
|
1819
|
+
if (arrays.length === 0) {
|
|
1820
|
+
return [];
|
|
1821
|
+
}
|
|
1822
|
+
const maxLength = Math.max(...arrays.map((arr) => arr.length));
|
|
1823
|
+
const result = [];
|
|
1824
|
+
for (let i = 0; i < maxLength; i++) {
|
|
1825
|
+
for (const arr of arrays) {
|
|
1826
|
+
if (i < arr.length) {
|
|
1827
|
+
result.push(arr[i]);
|
|
1828
|
+
}
|
|
1829
|
+
}
|
|
1830
|
+
}
|
|
1831
|
+
return result;
|
|
1832
|
+
}
|
|
1833
|
+
function bifurcate(array, predicate) {
|
|
1834
|
+
const pass = [];
|
|
1835
|
+
const fail = [];
|
|
1836
|
+
if (!Array.isArray(array)) {
|
|
1837
|
+
return { pass, fail };
|
|
1838
|
+
}
|
|
1839
|
+
for (let i = 0; i < array.length; i++) {
|
|
1840
|
+
if (predicate(array[i], i)) {
|
|
1841
|
+
pass.push(array[i]);
|
|
1842
|
+
} else {
|
|
1843
|
+
fail.push(array[i]);
|
|
1844
|
+
}
|
|
1845
|
+
}
|
|
1846
|
+
return { pass, fail };
|
|
1847
|
+
}
|
|
1848
|
+
function generate(length, generator) {
|
|
1849
|
+
if (length < 0) {
|
|
1850
|
+
return [];
|
|
1851
|
+
}
|
|
1852
|
+
const result = [];
|
|
1853
|
+
for (let i = 0; i < length; i++) {
|
|
1854
|
+
result.push(generator(i));
|
|
1855
|
+
}
|
|
1856
|
+
return result;
|
|
1857
|
+
}
|
|
1858
|
+
function repeat(array, times) {
|
|
1859
|
+
if (!Array.isArray(array) || times < 0) {
|
|
1860
|
+
return [];
|
|
1861
|
+
}
|
|
1862
|
+
const result = [];
|
|
1863
|
+
for (let i = 0; i < times; i++) {
|
|
1864
|
+
result.push(...array);
|
|
1865
|
+
}
|
|
1866
|
+
return result;
|
|
1867
|
+
}
|
|
1868
|
+
function median(array) {
|
|
1869
|
+
if (!Array.isArray(array) || array.length === 0) {
|
|
1870
|
+
return void 0;
|
|
1871
|
+
}
|
|
1872
|
+
const sorted = [...array].sort((a, b) => a - b);
|
|
1873
|
+
const mid = Math.floor(sorted.length / 2);
|
|
1874
|
+
if (sorted.length % 2 === 0) {
|
|
1875
|
+
return (sorted[mid - 1] + sorted[mid]) / 2;
|
|
1876
|
+
}
|
|
1877
|
+
return sorted[mid];
|
|
1878
|
+
}
|
|
1879
|
+
function mode(array) {
|
|
1880
|
+
const common = mostCommon(array, 1);
|
|
1881
|
+
return common.length > 0 ? common[0] : void 0;
|
|
1882
|
+
}
|
|
1883
|
+
function without(array, ...values) {
|
|
1884
|
+
if (!Array.isArray(array)) {
|
|
1885
|
+
return [];
|
|
1886
|
+
}
|
|
1887
|
+
const excludeSet = new Set(values);
|
|
1888
|
+
return array.filter((item) => !excludeSet.has(item));
|
|
1889
|
+
}
|
|
1890
|
+
function differenceWith(array, ...others) {
|
|
1891
|
+
if (!Array.isArray(array)) {
|
|
1892
|
+
return [];
|
|
1893
|
+
}
|
|
1894
|
+
const excludeSet = new Set(others.flat());
|
|
1895
|
+
return array.filter((item) => !excludeSet.has(item));
|
|
1896
|
+
}
|
|
1897
|
+
function groupConsecutive(array) {
|
|
1898
|
+
if (!Array.isArray(array) || array.length === 0) {
|
|
1899
|
+
return [];
|
|
1900
|
+
}
|
|
1901
|
+
const result = [];
|
|
1902
|
+
let currentGroup = [array[0]];
|
|
1903
|
+
for (let i = 1; i < array.length; i++) {
|
|
1904
|
+
if (array[i] === array[i - 1]) {
|
|
1905
|
+
currentGroup.push(array[i]);
|
|
1906
|
+
} else {
|
|
1907
|
+
result.push(currentGroup);
|
|
1908
|
+
currentGroup = [array[i]];
|
|
1909
|
+
}
|
|
1910
|
+
}
|
|
1911
|
+
result.push(currentGroup);
|
|
1912
|
+
return result;
|
|
1913
|
+
}
|
|
1914
|
+
function dedupeConsecutive(array) {
|
|
1915
|
+
if (!Array.isArray(array) || array.length === 0) {
|
|
1916
|
+
return [];
|
|
1917
|
+
}
|
|
1918
|
+
const result = [array[0]];
|
|
1919
|
+
for (let i = 1; i < array.length; i++) {
|
|
1920
|
+
if (array[i] !== array[i - 1]) {
|
|
1921
|
+
result.push(array[i]);
|
|
1922
|
+
}
|
|
1923
|
+
}
|
|
1924
|
+
return result;
|
|
1925
|
+
}
|
|
1926
|
+
function rank(array, method = "standard") {
|
|
1927
|
+
if (!Array.isArray(array) || array.length === 0) {
|
|
1928
|
+
return [];
|
|
1929
|
+
}
|
|
1930
|
+
const indexed = array.map((value, index) => ({ value, index }));
|
|
1931
|
+
indexed.sort((a, b) => a.value - b.value);
|
|
1932
|
+
const ranks = new Array(array.length);
|
|
1933
|
+
if (method === "ordinal") {
|
|
1934
|
+
for (let i = 0; i < indexed.length; i++) {
|
|
1935
|
+
ranks[indexed[i].index] = i + 1;
|
|
1936
|
+
}
|
|
1937
|
+
} else if (method === "dense") {
|
|
1938
|
+
let denseRank = 1;
|
|
1939
|
+
ranks[indexed[0].index] = denseRank;
|
|
1940
|
+
for (let i = 1; i < indexed.length; i++) {
|
|
1941
|
+
if (indexed[i].value !== indexed[i - 1].value) {
|
|
1942
|
+
denseRank++;
|
|
1943
|
+
}
|
|
1944
|
+
ranks[indexed[i].index] = denseRank;
|
|
1945
|
+
}
|
|
1946
|
+
} else {
|
|
1947
|
+
let i = 0;
|
|
1948
|
+
while (i < indexed.length) {
|
|
1949
|
+
let j = i;
|
|
1950
|
+
while (j < indexed.length && indexed[j].value === indexed[i].value) {
|
|
1951
|
+
j++;
|
|
1952
|
+
}
|
|
1953
|
+
const rankValue = i + 1;
|
|
1954
|
+
for (let k = i; k < j; k++) {
|
|
1955
|
+
ranks[indexed[k].index] = rankValue;
|
|
1956
|
+
}
|
|
1957
|
+
i = j;
|
|
1958
|
+
}
|
|
1959
|
+
}
|
|
1960
|
+
return ranks;
|
|
1961
|
+
}
|
|
1962
|
+
function percentile(array, percentile2) {
|
|
1963
|
+
if (!Array.isArray(array) || array.length === 0) {
|
|
1964
|
+
return void 0;
|
|
1965
|
+
}
|
|
1966
|
+
if (percentile2 < 0 || percentile2 > 100) {
|
|
1967
|
+
return void 0;
|
|
1968
|
+
}
|
|
1969
|
+
const sorted = [...array].sort((a, b) => a - b);
|
|
1970
|
+
const index = percentile2 / 100 * (sorted.length - 1);
|
|
1971
|
+
const lower = Math.floor(index);
|
|
1972
|
+
const upper = Math.ceil(index);
|
|
1973
|
+
const weight = index - lower;
|
|
1974
|
+
if (lower === upper) {
|
|
1975
|
+
return sorted[lower];
|
|
1976
|
+
}
|
|
1977
|
+
return sorted[lower] * (1 - weight) + sorted[upper] * weight;
|
|
1978
|
+
}
|
|
1979
|
+
function quartiles(array) {
|
|
1980
|
+
if (!Array.isArray(array) || array.length === 0) {
|
|
1981
|
+
return void 0;
|
|
1982
|
+
}
|
|
1983
|
+
const q1 = percentile(array, 25);
|
|
1984
|
+
const q2 = percentile(array, 50);
|
|
1985
|
+
const q3 = percentile(array, 75);
|
|
1986
|
+
return {
|
|
1987
|
+
q1,
|
|
1988
|
+
q2,
|
|
1989
|
+
q3,
|
|
1990
|
+
iqr: q3 - q1
|
|
1991
|
+
};
|
|
1992
|
+
}
|
|
1993
|
+
function standardDeviation(array, sample2 = false) {
|
|
1994
|
+
if (!Array.isArray(array) || array.length === 0) {
|
|
1995
|
+
return void 0;
|
|
1996
|
+
}
|
|
1997
|
+
if (sample2 && array.length === 1) {
|
|
1998
|
+
return void 0;
|
|
1999
|
+
}
|
|
2000
|
+
const avg = array.reduce((sum, val) => sum + val, 0) / array.length;
|
|
2001
|
+
const squareDiffs = array.map((value) => Math.pow(value - avg, 2));
|
|
2002
|
+
const avgSquareDiff = squareDiffs.reduce((sum, val) => sum + val, 0) / (sample2 ? array.length - 1 : array.length);
|
|
2003
|
+
return Math.sqrt(avgSquareDiff);
|
|
2004
|
+
}
|
|
2005
|
+
function variance(array, sample2 = false) {
|
|
2006
|
+
const std = standardDeviation(array, sample2);
|
|
2007
|
+
return std !== void 0 ? Math.pow(std, 2) : void 0;
|
|
2008
|
+
}
|
|
2009
|
+
function normalize(array) {
|
|
2010
|
+
if (!Array.isArray(array) || array.length === 0) {
|
|
2011
|
+
return [];
|
|
2012
|
+
}
|
|
2013
|
+
const min = Math.min(...array);
|
|
2014
|
+
const max = Math.max(...array);
|
|
2015
|
+
const range2 = max - min;
|
|
2016
|
+
if (range2 === 0) {
|
|
2017
|
+
return array.map(() => 0);
|
|
2018
|
+
}
|
|
2019
|
+
return array.map((value) => (value - min) / range2);
|
|
2020
|
+
}
|
|
2021
|
+
function standardize(array) {
|
|
2022
|
+
if (!Array.isArray(array) || array.length === 0) {
|
|
2023
|
+
return [];
|
|
2024
|
+
}
|
|
2025
|
+
const avg = array.reduce((sum, val) => sum + val, 0) / array.length;
|
|
2026
|
+
const std = standardDeviation(array);
|
|
2027
|
+
if (std === void 0 || std === 0) {
|
|
2028
|
+
return array.map(() => 0);
|
|
2029
|
+
}
|
|
2030
|
+
return array.map((value) => (value - avg) / std);
|
|
2031
|
+
}
|
|
2032
|
+
function scan(array, fn, initial) {
|
|
2033
|
+
if (!Array.isArray(array)) {
|
|
2034
|
+
return [];
|
|
2035
|
+
}
|
|
2036
|
+
const result = [];
|
|
2037
|
+
let accumulator = initial;
|
|
2038
|
+
for (let i = 0; i < array.length; i++) {
|
|
2039
|
+
accumulator = fn(accumulator, array[i], i);
|
|
2040
|
+
result.push(accumulator);
|
|
2041
|
+
}
|
|
2042
|
+
return result;
|
|
2043
|
+
}
|
|
2044
|
+
function cumulativeSum(array) {
|
|
2045
|
+
return scan(array, (acc, x) => acc + x, 0);
|
|
2046
|
+
}
|
|
2047
|
+
function diff(array) {
|
|
2048
|
+
if (!Array.isArray(array) || array.length < 2) {
|
|
2049
|
+
return [];
|
|
2050
|
+
}
|
|
2051
|
+
const result = [];
|
|
2052
|
+
for (let i = 1; i < array.length; i++) {
|
|
2053
|
+
result.push(array[i] - array[i - 1]);
|
|
2054
|
+
}
|
|
2055
|
+
return result;
|
|
2056
|
+
}
|
|
2057
|
+
function pad(array, length, value, position = "end") {
|
|
2058
|
+
if (!Array.isArray(array) || length <= array.length) {
|
|
2059
|
+
return [...array];
|
|
2060
|
+
}
|
|
2061
|
+
const padding = new Array(length - array.length).fill(value);
|
|
2062
|
+
return position === "start" ? [...padding, ...array] : [...array, ...padding];
|
|
2063
|
+
}
|
|
2064
|
+
function trim(array, predicate) {
|
|
2065
|
+
if (!Array.isArray(array) || array.length === 0) {
|
|
2066
|
+
return [];
|
|
2067
|
+
}
|
|
2068
|
+
let start = 0;
|
|
2069
|
+
let end = array.length - 1;
|
|
2070
|
+
while (start <= end && predicate(array[start])) {
|
|
2071
|
+
start++;
|
|
2072
|
+
}
|
|
2073
|
+
while (end >= start && predicate(array[end])) {
|
|
2074
|
+
end--;
|
|
2075
|
+
}
|
|
2076
|
+
return array.slice(start, end + 1);
|
|
2077
|
+
}
|
|
2078
|
+
function pairwise(array) {
|
|
2079
|
+
if (!Array.isArray(array) || array.length < 2) {
|
|
2080
|
+
return [];
|
|
2081
|
+
}
|
|
2082
|
+
const result = [];
|
|
2083
|
+
for (let i = 0; i < array.length - 1; i++) {
|
|
2084
|
+
result.push([array[i], array[i + 1]]);
|
|
2085
|
+
}
|
|
2086
|
+
return result;
|
|
2087
|
+
}
|
|
2088
|
+
function enumerate(array) {
|
|
2089
|
+
if (!Array.isArray(array)) {
|
|
2090
|
+
return [];
|
|
2091
|
+
}
|
|
2092
|
+
return array.map((value, index) => [index, value]);
|
|
2093
|
+
}
|
|
2094
|
+
function applyByIndex(array, functions) {
|
|
2095
|
+
if (!Array.isArray(array)) {
|
|
2096
|
+
return [];
|
|
2097
|
+
}
|
|
2098
|
+
return array.map((item, index) => {
|
|
2099
|
+
const fn = functions[index % functions.length];
|
|
2100
|
+
return fn(item);
|
|
2101
|
+
});
|
|
2102
|
+
}
|
|
2103
|
+
function rotateLeft(array, n = 1) {
|
|
2104
|
+
if (!Array.isArray(array) || array.length === 0) {
|
|
2105
|
+
return [];
|
|
2106
|
+
}
|
|
2107
|
+
const len = array.length;
|
|
2108
|
+
const rotations = (n % len + len) % len;
|
|
2109
|
+
return [...array.slice(rotations), ...array.slice(0, rotations)];
|
|
2110
|
+
}
|
|
2111
|
+
function rotateRight(array, n = 1) {
|
|
2112
|
+
return rotateLeft(array, -n);
|
|
2113
|
+
}
|
|
2114
|
+
function swap(array, i, j) {
|
|
2115
|
+
if (!Array.isArray(array) || i < 0 || j < 0 || i >= array.length || j >= array.length) {
|
|
2116
|
+
return [...array];
|
|
2117
|
+
}
|
|
2118
|
+
const result = [...array];
|
|
2119
|
+
[result[i], result[j]] = [result[j], result[i]];
|
|
2120
|
+
return result;
|
|
2121
|
+
}
|
|
2122
|
+
function reverseSegment(array, start, end) {
|
|
2123
|
+
if (!Array.isArray(array) || start < 0 || end >= array.length || start >= end) {
|
|
2124
|
+
return [...array];
|
|
2125
|
+
}
|
|
2126
|
+
const result = [...array];
|
|
2127
|
+
const segment2 = result.slice(start, end + 1).reverse();
|
|
2128
|
+
result.splice(start, end - start + 1, ...segment2);
|
|
2129
|
+
return result;
|
|
2130
|
+
}
|
|
2131
|
+
function isSorted(array, compareFn) {
|
|
2132
|
+
if (!Array.isArray(array) || array.length <= 1) {
|
|
2133
|
+
return true;
|
|
2134
|
+
}
|
|
2135
|
+
const compare = compareFn || ((a, b) => a < b ? -1 : a > b ? 1 : 0);
|
|
2136
|
+
for (let i = 1; i < array.length; i++) {
|
|
2137
|
+
if (compare(array[i - 1], array[i]) > 0) {
|
|
2138
|
+
return false;
|
|
2139
|
+
}
|
|
2140
|
+
}
|
|
2141
|
+
return true;
|
|
2142
|
+
}
|
|
2143
|
+
function hasDuplicates(array) {
|
|
2144
|
+
if (!Array.isArray(array)) {
|
|
2145
|
+
return false;
|
|
2146
|
+
}
|
|
2147
|
+
return new Set(array).size !== array.length;
|
|
2148
|
+
}
|
|
2149
|
+
function pickMany(array, keys) {
|
|
2150
|
+
if (!Array.isArray(array)) {
|
|
2151
|
+
return [];
|
|
2152
|
+
}
|
|
2153
|
+
return array.map((obj) => {
|
|
2154
|
+
const result = {};
|
|
2155
|
+
for (const key of keys) {
|
|
2156
|
+
if (key in obj) {
|
|
2157
|
+
result[key] = obj[key];
|
|
2158
|
+
}
|
|
2159
|
+
}
|
|
2160
|
+
return result;
|
|
2161
|
+
});
|
|
2162
|
+
}
|
|
2163
|
+
function toObject(array, keySelector, valueSelector) {
|
|
2164
|
+
if (!Array.isArray(array)) {
|
|
2165
|
+
return {};
|
|
2166
|
+
}
|
|
2167
|
+
const result = {};
|
|
2168
|
+
for (let i = 0; i < array.length; i++) {
|
|
2169
|
+
const key = keySelector(array[i], i);
|
|
2170
|
+
const value = valueSelector ? valueSelector(array[i], i) : array[i];
|
|
2171
|
+
result[key] = value;
|
|
2172
|
+
}
|
|
2173
|
+
return result;
|
|
2174
|
+
}
|
|
2175
|
+
async function mapAsync(array, fn) {
|
|
2176
|
+
if (!Array.isArray(array)) {
|
|
2177
|
+
return [];
|
|
2178
|
+
}
|
|
2179
|
+
const result = [];
|
|
2180
|
+
for (let i = 0; i < array.length; i++) {
|
|
2181
|
+
result.push(await fn(array[i], i));
|
|
2182
|
+
}
|
|
2183
|
+
return result;
|
|
2184
|
+
}
|
|
2185
|
+
async function mapAsyncParallel(array, fn) {
|
|
2186
|
+
if (!Array.isArray(array)) {
|
|
2187
|
+
return [];
|
|
2188
|
+
}
|
|
2189
|
+
return Promise.all(array.map((item, index) => fn(item, index)));
|
|
2190
|
+
}
|
|
2191
|
+
async function filterAsync(array, predicate) {
|
|
2192
|
+
if (!Array.isArray(array)) {
|
|
2193
|
+
return [];
|
|
2194
|
+
}
|
|
2195
|
+
const result = [];
|
|
2196
|
+
for (let i = 0; i < array.length; i++) {
|
|
2197
|
+
if (await predicate(array[i], i)) {
|
|
2198
|
+
result.push(array[i]);
|
|
2199
|
+
}
|
|
2200
|
+
}
|
|
2201
|
+
return result;
|
|
2202
|
+
}
|
|
2203
|
+
async function reduceAsync(array, fn, initial) {
|
|
2204
|
+
if (!Array.isArray(array)) {
|
|
2205
|
+
return initial;
|
|
2206
|
+
}
|
|
2207
|
+
let accumulator = initial;
|
|
2208
|
+
for (let i = 0; i < array.length; i++) {
|
|
2209
|
+
accumulator = await fn(accumulator, array[i], i);
|
|
2210
|
+
}
|
|
2211
|
+
return accumulator;
|
|
2212
|
+
}
|
|
2213
|
+
async function findAsync(array, predicate) {
|
|
2214
|
+
if (!Array.isArray(array)) {
|
|
2215
|
+
return void 0;
|
|
2216
|
+
}
|
|
2217
|
+
for (let i = 0; i < array.length; i++) {
|
|
2218
|
+
if (await predicate(array[i], i)) {
|
|
2219
|
+
return array[i];
|
|
2220
|
+
}
|
|
2221
|
+
}
|
|
2222
|
+
return void 0;
|
|
2223
|
+
}
|
|
2224
|
+
async function someAsync(array, predicate) {
|
|
2225
|
+
if (!Array.isArray(array)) {
|
|
2226
|
+
return false;
|
|
2227
|
+
}
|
|
2228
|
+
for (let i = 0; i < array.length; i++) {
|
|
2229
|
+
if (await predicate(array[i], i)) {
|
|
2230
|
+
return true;
|
|
2231
|
+
}
|
|
2232
|
+
}
|
|
2233
|
+
return false;
|
|
2234
|
+
}
|
|
2235
|
+
async function everyAsync(array, predicate) {
|
|
2236
|
+
if (!Array.isArray(array)) {
|
|
2237
|
+
return true;
|
|
2238
|
+
}
|
|
2239
|
+
for (let i = 0; i < array.length; i++) {
|
|
2240
|
+
if (!await predicate(array[i], i)) {
|
|
2241
|
+
return false;
|
|
2242
|
+
}
|
|
2243
|
+
}
|
|
2244
|
+
return true;
|
|
2245
|
+
}
|
|
2246
|
+
function weightedAverage(array, valueSelector, weightSelector) {
|
|
2247
|
+
if (!Array.isArray(array) || array.length === 0) {
|
|
2248
|
+
return 0;
|
|
2249
|
+
}
|
|
2250
|
+
let totalWeight = 0;
|
|
2251
|
+
let weightedSum = 0;
|
|
2252
|
+
for (const item of array) {
|
|
2253
|
+
const value = typeof valueSelector === "function" ? valueSelector(item) : get(item, valueSelector);
|
|
2254
|
+
const weight = typeof weightSelector === "function" ? weightSelector(item) : get(item, weightSelector);
|
|
2255
|
+
if (typeof value === "number" && typeof weight === "number") {
|
|
2256
|
+
weightedSum += value * weight;
|
|
2257
|
+
totalWeight += weight;
|
|
2258
|
+
}
|
|
2259
|
+
}
|
|
2260
|
+
return totalWeight === 0 ? 0 : weightedSum / totalWeight;
|
|
2261
|
+
}
|
|
2262
|
+
function weightedSample(array, weightSelector, count = 1) {
|
|
2263
|
+
if (!Array.isArray(array) || array.length === 0 || count < 1) {
|
|
2264
|
+
return [];
|
|
2265
|
+
}
|
|
2266
|
+
const weights = [];
|
|
2267
|
+
let totalWeight = 0;
|
|
2268
|
+
for (const item of array) {
|
|
2269
|
+
const weight = typeof weightSelector === "function" ? weightSelector(item) : get(item, weightSelector);
|
|
2270
|
+
totalWeight += typeof weight === "number" && weight > 0 ? weight : 0;
|
|
2271
|
+
weights.push(totalWeight);
|
|
2272
|
+
}
|
|
2273
|
+
if (totalWeight === 0) {
|
|
2274
|
+
return [];
|
|
2275
|
+
}
|
|
2276
|
+
const result = [];
|
|
2277
|
+
for (let i = 0; i < count; i++) {
|
|
2278
|
+
const random = Math.random() * totalWeight;
|
|
2279
|
+
const index = weights.findIndex((w) => random < w);
|
|
2280
|
+
if (index !== -1) {
|
|
2281
|
+
result.push(array[index]);
|
|
2282
|
+
}
|
|
2283
|
+
}
|
|
2284
|
+
return result;
|
|
2285
|
+
}
|
|
2286
|
+
function segment(array, sizes) {
|
|
2287
|
+
if (!Array.isArray(array) || !Array.isArray(sizes)) {
|
|
2288
|
+
return [];
|
|
2289
|
+
}
|
|
2290
|
+
const result = [];
|
|
2291
|
+
let offset = 0;
|
|
2292
|
+
for (const size of sizes) {
|
|
2293
|
+
if (offset >= array.length) break;
|
|
2294
|
+
result.push(array.slice(offset, offset + size));
|
|
2295
|
+
offset += size;
|
|
2296
|
+
}
|
|
2297
|
+
return result;
|
|
2298
|
+
}
|
|
2299
|
+
function selectByCount(array, count) {
|
|
2300
|
+
if (!Array.isArray(array) || count < 1) {
|
|
2301
|
+
return [];
|
|
2302
|
+
}
|
|
2303
|
+
const freq = frequencies(array);
|
|
2304
|
+
const result = [];
|
|
2305
|
+
for (const item of array) {
|
|
2306
|
+
if (freq.get(item) === count) {
|
|
2307
|
+
result.push(item);
|
|
2308
|
+
}
|
|
2309
|
+
}
|
|
2310
|
+
return result;
|
|
2311
|
+
}
|
|
2312
|
+
function filterConsecutive(array, n, predicate) {
|
|
2313
|
+
if (!Array.isArray(array) || n < 1) {
|
|
2314
|
+
return [];
|
|
2315
|
+
}
|
|
2316
|
+
const result = [];
|
|
2317
|
+
let consecutiveCount = 0;
|
|
2318
|
+
const buffer = [];
|
|
2319
|
+
for (const item of array) {
|
|
2320
|
+
if (predicate(item)) {
|
|
2321
|
+
consecutiveCount++;
|
|
2322
|
+
buffer.push(item);
|
|
2323
|
+
if (consecutiveCount >= n) {
|
|
2324
|
+
result.push(...buffer.splice(0, buffer.length - n + 1));
|
|
2325
|
+
}
|
|
2326
|
+
} else {
|
|
2327
|
+
consecutiveCount = 0;
|
|
2328
|
+
buffer.length = 0;
|
|
2329
|
+
}
|
|
2330
|
+
}
|
|
2331
|
+
if (consecutiveCount >= n) {
|
|
2332
|
+
result.push(...buffer);
|
|
2333
|
+
}
|
|
2334
|
+
return result;
|
|
2335
|
+
}
|
|
2336
|
+
function mapWithContext(array, fn, initialContext) {
|
|
2337
|
+
if (!Array.isArray(array)) {
|
|
2338
|
+
return [];
|
|
2339
|
+
}
|
|
2340
|
+
const result = [];
|
|
2341
|
+
let context = initialContext;
|
|
2342
|
+
for (let i = 0; i < array.length; i++) {
|
|
2343
|
+
const { value, newContext } = fn(array[i], context, i);
|
|
2344
|
+
result.push(value);
|
|
2345
|
+
context = newContext;
|
|
2346
|
+
}
|
|
2347
|
+
return result;
|
|
2348
|
+
}
|
|
2349
|
+
function batch(array, batchSize) {
|
|
2350
|
+
return chunk(array, batchSize);
|
|
2351
|
+
}
|
|
2352
|
+
function zipWith(array1, array2, fn) {
|
|
2353
|
+
if (!Array.isArray(array1) || !Array.isArray(array2)) {
|
|
2354
|
+
return [];
|
|
2355
|
+
}
|
|
2356
|
+
const length = Math.min(array1.length, array2.length);
|
|
2357
|
+
const result = [];
|
|
2358
|
+
for (let i = 0; i < length; i++) {
|
|
2359
|
+
result.push(fn(array1[i], array2[i]));
|
|
2360
|
+
}
|
|
2361
|
+
return result;
|
|
2362
|
+
}
|
|
2363
|
+
function mergeArraysByKey(arrays, key, mergeStrategy = "last") {
|
|
2364
|
+
if (!Array.isArray(arrays) || arrays.length === 0) {
|
|
2365
|
+
return [];
|
|
2366
|
+
}
|
|
2367
|
+
const map = /* @__PURE__ */ new Map();
|
|
2368
|
+
for (const array of arrays) {
|
|
2369
|
+
if (!Array.isArray(array)) continue;
|
|
2370
|
+
for (const item of array) {
|
|
2371
|
+
const keyValue = get(item, key);
|
|
2372
|
+
if (mergeStrategy === "first") {
|
|
2373
|
+
if (!map.has(keyValue)) {
|
|
2374
|
+
map.set(keyValue, item);
|
|
2375
|
+
}
|
|
2376
|
+
} else if (mergeStrategy === "last") {
|
|
2377
|
+
map.set(keyValue, item);
|
|
2378
|
+
} else if (mergeStrategy === "concat") {
|
|
2379
|
+
const existing = map.get(keyValue);
|
|
2380
|
+
if (Array.isArray(existing)) {
|
|
2381
|
+
existing.push(item);
|
|
2382
|
+
} else if (existing) {
|
|
2383
|
+
map.set(keyValue, [existing, item]);
|
|
2384
|
+
} else {
|
|
2385
|
+
map.set(keyValue, item);
|
|
2386
|
+
}
|
|
2387
|
+
} else if (typeof mergeStrategy === "function") {
|
|
2388
|
+
const existing = map.get(keyValue);
|
|
2389
|
+
if (existing && !Array.isArray(existing)) {
|
|
2390
|
+
map.set(keyValue, mergeStrategy(existing, item));
|
|
2391
|
+
} else {
|
|
2392
|
+
map.set(keyValue, item);
|
|
2393
|
+
}
|
|
2394
|
+
}
|
|
2395
|
+
}
|
|
2396
|
+
}
|
|
2397
|
+
const result = [];
|
|
2398
|
+
for (const value of map.values()) {
|
|
2399
|
+
if (Array.isArray(value) && mergeStrategy === "concat") {
|
|
2400
|
+
result.push(...value);
|
|
2401
|
+
} else if (!Array.isArray(value)) {
|
|
2402
|
+
result.push(value);
|
|
2403
|
+
}
|
|
2404
|
+
}
|
|
2405
|
+
return result;
|
|
2406
|
+
}
|
|
2407
|
+
function indexBy(array, key) {
|
|
2408
|
+
return toObject(array, (item) => String(get(item, key)));
|
|
2409
|
+
}
|
|
2410
|
+
function binarySearch(array, target, compareFn) {
|
|
2411
|
+
if (!Array.isArray(array) || array.length === 0) {
|
|
2412
|
+
return -1;
|
|
2413
|
+
}
|
|
2414
|
+
const compare = compareFn || ((a, b) => a < b ? -1 : a > b ? 1 : 0);
|
|
2415
|
+
let left = 0;
|
|
2416
|
+
let right = array.length - 1;
|
|
2417
|
+
while (left <= right) {
|
|
2418
|
+
const mid = Math.floor((left + right) / 2);
|
|
2419
|
+
const comparison = compare(array[mid], target);
|
|
2420
|
+
if (comparison === 0) {
|
|
2421
|
+
return mid;
|
|
2422
|
+
} else if (comparison < 0) {
|
|
2423
|
+
left = mid + 1;
|
|
2424
|
+
} else {
|
|
2425
|
+
right = mid - 1;
|
|
2426
|
+
}
|
|
2427
|
+
}
|
|
2428
|
+
return -1;
|
|
2429
|
+
}
|
|
2430
|
+
function insertSorted(array, value, compareFn) {
|
|
2431
|
+
if (!Array.isArray(array)) {
|
|
2432
|
+
return [value];
|
|
2433
|
+
}
|
|
2434
|
+
const compare = compareFn || ((a, b) => a < b ? -1 : a > b ? 1 : 0);
|
|
2435
|
+
const result = [...array];
|
|
2436
|
+
let insertIndex = 0;
|
|
2437
|
+
while (insertIndex < result.length && compare(result[insertIndex], value) < 0) {
|
|
2438
|
+
insertIndex++;
|
|
2439
|
+
}
|
|
2440
|
+
result.splice(insertIndex, 0, value);
|
|
2441
|
+
return result;
|
|
2442
|
+
}
|
|
2443
|
+
|
|
2444
|
+
// src/lib/dom/events.ts
|
|
2445
|
+
function isDOMEventTarget(target) {
|
|
2446
|
+
return target && typeof target.addEventListener === "function";
|
|
2447
|
+
}
|
|
2448
|
+
function isNodeEventEmitter(target) {
|
|
2449
|
+
return target && typeof target.addEventListener === "function" && typeof target.removeEventListener === "function";
|
|
2450
|
+
}
|
|
2451
|
+
function isOnOffTarget(target) {
|
|
2452
|
+
return target && typeof target.on === "function" && typeof target.off === "function";
|
|
2453
|
+
}
|
|
2454
|
+
function isAddRemoveListenerTarget(target) {
|
|
2455
|
+
return target && typeof target.addListener === "function" && typeof target.removeListener === "function";
|
|
2456
|
+
}
|
|
2457
|
+
|
|
2458
|
+
// src/lib/dom/utils.ts
|
|
2459
|
+
function windowObject() {
|
|
2460
|
+
return typeof globalThis === "object" ? globalThis : typeof window === "object" ? window : typeof self === "object" ? self : typeof global === "object" ? global : null;
|
|
2461
|
+
}
|
|
2462
|
+
function btoa(chn) {
|
|
2463
|
+
return Buffer.from(chn).toString("base64");
|
|
2464
|
+
}
|
|
2465
|
+
function uena(chn) {
|
|
2466
|
+
return Buffer.from(chn).toString("base64");
|
|
2467
|
+
}
|
|
2468
|
+
function aenu(chn) {
|
|
2469
|
+
return decodeURIComponent(Buffer.from(chn, "base64").toString("utf-8"));
|
|
2470
|
+
}
|
|
2471
|
+
var updateQueryStringParameter = (uri, key, val) => {
|
|
2472
|
+
let value = val;
|
|
2473
|
+
const re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
|
|
2474
|
+
const separator = uri.includes("?") ? "&" : "?";
|
|
2475
|
+
if (key === "country") {
|
|
2476
|
+
value = JSON.parse(value).alpha_2;
|
|
2477
|
+
}
|
|
2478
|
+
if (key === "phone") {
|
|
2479
|
+
value = value.trim().replace(/\s/g, "");
|
|
2480
|
+
}
|
|
2481
|
+
const match = uri.match(re);
|
|
2482
|
+
if (typeof match !== "undefined" && match !== null) {
|
|
2483
|
+
return uri.replace(re, "$1" + key + "=" + value + "$2");
|
|
2484
|
+
}
|
|
2485
|
+
return uri + separator + key + "=" + value;
|
|
2486
|
+
};
|
|
2487
|
+
|
|
2488
|
+
// src/lib/crypto/hash.ts
|
|
2489
|
+
var createHash = async (value, algorithm = "SHA-1") => {
|
|
2490
|
+
if (typeof window === "undefined") return null;
|
|
2491
|
+
const { subtle } = window.globalThis.crypto;
|
|
2492
|
+
const key = await subtle.generateKey(
|
|
2493
|
+
{
|
|
2494
|
+
name: "HMAC",
|
|
2495
|
+
hash: algorithm,
|
|
2496
|
+
length: 256
|
|
2497
|
+
},
|
|
2498
|
+
true,
|
|
2499
|
+
["sign", "verify"]
|
|
2500
|
+
);
|
|
2501
|
+
const enc = new TextEncoder();
|
|
2502
|
+
const message = enc.encode(value);
|
|
2503
|
+
const digest = await subtle.sign(
|
|
2504
|
+
{
|
|
2505
|
+
name: "HMAC"
|
|
2506
|
+
},
|
|
2507
|
+
key,
|
|
2508
|
+
message
|
|
2509
|
+
);
|
|
2510
|
+
const hex = [...new Uint8Array(digest)].map((x) => x.toString(16).padStart(2, "0")).join("");
|
|
2511
|
+
return hex;
|
|
2512
|
+
};
|
|
2513
|
+
var hash = async (value, algorithm = "SHA-256") => {
|
|
2514
|
+
const encoder = new TextEncoder();
|
|
2515
|
+
const data = encoder.encode(value);
|
|
2516
|
+
const hashBuffer = await crypto.subtle.digest(algorithm, data);
|
|
2517
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
2518
|
+
const hashHex = hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
2519
|
+
return hashHex;
|
|
2520
|
+
};
|
|
2521
|
+
var compareWithHash = async (value1, value2, algorithm = "SHA-256") => {
|
|
2522
|
+
const hash1 = await hash(value1, algorithm);
|
|
2523
|
+
const hash2 = await hash(value2, algorithm);
|
|
2524
|
+
return hash1 === hash2;
|
|
2525
|
+
};
|
|
2526
|
+
async function hashStringPromise(value, algorithm = "SHA-256") {
|
|
2527
|
+
const encoder = new TextEncoder();
|
|
2528
|
+
const data = encoder.encode(value);
|
|
2529
|
+
const hashBuffer = await crypto.subtle.digest(algorithm, data);
|
|
2530
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
2531
|
+
const hashHex = hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
2532
|
+
return hashHex;
|
|
2533
|
+
}
|
|
2534
|
+
var string_hash = (str) => {
|
|
2535
|
+
let hash2 = 0;
|
|
2536
|
+
for (let i = 0; i < str.length; i++) {
|
|
2537
|
+
const char = str.charCodeAt(i);
|
|
2538
|
+
hash2 = (hash2 << 5) - hash2 + char;
|
|
2539
|
+
hash2 = hash2 & hash2;
|
|
2540
|
+
}
|
|
2541
|
+
return hash2.toString(16);
|
|
2542
|
+
};
|
|
2543
|
+
|
|
2544
|
+
// src/lib/functions/functions.ts
|
|
2545
|
+
var import_object3 = require("@fluixi/utils/object");
|
|
2546
|
+
function isFunction2(v) {
|
|
2547
|
+
return typeof v === "function" && !(0, import_object3.isClass)(v);
|
|
2548
|
+
}
|
|
2549
|
+
function isPromise(v) {
|
|
2550
|
+
return v instanceof Promise || !!v && (typeof v === "object" || typeof v === "function") && "then" in v;
|
|
2551
|
+
}
|
|
2552
|
+
function isAsyncFunction(v) {
|
|
2553
|
+
return isFunction2(v) && v.constructor.name === "AsyncFunction";
|
|
2554
|
+
}
|
|
2555
|
+
function memoize(fn, resolver) {
|
|
2556
|
+
const cache = /* @__PURE__ */ new Map();
|
|
2557
|
+
const memoized = function(...args) {
|
|
2558
|
+
const key = resolver ? resolver(...args) : JSON.stringify(args);
|
|
2559
|
+
if (cache.has(key)) {
|
|
2560
|
+
return cache.get(key);
|
|
2561
|
+
}
|
|
2562
|
+
const result = fn.apply(this, args);
|
|
2563
|
+
cache.set(key, result);
|
|
2564
|
+
return result;
|
|
2565
|
+
};
|
|
2566
|
+
memoized.cache = cache;
|
|
2567
|
+
return memoized;
|
|
2568
|
+
}
|
|
2569
|
+
function debounce(fn, wait, options = {}) {
|
|
2570
|
+
const { leading = false, trailing = true, maxWait } = options;
|
|
2571
|
+
let timerId;
|
|
2572
|
+
let maxTimerId;
|
|
2573
|
+
let lastCallTime;
|
|
2574
|
+
let lastInvokeTime = 0;
|
|
2575
|
+
let lastArgs;
|
|
2576
|
+
let lastThis;
|
|
2577
|
+
let result;
|
|
2578
|
+
function invokeFunc(time) {
|
|
2579
|
+
const args = lastArgs;
|
|
2580
|
+
const thisArg = lastThis;
|
|
2581
|
+
lastArgs = lastThis = void 0;
|
|
2582
|
+
lastInvokeTime = time;
|
|
2583
|
+
result = fn.apply(thisArg, args);
|
|
2584
|
+
return result;
|
|
2585
|
+
}
|
|
2586
|
+
function startTimer(pendingFunc, wait2) {
|
|
2587
|
+
return setTimeout(pendingFunc, wait2);
|
|
2588
|
+
}
|
|
2589
|
+
function cancelTimer(id) {
|
|
2590
|
+
if (id !== void 0) {
|
|
2591
|
+
clearTimeout(id);
|
|
2592
|
+
}
|
|
2593
|
+
}
|
|
2594
|
+
function leadingEdge(time) {
|
|
2595
|
+
lastInvokeTime = time;
|
|
2596
|
+
timerId = startTimer(timerExpired, wait);
|
|
2597
|
+
return leading ? invokeFunc(time) : result;
|
|
2598
|
+
}
|
|
2599
|
+
function remainingWait(time) {
|
|
2600
|
+
const timeSinceLastCall = time - lastCallTime;
|
|
2601
|
+
const timeSinceLastInvoke = time - lastInvokeTime;
|
|
2602
|
+
const timeWaiting = wait - timeSinceLastCall;
|
|
2603
|
+
return maxWait !== void 0 ? Math.min(timeWaiting, maxWait - timeSinceLastInvoke) : timeWaiting;
|
|
2604
|
+
}
|
|
2605
|
+
function shouldInvoke(time) {
|
|
2606
|
+
const timeSinceLastCall = time - lastCallTime;
|
|
2607
|
+
const timeSinceLastInvoke = time - lastInvokeTime;
|
|
2608
|
+
return lastCallTime === void 0 || timeSinceLastCall >= wait || timeSinceLastCall < 0 || maxWait !== void 0 && timeSinceLastInvoke >= maxWait;
|
|
2609
|
+
}
|
|
2610
|
+
function timerExpired() {
|
|
2611
|
+
const time = Date.now();
|
|
2612
|
+
if (shouldInvoke(time)) {
|
|
2613
|
+
trailingEdge(time);
|
|
2614
|
+
return;
|
|
2615
|
+
}
|
|
2616
|
+
timerId = startTimer(timerExpired, remainingWait(time));
|
|
2617
|
+
}
|
|
2618
|
+
function trailingEdge(time) {
|
|
2619
|
+
timerId = void 0;
|
|
2620
|
+
if (trailing && lastArgs) {
|
|
2621
|
+
return invokeFunc(time);
|
|
2622
|
+
}
|
|
2623
|
+
lastArgs = lastThis = void 0;
|
|
2624
|
+
return result;
|
|
2625
|
+
}
|
|
2626
|
+
function cancel() {
|
|
2627
|
+
cancelTimer(timerId);
|
|
2628
|
+
cancelTimer(maxTimerId);
|
|
2629
|
+
lastInvokeTime = 0;
|
|
2630
|
+
lastArgs = lastCallTime = lastThis = timerId = maxTimerId = void 0;
|
|
2631
|
+
}
|
|
2632
|
+
function flush() {
|
|
2633
|
+
return timerId === void 0 ? result : trailingEdge(Date.now());
|
|
2634
|
+
}
|
|
2635
|
+
function pending() {
|
|
2636
|
+
return timerId !== void 0;
|
|
2637
|
+
}
|
|
2638
|
+
function debounced(...args) {
|
|
2639
|
+
const time = Date.now();
|
|
2640
|
+
const isInvoking = shouldInvoke(time);
|
|
2641
|
+
lastArgs = args;
|
|
2642
|
+
lastThis = this;
|
|
2643
|
+
lastCallTime = time;
|
|
2644
|
+
if (isInvoking) {
|
|
2645
|
+
if (timerId === void 0) {
|
|
2646
|
+
return leadingEdge(lastCallTime);
|
|
2647
|
+
}
|
|
2648
|
+
if (maxWait !== void 0) {
|
|
2649
|
+
timerId = startTimer(timerExpired, wait);
|
|
2650
|
+
return invokeFunc(lastCallTime);
|
|
2651
|
+
}
|
|
2652
|
+
}
|
|
2653
|
+
if (timerId === void 0) {
|
|
2654
|
+
timerId = startTimer(timerExpired, wait);
|
|
2655
|
+
}
|
|
2656
|
+
return result;
|
|
2657
|
+
}
|
|
2658
|
+
debounced.cancel = cancel;
|
|
2659
|
+
debounced.flush = flush;
|
|
2660
|
+
debounced.pending = pending;
|
|
2661
|
+
return debounced;
|
|
2662
|
+
}
|
|
2663
|
+
function throttle(fn, wait, options = {}) {
|
|
2664
|
+
const { leading = true, trailing = true } = options;
|
|
2665
|
+
return debounce(fn, wait, {
|
|
2666
|
+
leading,
|
|
2667
|
+
trailing,
|
|
2668
|
+
maxWait: wait
|
|
2669
|
+
});
|
|
2670
|
+
}
|
|
2671
|
+
function once(fn) {
|
|
2672
|
+
let called = false;
|
|
2673
|
+
let result;
|
|
2674
|
+
const wrapped = function(...args) {
|
|
2675
|
+
if (!called) {
|
|
2676
|
+
called = true;
|
|
2677
|
+
result = fn.apply(this, args);
|
|
2678
|
+
}
|
|
2679
|
+
return result;
|
|
2680
|
+
};
|
|
2681
|
+
Object.defineProperty(wrapped, "called", {
|
|
2682
|
+
get() {
|
|
2683
|
+
return called;
|
|
2684
|
+
}
|
|
2685
|
+
});
|
|
2686
|
+
return wrapped;
|
|
2687
|
+
}
|
|
2688
|
+
function rearg(fn, ...indexes) {
|
|
2689
|
+
return function(...args) {
|
|
2690
|
+
const reordered = indexes.map((i) => args[i]);
|
|
2691
|
+
return fn.apply(this, reordered);
|
|
2692
|
+
};
|
|
2693
|
+
}
|
|
2694
|
+
function curry(fn, arity = fn.length) {
|
|
2695
|
+
return function curried(...args) {
|
|
2696
|
+
if (args.length >= arity) {
|
|
2697
|
+
return fn.apply(this, args);
|
|
2698
|
+
}
|
|
2699
|
+
return function(...nextArgs) {
|
|
2700
|
+
return curried.apply(this, [...args, ...nextArgs]);
|
|
2701
|
+
};
|
|
2702
|
+
};
|
|
2703
|
+
}
|
|
2704
|
+
function compose(...fns) {
|
|
2705
|
+
return fns.reduceRight(
|
|
2706
|
+
(prevFn, nextFn) => (value) => nextFn(prevFn(value)),
|
|
2707
|
+
(value) => value
|
|
2708
|
+
);
|
|
2709
|
+
}
|
|
2710
|
+
function pipe(...fns) {
|
|
2711
|
+
return fns.reduce(
|
|
2712
|
+
(prevFn, nextFn) => (value) => nextFn(prevFn(value)),
|
|
2713
|
+
(value) => value
|
|
2714
|
+
);
|
|
2715
|
+
}
|
|
2716
|
+
function negate(predicate) {
|
|
2717
|
+
return function(...args) {
|
|
2718
|
+
return !predicate.apply(this, args);
|
|
2719
|
+
};
|
|
2720
|
+
}
|
|
2721
|
+
function overArgs(fn, ...transforms) {
|
|
2722
|
+
return function(...args) {
|
|
2723
|
+
const transformedArgs = args.map(
|
|
2724
|
+
(arg, index) => transforms[index] ? transforms[index](arg) : arg
|
|
2725
|
+
);
|
|
2726
|
+
return fn.apply(this, transformedArgs);
|
|
2727
|
+
};
|
|
2728
|
+
}
|
|
2729
|
+
function partial(fn, ...partials) {
|
|
2730
|
+
return function(...args) {
|
|
2731
|
+
return fn.apply(this, [...partials, ...args]);
|
|
2732
|
+
};
|
|
2733
|
+
}
|
|
2734
|
+
function partialRight(fn, ...partials) {
|
|
2735
|
+
return function(...args) {
|
|
2736
|
+
return fn.apply(this, [...args, ...partials]);
|
|
2737
|
+
};
|
|
2738
|
+
}
|
|
2739
|
+
function bind(fn, thisArg, ...partials) {
|
|
2740
|
+
return function(...args) {
|
|
2741
|
+
return fn.apply(thisArg, [...partials, ...args]);
|
|
2742
|
+
};
|
|
2743
|
+
}
|
|
2744
|
+
function flip(fn) {
|
|
2745
|
+
return function(...args) {
|
|
2746
|
+
return fn.apply(this, args.reverse());
|
|
2747
|
+
};
|
|
2748
|
+
}
|
|
2749
|
+
function ary(fn, n) {
|
|
2750
|
+
return function(...args) {
|
|
2751
|
+
return fn.apply(this, args.slice(0, n));
|
|
2752
|
+
};
|
|
2753
|
+
}
|
|
2754
|
+
function unary(fn) {
|
|
2755
|
+
return function(arg) {
|
|
2756
|
+
return fn.call(this, arg);
|
|
2757
|
+
};
|
|
2758
|
+
}
|
|
2759
|
+
function defer(fn, ...args) {
|
|
2760
|
+
return setTimeout(fn, 1, ...args);
|
|
2761
|
+
}
|
|
2762
|
+
function delay(fn, wait, ...args) {
|
|
2763
|
+
return setTimeout(fn, wait, ...args);
|
|
2764
|
+
}
|
|
2765
|
+
function memoizeWithTTL(fn, ttl, resolver) {
|
|
2766
|
+
const cache = /* @__PURE__ */ new Map();
|
|
2767
|
+
const memoized = function(...args) {
|
|
2768
|
+
const key = resolver ? resolver(...args) : JSON.stringify(args);
|
|
2769
|
+
const now = Date.now();
|
|
2770
|
+
const cached = cache.get(key);
|
|
2771
|
+
if (cached && cached.expires > now) {
|
|
2772
|
+
return cached.value;
|
|
2773
|
+
}
|
|
2774
|
+
const result = fn.apply(this, args);
|
|
2775
|
+
cache.set(key, { value: result, expires: now + ttl });
|
|
2776
|
+
for (const [k, v] of cache.entries()) {
|
|
2777
|
+
if (v.expires <= now) {
|
|
2778
|
+
cache.delete(k);
|
|
2779
|
+
}
|
|
2780
|
+
}
|
|
2781
|
+
return result;
|
|
2782
|
+
};
|
|
2783
|
+
memoized.cache = cache;
|
|
2784
|
+
return memoized;
|
|
2785
|
+
}
|
|
2786
|
+
function before(fn, n) {
|
|
2787
|
+
let result;
|
|
2788
|
+
let callCount = 0;
|
|
2789
|
+
return function(...args) {
|
|
2790
|
+
if (++callCount < n) {
|
|
2791
|
+
result = fn.apply(this, args);
|
|
2792
|
+
}
|
|
2793
|
+
if (callCount >= n) {
|
|
2794
|
+
fn = void 0;
|
|
2795
|
+
}
|
|
2796
|
+
return result;
|
|
2797
|
+
};
|
|
2798
|
+
}
|
|
2799
|
+
function after(fn, n) {
|
|
2800
|
+
let callCount = 0;
|
|
2801
|
+
return function(...args) {
|
|
2802
|
+
if (++callCount >= n) {
|
|
2803
|
+
return fn.apply(this, args);
|
|
2804
|
+
}
|
|
2805
|
+
return void 0;
|
|
2806
|
+
};
|
|
2807
|
+
}
|
|
2808
|
+
function tryCatch(fn, errorHandler) {
|
|
2809
|
+
return function(...args) {
|
|
2810
|
+
try {
|
|
2811
|
+
return fn.apply(this, args);
|
|
2812
|
+
} catch (error) {
|
|
2813
|
+
return errorHandler(error, ...args);
|
|
2814
|
+
}
|
|
2815
|
+
};
|
|
2816
|
+
}
|
|
2817
|
+
function flow(...fns) {
|
|
2818
|
+
return pipe(...fns);
|
|
2819
|
+
}
|
|
2820
|
+
function flowRight(...fns) {
|
|
2821
|
+
return compose(...fns);
|
|
2822
|
+
}
|
|
2823
|
+
function retry(fn, options = {}) {
|
|
2824
|
+
const { retries = 3, delay: delay2 = 1e3, backoff = 2, onRetry } = options;
|
|
2825
|
+
return async function(...args) {
|
|
2826
|
+
let lastError;
|
|
2827
|
+
let currentDelay = delay2;
|
|
2828
|
+
for (let attempt = 0; attempt <= retries; attempt++) {
|
|
2829
|
+
try {
|
|
2830
|
+
return await fn.apply(this, args);
|
|
2831
|
+
} catch (error) {
|
|
2832
|
+
lastError = error;
|
|
2833
|
+
if (attempt < retries) {
|
|
2834
|
+
if (onRetry) {
|
|
2835
|
+
onRetry(lastError, attempt + 1);
|
|
2836
|
+
}
|
|
2837
|
+
await new Promise((resolve) => setTimeout(resolve, currentDelay));
|
|
2838
|
+
currentDelay *= backoff;
|
|
2839
|
+
}
|
|
2840
|
+
}
|
|
2841
|
+
}
|
|
2842
|
+
throw lastError;
|
|
2843
|
+
};
|
|
2844
|
+
}
|
|
2845
|
+
function withTimeout(fn, timeout, onTimeout) {
|
|
2846
|
+
return async function(...args) {
|
|
2847
|
+
return Promise.race([
|
|
2848
|
+
fn.apply(this, args),
|
|
2849
|
+
new Promise(
|
|
2850
|
+
(_, reject) => setTimeout(() => {
|
|
2851
|
+
if (onTimeout) onTimeout();
|
|
2852
|
+
reject(new Error(`Function timed out after ${timeout}ms`));
|
|
2853
|
+
}, timeout)
|
|
2854
|
+
)
|
|
2855
|
+
]);
|
|
2856
|
+
};
|
|
2857
|
+
}
|