From f8d7b84f695b51688fcb5340fac29727bc6707cc Mon Sep 17 00:00:00 2001 From: Ray Epps Date: Sun, 11 Dec 2022 16:16:23 -0700 Subject: [PATCH] Fix return type on group function (#145) * fix type on group function --- cdn/radash.min.js | 2 +- package.json | 4 ++-- src/array.ts | 2 +- src/tests/array.test.ts | 8 ++++---- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cdn/radash.min.js b/cdn/radash.min.js index 96e6c16a..3fdfda70 100644 --- a/cdn/radash.min.js +++ b/cdn/radash.min.js @@ -1 +1 @@ -var radash=function(s){"use strict";const $=t=>!!t&&t.constructor===Symbol,N=t=>!!t&&t.constructor===Array,_=t=>!!t&&t.constructor===Object,z=t=>t==null||typeof t!="object"&&typeof t!="function",p=t=>!!(t&&t.constructor&&t.call&&t.apply),D=t=>typeof t=="string"||t instanceof String,F=t=>h(t)&&t%1===0,R=t=>h(t)&&t%1!==0,h=t=>{try{return Number(t)===t}catch{return!1}},P=t=>Object.prototype.toString.call(t)==="[object Date]",Z=t=>{if(t===!0||t===!1||t==null)return!0;if(h(t))return t===0;if(P(t))return isNaN(t.getTime());if(p(t)||$(t))return!1;const n=t.length;if(h(n))return n===0;const e=t.size;return h(e)?e===0:Object.keys(t).length===0},S=(t,n)=>{if(Object.is(t,n))return!0;if(t instanceof Date&&n instanceof Date)return t.getTime()===n.getTime();if(t instanceof RegExp&&n instanceof RegExp)return t.toString()===n.toString();if(typeof t!="object"||t===null||typeof n!="object"||n===null)return!1;const e=Reflect.ownKeys(t),r=Reflect.ownKeys(n);if(e.length!==r.length)return!1;for(let c=0;ct.reduce((e,r)=>{const c=n(r);return e[c]||(e[c]=[]),e[c].push(r),e},{});function q(...t){return!t||!t.length?[]:new Array(Math.max(...t.map(({length:n})=>n))).fill([]).map((n,e)=>t.map(r=>r[e]))}function I(t,n){if(!t||!t.length)return{};const e=p(n)?n:N(n)?(r,c)=>n[c]:(r,c)=>n;return t.reduce((r,c,i)=>({...r,[c]:e(c,i)}),{})}const b=(t,n)=>!t||(t.length??0)===0?null:t.reduce(n),U=(t,n)=>(t||[]).reduce((e,r)=>e+(n?n(r):r),0),J=(t,n=void 0)=>t?.length>0?t[0]:n,K=(t,n=void 0)=>t?.length>0?t[t.length-1]:n,T=(t,n,e=!1)=>{if(!t)return[];const r=(i,u)=>n(i)-n(u),c=(i,u)=>n(u)-n(i);return t.slice().sort(e===!0?c:r)},W=(t,n,e="asc")=>{if(!t)return[];const r=(i,u)=>`${n(i)}`.localeCompare(n(u)),c=(i,u)=>`${n(u)}`.localeCompare(n(i));return t.slice().sort(e==="desc"?c:r)},X=(t,n)=>t.reduce((e,r)=>{const c=n(r);return{...e,[c]:(e[c]??0)+1}},{}),Y=(t,n,e)=>{if(!t)return[];if(!n)return[...t];for(let r=0;rr)=>t.reduce((r,c)=>({...r,[n(c)]:e(c)}),{}),H=(t,n,e)=>t.reduce((r,c)=>e(c)?[...r,n(c)]:r,[]),Q=(t,n)=>{const e=n||(r=>r);return b(t,(r,c)=>e(r)>e(c)?r:c)},V=(t,n)=>{const e=n||(r=>r);return b(t,(r,c)=>e(r){const e=Math.ceil(t.length/n);return new Array(e).fill(null).map((r,c)=>t.slice(c*n,c*n+n))},x=(t,n)=>{const e=t.reduce((r,c)=>{const i=n?n(c):c;return r[i]?r:{...r,[i]:c}},{});return Object.values(e)};function*k(t,n,e=c=>c,r=1){const c=p(e)?e:()=>e,i=n?t:0,u=n??t;for(let o=i;o<=u&&(yield c(o),!(o+r>u));o+=r);}const A=(t,n,e,r)=>Array.from(k(t,n,e,r)),tt=t=>t.reduce((n,e)=>[...n,...e],[]),nt=(t,n,e)=>{if(!t||!n)return!1;const r=e??(i=>i),c=n.reduce((i,u)=>({...i,[r(u)]:!0}),{});return t.some(i=>c[r(i)])},j=(t,n)=>t?t.reduce((e,r)=>{const[c,i]=e;return n(r)?[[...c,r],i]:[c,[...i,r]]},[[],[]]):[[],[]],et=(t,n,e)=>!n&&!t?[]:n?t?e?t.reduce((r,c)=>{const i=n.find(u=>e(c)===e(u));return i?[...r,i]:[...r,c]},[]):t:[]:t,rt=(t,n,e)=>{if(!t&&!n)return[];if(!n)return[...t];if(!t)return[n];for(let r=0;r{if(!t&&!n)return[];if(!t)return[n];if(!n)return[...t];const c=e?(o,f)=>e(o,f)===e(n,f):o=>o===n;return t.find(c)?t.filter((o,f)=>!c(o,f)):(r?.strategy??"append")==="append"?[...t,n]:[n,...t]},st=t=>t?.filter(n=>!!n)??[],B=(t,n,e)=>{let r=e;for(let c=1;c<=t;c++)r=n(r,c);return r},it=(t,n,e=r=>r)=>{if(!t?.length&&!n?.length)return[];if(t?.length===void 0)return[...n];if(!n?.length)return[...t];const r=n.reduce((c,i)=>({...c,[e(i)]:!0}),{});return t.filter(c=>!r[e(c)])};function ut(t,n){if(t.length===0)return t;const e=n%t.length;return e===0?t:[...t.slice(-e,t.length),...t.slice(0,-e)]}const ot=async(t,n,e)=>{const r=e!==void 0;if(!r&&t?.length<1)throw new Error("Cannot reduce empty array with no init value");const c=r?t:t.slice(1);let i=r?e:t[0];for(const u of c)i=await n(i,u);return i},lt=async(t,n)=>{if(!t)return[];let e=[],r=0;for(const c of t){const i=await n(c,r++);e.push(i)}return e},ft=async t=>{const n=[],e=(i,u)=>n.push({fn:i,rethrow:u?.rethrow??!1}),[r,c]=await m(t)(e);for(const{fn:i,rethrow:u}of n){const[o]=await m(i)(r);if(u)throw o}if(r)throw r;return c};class at extends Error{constructor(n=[]){super();const e=n.find(r=>r.name)?.name??"";this.name=`AggregateError(${e}...)`,this.message=`AggregateError with ${n.length} errors`,this.stack=n.find(r=>r.stack)?.stack??this.stack,this.errors=n}}const dt=async(t,n,e)=>{const r=n.map((a,y)=>({index:y,item:a})),c=async a=>{const y=[];for(;;){const l=r.pop();if(!l)return a(y);const[d,g]=await m(e)(l.item);y.push({error:d,result:g,index:l.index})}},i=A(1,t).map(()=>new Promise(c)),u=await Promise.all(i),[o,f]=j(T(u.flat(),a=>a.index),a=>!!a.error);if(o.length>0)throw new at(o.map(a=>a.error));return f.map(a=>a.result)},gt=async(t,n)=>{const e=t?.times??3,r=t?.delay,c=t?.backoff??null;for(const i of k(1,e)){const[u,o]=await m(n)(f=>{throw{_exited:f}});if(!u)return o;if(u._exited)throw u._exited;if(i===e)throw u;r&&await O(r),c&&await O(c(i))}},O=t=>new Promise(n=>setTimeout(n,t)),m=t=>async(...n)=>{try{return[null,await t(...n)]}catch(e){return[e,null]}},ht=(...t)=>(...n)=>t.slice(1).reduce((e,r)=>r(e),t[0](...n)),mt=(...t)=>t.reverse().reduce((n,e)=>e(n)),wt=(t,...n)=>(...e)=>t(...n,...e),yt=(t,n)=>e=>t({...n,...e}),pt=t=>new Proxy({},{get:(n,e)=>t(e)}),bt=(t,n,e,r)=>function(...i){const u=e?e(...i):JSON.stringify({args:i}),o=t[u];if(o!==void 0&&o.exp>new Date().getTime())return o.value;const f=n(...i);return t[u]={exp:new Date().getTime()+r,value:f},f},kt=(t,{key:n=null,ttl:e=300}={})=>bt({},t,n,e),At=({delay:t},n)=>{let e=null;return(...c)=>{clearTimeout(e),e=setTimeout(()=>n(...c),t)}},Ot=({interval:t},n)=>{let e=!0;return(...c)=>{!e||(n(...c),e=!1,setTimeout(()=>{e=!0},t))}},Ct=(t,n)=>{const e=()=>{};return new Proxy(Object.assign(e,t),{get:(r,c)=>r[c],set:(r,c,i)=>(r[c]=i,!0),apply:(r,c,i)=>n(Object.assign({},r))(...i)})},Et=(t,n)=>{const e=n===void 0?0:n;if(t==null)return e;const r=parseFloat(t);return isNaN(r)?e:r},$t=(t,n)=>{const e=n===void 0?0:n;if(t==null)return e;const r=parseInt(t);return isNaN(r)?e:r},Nt=(t,n=e=>e===void 0)=>t?Object.keys(t).reduce((r,c)=>n(t[c])?r:{...r,[c]:t[c]},{}):{},C=(t,n)=>Object.keys(t).reduce((r,c)=>({...r,[n(c,t[c])]:t[c]}),{}),_t=(t,n)=>Object.keys(t).reduce((r,c)=>({...r,[c]:n(t[c],c)}),{}),zt=(t,n)=>t?Object.entries(t).reduce((e,[r,c])=>{const[i,u]=n(r,c);return{...e,[i]:u}},{}):{},Pt=t=>t?Object.keys(t).reduce((e,r)=>({...e,[t[r]]:r}),{}):{},St=t=>C(t,n=>n.toLowerCase()),Tt=t=>C(t,n=>n.toUpperCase()),jt=t=>{if(z(t))return t;if(typeof t=="function")return t.bind({});const n=new t.constructor;return Object.getOwnPropertyNames(t).forEach(e=>{n[e]=t[e]}),n},Bt=(t,n)=>{if(!t)return[];const e=Object.entries(t);return e.length===0?[]:e.reduce((r,c)=>[...r,n(c[0],c[1])],[])},Lt=(t,n)=>t?n.reduce((e,r)=>(t.hasOwnProperty(r)&&(e[r]=t[r]),e),{}):{},Dt=(t,n)=>t?!n||n.length===0?t:n.reduce((e,r)=>(delete e[r],e),{...t}):{},Ft=(t,n,e=null)=>{const r=n.split(/[\.\[\]]/g);let c=t;for(const i of r){if(c===null||c===void 0)return e;i.trim()!==""&&(c=c[i])}return c===void 0?e:c},L=(t,n)=>!t&&!n?{}:t?n?Object.entries(t).reduce((e,[r,c])=>({...e,[r]:(()=>_(c)?L(c,n[r]):n[r])()}),{}):t:n,E=(t,n)=>Math.floor(Math.random()*(n-t+1)+t),Rt=t=>{const n=t.length;if(n===0)return null;const e=E(0,n-1);return t[e]},Zt=t=>t.map(n=>({rand:Math.random(),value:n})).sort((n,e)=>n.rand-e.rand).map(n=>n.value),Mt=(t,n="")=>{const e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"+n;return B(t,r=>r+e.charAt(E(0,e.length-1)),"")},qt=(t,n=e=>`${e}`)=>{const{indexesByKey:e,itemsByIndex:r}=t.reduce((l,d,g)=>({indexesByKey:{...l.indexesByKey,[n(d)]:g},itemsByIndex:{...l.itemsByIndex,[g]:d}}),{indexesByKey:{},itemsByIndex:{}}),c=(l,d)=>e[n(l)]e[n(l)]>e[n(d)]?l:d,u=()=>r[0],o=()=>r[t.length-1],f=l=>r[e[n(l)]+1]??u(),a=l=>r[e[n(l)]-1]??o();return{min:c,max:i,first:u,last:o,next:f,previous:a,spin:(l,d)=>{if(d===0)return l;const g=Math.abs(d),Gt=g>t.length?g%t.length:g;return A(0,Gt-1).reduce(d>0?f:a,l)}}},w=t=>{if(!t||t.length===0)return"";const n=t.toLowerCase();return n.substring(0,1).toUpperCase()+n.substring(1,n.length)},It=t=>{const n=t?.replace(/([A-Z])+/g,w)?.split(/(?=[A-Z])|[\.\-\s_]/).map(e=>e.toLowerCase())??[];return n.length===0?"":n.length===1?n[0]:n.reduce((e,r)=>`${e}${r.charAt(0).toUpperCase()}${r.slice(1)}`)},Ut=t=>{const n=t?.replace(/([A-Z])+/g,w).split(/(?=[A-Z])|[\.\-\s_]/).map(e=>e.toLowerCase())??[];return n.length===0?"":n.length===1?n[0]:n.reduce((e,r)=>`${e}_${r.toLowerCase()}`)},Jt=t=>{const n=t?.replace(/([A-Z])+/g,w)?.split(/(?=[A-Z])|[\.\-\s_]/).map(e=>e.toLowerCase())??[];return n.length===0?"":n.length===1?n[0]:n.reduce((e,r)=>`${e}-${r.toLowerCase()}`)},Kt=t=>{const n=t?.split(/[\.\-\s_]/).map(e=>e.toLowerCase())??[];return n.length===0?"":n.map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join("")},Wt=t=>t?t.split(/(?=[A-Z])|[\.\-\s_]/).map(n=>n.trim()).filter(n=>!!n).map(n=>w(n.toLowerCase())).join(" "):"",Xt=(t,n,e=/\{\{(.+?)\}\}/g)=>Array.from(t.matchAll(e)).reduce((r,c)=>r.replace(c[0],n[c[1]]),t),Yt=(t,n=" ")=>{if(!t)return"";const e=new RegExp(`^[${n}]+|[${n}]+$`,"g");return t.replace(e,"")};return s.alphabetical=W,s.assign=L,s.boil=b,s.callable=Ct,s.camel=It,s.capitalize=w,s.chain=ht,s.clone=jt,s.cluster=v,s.compose=mt,s.counting=X,s.dash=Jt,s.debounce=At,s.defer=ft,s.diff=it,s.draw=Rt,s.first=J,s.flat=tt,s.fork=j,s.get=Ft,s.group=M,s.intersects=nt,s.invert=Pt,s.isArray=N,s.isDate=P,s.isEmpty=Z,s.isEqual=S,s.isFloat=R,s.isFunction=p,s.isInt=F,s.isNumber=h,s.isObject=_,s.isPrimitive=z,s.isString=D,s.isSymbol=$,s.iterate=B,s.last=K,s.list=A,s.listify=Bt,s.lowerize=St,s.map=lt,s.mapEntries=zt,s.mapKeys=C,s.mapValues=_t,s.max=Q,s.memo=kt,s.merge=et,s.min=V,s.objectify=G,s.omit=Dt,s.parallel=dt,s.partial=wt,s.partob=yt,s.pascal=Kt,s.pick=Lt,s.proxied=pt,s.random=E,s.range=k,s.reduce=ot,s.replace=Y,s.replaceOrAppend=rt,s.retry=gt,s.select=H,s.series=qt,s.shake=Nt,s.shift=ut,s.shuffle=Zt,s.sift=st,s.sleep=O,s.snake=Ut,s.sort=T,s.sum=U,s.template=Xt,s.throttle=Ot,s.title=Wt,s.toFloat=Et,s.toInt=$t,s.toggle=ct,s.trim=Yt,s.try=m,s.tryit=m,s.uid=Mt,s.unique=x,s.upperize=Tt,s.zip=q,s.zipToObject=I,s}({}); +var radash=function(i){"use strict";const $=t=>!!t&&t.constructor===Symbol,N=t=>!!t&&t.constructor===Array,_=t=>!!t&&t.constructor===Object,z=t=>t==null||typeof t!="object"&&typeof t!="function",p=t=>!!(t&&t.constructor&&t.call&&t.apply),D=t=>typeof t=="string"||t instanceof String,F=t=>h(t)&&t%1===0,R=t=>h(t)&&t%1!==0,h=t=>{try{return Number(t)===t}catch{return!1}},P=t=>Object.prototype.toString.call(t)==="[object Date]",Z=t=>{if(t===!0||t===!1||t==null)return!0;if(h(t))return t===0;if(P(t))return isNaN(t.getTime());if(p(t)||$(t))return!1;const e=t.length;if(h(e))return e===0;const n=t.size;return h(n)?n===0:Object.keys(t).length===0},S=(t,e)=>{if(Object.is(t,e))return!0;if(t instanceof Date&&e instanceof Date)return t.getTime()===e.getTime();if(t instanceof RegExp&&e instanceof RegExp)return t.toString()===e.toString();if(typeof t!="object"||t===null||typeof e!="object"||e===null)return!1;const n=Reflect.ownKeys(t),r=Reflect.ownKeys(e);if(n.length!==r.length)return!1;for(let c=0;ct.reduce((n,r)=>{const c=e(r);return n[c]||(n[c]=[]),n[c].push(r),n},{});function q(...t){return!t||!t.length?[]:new Array(Math.max(...t.map(({length:e})=>e))).fill([]).map((e,n)=>t.map(r=>r[n]))}function I(t,e){if(!t||!t.length)return{};const n=p(e)?e:N(e)?(r,c)=>e[c]:(r,c)=>e;return t.reduce((r,c,s)=>({...r,[c]:n(c,s)}),{})}const b=(t,e)=>!t||(t.length??0)===0?null:t.reduce(e),U=(t,e)=>(t||[]).reduce((n,r)=>n+(e?e(r):r),0),J=(t,e=void 0)=>t?.length>0?t[0]:e,K=(t,e=void 0)=>t?.length>0?t[t.length-1]:e,T=(t,e,n=!1)=>{if(!t)return[];const r=(s,u)=>e(s)-e(u),c=(s,u)=>e(u)-e(s);return t.slice().sort(n===!0?c:r)},W=(t,e,n="asc")=>{if(!t)return[];const r=(s,u)=>`${e(s)}`.localeCompare(e(u)),c=(s,u)=>`${e(u)}`.localeCompare(e(s));return t.slice().sort(n==="desc"?c:r)},X=(t,e)=>t.reduce((n,r)=>{const c=e(r);return{...n,[c]:(n[c]??0)+1}},{}),Y=(t,e,n)=>{if(!t)return[];if(!e)return[...t];for(let r=0;rr)=>t.reduce((r,c)=>({...r,[e(c)]:n(c)}),{}),H=(t,e,n)=>t.reduce((r,c)=>n(c)?[...r,e(c)]:r,[]),Q=(t,e)=>{const n=e||(r=>r);return b(t,(r,c)=>n(r)>n(c)?r:c)},V=(t,e)=>{const n=e||(r=>r);return b(t,(r,c)=>n(r){const n=Math.ceil(t.length/e);return new Array(n).fill(null).map((r,c)=>t.slice(c*e,c*e+e))},x=(t,e)=>{const n=t.reduce((r,c)=>{const s=e?e(c):c;return r[s]?r:{...r,[s]:c}},{});return Object.values(n)};function*k(t,e,n=c=>c,r=1){const c=p(n)?n:()=>n,s=e?t:0,u=e??t;for(let o=s;o<=u&&(yield c(o),!(o+r>u));o+=r);}const A=(t,e,n,r)=>Array.from(k(t,e,n,r)),tt=t=>t.reduce((e,n)=>[...e,...n],[]),et=(t,e,n)=>{if(!t||!e)return!1;const r=n??(s=>s),c=e.reduce((s,u)=>({...s,[r(u)]:!0}),{});return t.some(s=>c[r(s)])},j=(t,e)=>t?t.reduce((n,r)=>{const[c,s]=n;return e(r)?[[...c,r],s]:[c,[...s,r]]},[[],[]]):[[],[]],nt=(t,e,n)=>!e&&!t?[]:e?t?n?t.reduce((r,c)=>{const s=e.find(u=>n(c)===n(u));return s?[...r,s]:[...r,c]},[]):t:[]:t,rt=(t,e,n)=>{if(!t&&!e)return[];if(!e)return[...t];if(!t)return[e];for(let r=0;r{if(!t&&!e)return[];if(!t)return[e];if(!e)return[...t];const c=n?(o,f)=>n(o,f)===n(e,f):o=>o===e;return t.find(c)?t.filter((o,f)=>!c(o,f)):(r?.strategy??"append")==="append"?[...t,e]:[e,...t]},it=t=>t?.filter(e=>!!e)??[],B=(t,e,n)=>{let r=n;for(let c=1;c<=t;c++)r=e(r,c);return r},st=(t,e,n=r=>r)=>{if(!t?.length&&!e?.length)return[];if(t?.length===void 0)return[...e];if(!e?.length)return[...t];const r=e.reduce((c,s)=>({...c,[n(s)]:!0}),{});return t.filter(c=>!r[n(c)])};function ut(t,e){if(t.length===0)return t;const n=e%t.length;return n===0?t:[...t.slice(-n,t.length),...t.slice(0,-n)]}const ot=async(t,e,n)=>{const r=n!==void 0;if(!r&&t?.length<1)throw new Error("Cannot reduce empty array with no init value");const c=r?t:t.slice(1);let s=r?n:t[0];for(const u of c)s=await e(s,u);return s},lt=async(t,e)=>{if(!t)return[];let n=[],r=0;for(const c of t){const s=await e(c,r++);n.push(s)}return n},ft=async t=>{const e=[],n=(s,u)=>e.push({fn:s,rethrow:u?.rethrow??!1}),[r,c]=await m(t)(n);for(const{fn:s,rethrow:u}of e){const[o]=await m(s)(r);if(u)throw o}if(r)throw r;return c};class at extends Error{constructor(e=[]){super();const n=e.find(r=>r.name)?.name??"";this.name=`AggregateError(${n}...)`,this.message=`AggregateError with ${e.length} errors`,this.stack=e.find(r=>r.stack)?.stack??this.stack,this.errors=e}}const dt=async(t,e,n)=>{const r=e.map((a,y)=>({index:y,item:a})),c=async a=>{const y=[];for(;;){const l=r.pop();if(!l)return a(y);const[d,g]=await m(n)(l.item);y.push({error:d,result:g,index:l.index})}},s=A(1,t).map(()=>new Promise(c)),u=await Promise.all(s),[o,f]=j(T(u.flat(),a=>a.index),a=>!!a.error);if(o.length>0)throw new at(o.map(a=>a.error));return f.map(a=>a.result)},gt=async(t,e)=>{const n=t?.times??3,r=t?.delay,c=t?.backoff??null;for(const s of k(1,n)){const[u,o]=await m(e)(f=>{throw{_exited:f}});if(!u)return o;if(u._exited)throw u._exited;if(s===n)throw u;r&&await O(r),c&&await O(c(s))}},O=t=>new Promise(e=>setTimeout(e,t)),m=t=>async(...e)=>{try{return[void 0,await t(...e)]}catch(n){return[n,void 0]}},ht=(...t)=>(...e)=>t.slice(1).reduce((n,r)=>r(n),t[0](...e)),mt=(...t)=>t.reverse().reduce((e,n)=>n(e)),wt=(t,...e)=>(...n)=>t(...e,...n),yt=(t,e)=>n=>t({...e,...n}),pt=t=>new Proxy({},{get:(e,n)=>t(n)}),bt=(t,e,n,r)=>function(...s){const u=n?n(...s):JSON.stringify({args:s}),o=t[u];if(o!==void 0&&o.exp>new Date().getTime())return o.value;const f=e(...s);return t[u]={exp:new Date().getTime()+r,value:f},f},kt=(t,{key:e=null,ttl:n=300}={})=>bt({},t,e,n),At=({delay:t},e)=>{let n=null;return(...c)=>{clearTimeout(n),n=setTimeout(()=>e(...c),t)}},Ot=({interval:t},e)=>{let n=!0;return(...c)=>{!n||(e(...c),n=!1,setTimeout(()=>{n=!0},t))}},Ct=(t,e)=>{const n=()=>{};return new Proxy(Object.assign(n,t),{get:(r,c)=>r[c],set:(r,c,s)=>(r[c]=s,!0),apply:(r,c,s)=>e(Object.assign({},r))(...s)})},Et=(t,e)=>{const n=e===void 0?0:e;if(t==null)return n;const r=parseFloat(t);return isNaN(r)?n:r},$t=(t,e)=>{const n=e===void 0?0:e;if(t==null)return n;const r=parseInt(t);return isNaN(r)?n:r},Nt=(t,e=n=>n===void 0)=>t?Object.keys(t).reduce((r,c)=>e(t[c])?r:{...r,[c]:t[c]},{}):{},C=(t,e)=>Object.keys(t).reduce((r,c)=>({...r,[e(c,t[c])]:t[c]}),{}),_t=(t,e)=>Object.keys(t).reduce((r,c)=>({...r,[c]:e(t[c],c)}),{}),zt=(t,e)=>t?Object.entries(t).reduce((n,[r,c])=>{const[s,u]=e(r,c);return{...n,[s]:u}},{}):{},Pt=t=>t?Object.keys(t).reduce((n,r)=>({...n,[t[r]]:r}),{}):{},St=t=>C(t,e=>e.toLowerCase()),Tt=t=>C(t,e=>e.toUpperCase()),jt=t=>{if(z(t))return t;if(typeof t=="function")return t.bind({});const e=new t.constructor;return Object.getOwnPropertyNames(t).forEach(n=>{e[n]=t[n]}),e},Bt=(t,e)=>{if(!t)return[];const n=Object.entries(t);return n.length===0?[]:n.reduce((r,c)=>[...r,e(c[0],c[1])],[])},Lt=(t,e)=>t?e.reduce((n,r)=>(t.hasOwnProperty(r)&&(n[r]=t[r]),n),{}):{},Dt=(t,e)=>t?!e||e.length===0?t:e.reduce((n,r)=>(delete n[r],n),{...t}):{},Ft=(t,e,n=null)=>{const r=e.split(/[\.\[\]]/g);let c=t;for(const s of r){if(c===null||c===void 0)return n;s.trim()!==""&&(c=c[s])}return c===void 0?n:c},L=(t,e)=>!t&&!e?{}:t?e?Object.entries(t).reduce((n,[r,c])=>({...n,[r]:(()=>_(c)?L(c,e[r]):e[r])()}),{}):t:e,E=(t,e)=>Math.floor(Math.random()*(e-t+1)+t),Rt=t=>{const e=t.length;if(e===0)return null;const n=E(0,e-1);return t[n]},Zt=t=>t.map(e=>({rand:Math.random(),value:e})).sort((e,n)=>e.rand-n.rand).map(e=>e.value),Mt=(t,e="")=>{const n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"+e;return B(t,r=>r+n.charAt(E(0,n.length-1)),"")},qt=(t,e=n=>`${n}`)=>{const{indexesByKey:n,itemsByIndex:r}=t.reduce((l,d,g)=>({indexesByKey:{...l.indexesByKey,[e(d)]:g},itemsByIndex:{...l.itemsByIndex,[g]:d}}),{indexesByKey:{},itemsByIndex:{}}),c=(l,d)=>n[e(l)]n[e(l)]>n[e(d)]?l:d,u=()=>r[0],o=()=>r[t.length-1],f=l=>r[n[e(l)]+1]??u(),a=l=>r[n[e(l)]-1]??o();return{min:c,max:s,first:u,last:o,next:f,previous:a,spin:(l,d)=>{if(d===0)return l;const g=Math.abs(d),Gt=g>t.length?g%t.length:g;return A(0,Gt-1).reduce(d>0?f:a,l)}}},w=t=>{if(!t||t.length===0)return"";const e=t.toLowerCase();return e.substring(0,1).toUpperCase()+e.substring(1,e.length)},It=t=>{const e=t?.replace(/([A-Z])+/g,w)?.split(/(?=[A-Z])|[\.\-\s_]/).map(n=>n.toLowerCase())??[];return e.length===0?"":e.length===1?e[0]:e.reduce((n,r)=>`${n}${r.charAt(0).toUpperCase()}${r.slice(1)}`)},Ut=t=>{const e=t?.replace(/([A-Z])+/g,w).split(/(?=[A-Z])|[\.\-\s_]/).map(n=>n.toLowerCase())??[];return e.length===0?"":e.length===1?e[0]:e.reduce((n,r)=>`${n}_${r.toLowerCase()}`)},Jt=t=>{const e=t?.replace(/([A-Z])+/g,w)?.split(/(?=[A-Z])|[\.\-\s_]/).map(n=>n.toLowerCase())??[];return e.length===0?"":e.length===1?e[0]:e.reduce((n,r)=>`${n}-${r.toLowerCase()}`)},Kt=t=>{const e=t?.split(/[\.\-\s_]/).map(n=>n.toLowerCase())??[];return e.length===0?"":e.map(n=>n.charAt(0).toUpperCase()+n.slice(1)).join("")},Wt=t=>t?t.split(/(?=[A-Z])|[\.\-\s_]/).map(e=>e.trim()).filter(e=>!!e).map(e=>w(e.toLowerCase())).join(" "):"",Xt=(t,e,n=/\{\{(.+?)\}\}/g)=>Array.from(t.matchAll(n)).reduce((r,c)=>r.replace(c[0],e[c[1]]),t),Yt=(t,e=" ")=>{if(!t)return"";const n=new RegExp(`^[${e}]+|[${e}]+$`,"g");return t.replace(n,"")};return i.alphabetical=W,i.assign=L,i.boil=b,i.callable=Ct,i.camel=It,i.capitalize=w,i.chain=ht,i.clone=jt,i.cluster=v,i.compose=mt,i.counting=X,i.dash=Jt,i.debounce=At,i.defer=ft,i.diff=st,i.draw=Rt,i.first=J,i.flat=tt,i.fork=j,i.get=Ft,i.group=M,i.intersects=et,i.invert=Pt,i.isArray=N,i.isDate=P,i.isEmpty=Z,i.isEqual=S,i.isFloat=R,i.isFunction=p,i.isInt=F,i.isNumber=h,i.isObject=_,i.isPrimitive=z,i.isString=D,i.isSymbol=$,i.iterate=B,i.last=K,i.list=A,i.listify=Bt,i.lowerize=St,i.map=lt,i.mapEntries=zt,i.mapKeys=C,i.mapValues=_t,i.max=Q,i.memo=kt,i.merge=nt,i.min=V,i.objectify=G,i.omit=Dt,i.parallel=dt,i.partial=wt,i.partob=yt,i.pascal=Kt,i.pick=Lt,i.proxied=pt,i.random=E,i.range=k,i.reduce=ot,i.replace=Y,i.replaceOrAppend=rt,i.retry=gt,i.select=H,i.series=qt,i.shake=Nt,i.shift=ut,i.shuffle=Zt,i.sift=it,i.sleep=O,i.snake=Ut,i.sort=T,i.sum=U,i.template=Xt,i.throttle=Ot,i.title=Wt,i.toFloat=Et,i.toInt=$t,i.toggle=ct,i.trim=Yt,i.try=m,i.tryit=m,i.uid=Mt,i.unique=x,i.upperize=Tt,i.zip=q,i.zipToObject=I,i}({}); diff --git a/package.json b/package.json index 89fa781c..545d3805 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "radash", - "version": "9.5.0", + "version": "10.0.0", "description": "Functional utility library - modern, simple, typed, powerful", "main": "dist/cjs/index.cjs", "module": "dist/esm/index.mjs", @@ -48,4 +48,4 @@ "engines": { "node": ">=14.18.0" } -} +} \ No newline at end of file diff --git a/src/array.ts b/src/array.ts index 91190011..88a7d68b 100644 --- a/src/array.ts +++ b/src/array.ts @@ -8,7 +8,7 @@ import { isArray, isFunction } from './typed' export const group = ( array: readonly T[], getGroupId: (item: T) => Key -) => { +): Partial> => { return array.reduce((acc, item) => { const groupId = getGroupId(item) if (!acc[groupId]) acc[groupId] = [] diff --git a/src/tests/array.test.ts b/src/tests/array.test.ts index 799d3780..7ad6f754 100644 --- a/src/tests/array.test.ts +++ b/src/tests/array.test.ts @@ -14,10 +14,10 @@ describe('array module', () => { { group: 'c', word: 'ok' } ] const groups = _.group(list, x => x.group) - assert.equal(groups.a.length, 2) - assert.equal(groups.b.length, 2) - assert.equal(groups.c.length, 1) - assert.equal(groups.c[0].word, 'ok') + assert.equal(groups.a?.length, 2) + assert.equal(groups.b?.length, 2) + assert.equal(groups.c?.length, 1) + assert.equal(groups.c?.[0].word, 'ok') }) })