UNPKG

@react-hive/honey-utils

Version:

A lightweight TypeScript utility library providing a collection of helper functions for common programming tasks

2 lines 3.84 kB
function t(t,e){if(!t)throw new Error(e)}const e=t=>null===t,n=t=>null==t,r=t=>""===t||n(t),a=t=>null!=t,o=t=>"string"==typeof t,l=t=>"number"==typeof t,s=t=>"boolean"==typeof t,i=t=>"object"==typeof t,c=t=>i(t)&&!e(t)&&0===Object.keys(t).length,f=t=>Array.isArray(t),h=t=>f(t)&&0===t.length,u=t=>"function"==typeof t,y=t=>u(t?.then),p=t=>t instanceof Date,g=t=>p(t)&&!isNaN(t.getTime()),w=t=>t instanceof RegExp,m=t=>t instanceof Map,b=t=>t instanceof Set,M=t=>"symbol"==typeof t,d=t=>void 0===t,x=t=>l(t)&&isFinite(t),A=t=>l(t)&&Number.isInteger(t),k=t=>t.filter(Boolean),C=t=>[...new Set(t)],X=(e,n)=>(t(n>0,"Chunk size must be greater than 0"),Array.from({length:Math.ceil(e.length/n)},(t,r)=>e.slice(r*n,(r+1)*n))),Y=(...t)=>{if(0===t.length)return[];if(1===t.length)return[...t[0]];const[e,...n]=t;return C(e).filter(t=>n.every(e=>e.includes(t)))},L=(t,e)=>t.filter(t=>!e.includes(t)),R=(...t)=>e=>t.reduce((t,e)=>e(t),e),S=(...t)=>e=>t.reduceRight((t,e)=>e(t),e),$=async(t,e)=>{const n=[];for(let r=0;r<t.length;r++)n.push(await e(t[r],r,t));return n},B=async(t,e)=>Promise.all(t.map(e)),F=async(t,e)=>{const n=[];for(let r=0;r<t.length;r++){const a=t[r];await e(a,r,t)&&n.push(a)}return n},N=async(t,e)=>{const n=await B(t,async(t,n,r)=>!!await e(t,n,r)&&t);return k(n)},P=async(t,e)=>{for(let n=0;n<t.length;n++)if(await e(t[n],n,t))return!0;return!1},T=async(t,e)=>{for(let n=0;n<t.length;n++)if(!await e(t[n],n,t))return!1;return!0},j=async(t,e,n)=>{let r=n;for(let n=0;n<t.length;n++)r=await e(r,t[n],n,t);return r},v=async(t,e)=>{for(let n=0;n<t.length;n++)if(await e(t[n],n,t))return t[n];return null},z=t=>t.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),D=t=>{const e=t.charAt(0),n=t.slice(1);return e.toLowerCase()+n.replace(/[A-Z]/g,t=>`-${t.toLowerCase()}`)},E=t=>t.split(" ").filter(Boolean),O=t=>{let e=5381;for(let n=0;n<t.length;n++)e=33*e^t.charCodeAt(n);return(e>>>0).toString(36)},Z=()=>{},H=(t,...e)=>"function"==typeof t?t(...e):t,I=t=>new Promise(e=>setTimeout(e,t)),V=(t,{maxAttempts:e=3,delayMs:n=300,backoff:r=!0,onRetry:a}={})=>async(...o)=>{let l;for(let s=1;s<=e;s++)try{return await t(...o)}catch(t){if(l=t,s<e){a?.(s,t);const e=r?n*2**(s-1):n;await I(e)}}throw l},W=(t,e,n,r)=>{const a=n-t,o=r-e;return Math.hypot(a,o)},q=(t,e)=>Math.abs(t/e),G=(t,e)=>t*e/100,J=t=>{const e=window.getComputedStyle(t).getPropertyValue("transform").match(/^matrix\((.+)\)$/);if(!e)return{translateX:0,translateY:0,scaleX:1,scaleY:1,skewX:0,skewY:0};const[n,r,a,o,l,s]=e[1].split(", ").map(parseFloat);return{translateX:l,translateY:s,scaleX:n,scaleY:o,skewX:a,skewY:r}},K=t=>new Blob([t],{type:t.type}),Q=(t,e)=>new File([t],e,{type:t.type}),U=(t,e)=>Math.max(0,Math.min(t.right,e.right)-Math.max(t.left,e.left))*Math.max(0,Math.min(t.bottom,e.bottom)-Math.max(t.top,e.top))/(e.width*e.height),_=t=>new DOMRect(t.offsetLeft,t.offsetTop,t.clientWidth,t.clientHeight);export{t as assert,W as calculateEuclideanDistance,q as calculateMovingSpeed,G as calculatePercentage,D as camelToDashCase,X as chunk,K as cloneBlob,k as compact,S as compose,Q as convertBlobToFile,I as delay,L as difference,T as everyAsync,N as filterParallel,F as filterSequential,v as findAsync,U as getDOMRectIntersectionRatio,_ as getElementOffsetRect,O as hashString,Y as intersection,H as invokeIfFunction,f as isArray,s as isBool,p as isDate,a as isDefined,h as isEmptyArray,c as isEmptyObject,x as isFiniteNumber,u as isFunction,A as isInteger,m as isMap,n as isNil,r as isNilOrEmptyString,e as isNull,l as isNumber,i as isObject,y as isPromise,w as isRegExp,b as isSet,o as isString,M as isSymbol,d as isUndefined,g as isValidDate,Z as noop,J as parse2DMatrix,R as pipe,j as reduceAsync,V as retry,B as runParallel,$ as runSequential,P as someAsync,E as splitStringIntoWords,z as toKebabCase,C as unique}; //# sourceMappingURL=index.mjs.map