UNPKG

@react-hive/honey-utils

Version:

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

2 lines 8.25 kB
var e={};function t(e,t){if(!e)throw new Error(t)}e.d=(t,n)=>{for(var r in n)e.o(n,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:n[r]})},e.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);const n=e=>null===e,r=e=>null==e,i=e=>null!=e,a=e=>void 0===e,o=e=>"number"==typeof e,l=e=>"boolean"==typeof e,s=e=>"object"==typeof e,c=e=>s(e)&&!n(e)&&0===Object.keys(e).length,f=e=>e instanceof Date,u=e=>e instanceof Blob,h=e=>e instanceof Error,m=e=>f(e)&&!isNaN(e.getTime()),y=e=>e instanceof RegExp,w=e=>e instanceof Map,d=e=>e instanceof Set,g=e=>"symbol"==typeof e,p=e=>o(e)&&isFinite(e),b=e=>o(e)&&Number.isInteger(e),S=e=>p(e)&&!Number.isInteger(e),x=e=>Array.isArray(e),A=e=>x(e)&&0===e.length,M=e=>e.filter(Boolean),O=e=>[...new Set(e)],k=(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))),v=(...e)=>{if(0===e.length)return[];if(1===e.length)return[...e[0]];const[t,...n]=e;return O(t).filter(e=>n.every(t=>t.includes(e)))},E=(e,t)=>e.filter(e=>!t.includes(e)),_=(...e)=>t=>e.reduce((e,t)=>t(e),t),P=(...e)=>t=>e.reduceRight((e,t)=>t(e),t),T=()=>{},z=e=>"function"==typeof e,L=e=>(...t)=>!e(...t),C=(e,...t)=>"function"==typeof e?e(...t):e,R=e=>new Promise(t=>setTimeout(t,e)),N=async(e,t,n="Operation timed out")=>{try{return await Promise.race([e,R(t).then(()=>Promise.reject(new Error(n)))])}finally{}},j=(e,{maxAttempts:t=3,delayMs:n=300,backoff:r=!0,onRetry:i}={})=>async(...a)=>{let o;for(let l=1;l<=t;l++)try{return await e(...a)}catch(e){if(o=e,l<t){i?.(l,e);const t=r?n*2**(l-1):n;await R(t)}}throw o},F=e=>{let t,n=!1;return function(...r){return n||(n=!0,t=e.apply(this,r)),t}},I=e=>z(e?.then),X=async(e,t)=>{const n=[];for(let r=0;r<e.length;r++)n.push(await t(e[r],r,e));return n},$=async(e,t)=>Promise.all(e.map(t)),H=async(e,t)=>{const n=[];for(let r=0;r<e.length;r++){const i=e[r];await t(i,r,e)&&n.push(i)}return n},U=async(e,t)=>{const n=await $(e,async(e,n,r)=>!!await t(e,n,r)&&e);return M(n)},W=async(e,t)=>{for(let n=0;n<e.length;n++)if(await t(e[n],n,e))return!0;return!1},Y=async(e,t)=>{for(let n=0;n<e.length;n++)if(!await t(e[n],n,e))return!1;return!0},B=async(e,t,n)=>{let r=n;for(let n=0;n<e.length;n++)r=await t(r,e[n],n,e);return r},D=async(e,t)=>{for(let n=0;n<e.length;n++)if(await t(e[n],n,e))return e[n];return null},Z=e=>"string"==typeof e,G=e=>""===e||r(e),V=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),q=e=>{const t=e.charAt(0),n=e.slice(1);return t.toLowerCase()+n.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`)},J=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1 $2"),K=e=>e.split(" ").filter(Boolean),Q=e=>{let t=5381;for(let n=0;n<e.length;n++)t=33*t^e.charCodeAt(n);return(t>>>0).toString(36)},ee=(e,t,n,r)=>{const i=n-e,a=r-t;return Math.hypot(i,a)},te=(e,t)=>Math.abs(e/t),ne=(e,t)=>e*t/100,re=["INPUT","SELECT","TEXTAREA","BUTTON","A"],ie=e=>{const t=window.getComputedStyle(e).getPropertyValue("transform").match(/^matrix\((.+)\)$/);if(!t)return{translateX:0,translateY:0,scaleX:1,scaleY:1,skewX:0,skewY:0};const[n,r,i,a,o,l]=t[1].split(", ").map(parseFloat);return{translateX:o,translateY:l,scaleX:n,scaleY:a,skewX:i,skewY:r}},ae=e=>new Blob([e],{type:e.type}),oe=(e,t)=>Math.max(0,Math.min(e.right,t.right)-Math.max(e.left,t.left))*Math.max(0,Math.min(e.bottom,t.bottom)-Math.max(e.top,t.top))/(t.width*t.height),le=e=>new DOMRect(e.offsetLeft,e.offsetTop,e.clientWidth,e.clientHeight),se=e=>"A"===e.tagName,ce=e=>"true"===e.getAttribute("contenteditable"),fe=e=>{if(!e)return!1;const t=window.getComputedStyle(e);if("hidden"===t.visibility||"none"===t.display)return!1;if("disabled"in e&&e.disabled)return!1;const n=e.getAttribute("tabindex");return"-1"!==n&&(re.includes(e.tagName)?!se(e)||""!==e.href:!!ce(e)||null!==n)},ue=e=>Array.from(e.querySelectorAll("*")).filter(fe),he=(e,t=null,{wrap:n=!0,getNextIndex:r}={})=>{const i=document.activeElement,a=t??i?.parentElement;if(!i||!a)return;const o=ue(a);if(0===o.length)return;const l=o.indexOf(i);if(-1===l)return;let s;r?s=r(l,e,o):"next"===e?(s=l+1,s>=o.length&&(s=n?0:null)):(s=l-1,s<0&&(s=n?o.length-1:null)),null!==s&&o[s]?.focus()},me=e=>e.scrollWidth>e.clientWidth,ye=e=>Math.max(0,e.scrollWidth-e.clientWidth),we=e=>e.scrollHeight>e.clientHeight,de=e=>Math.max(0,e.scrollHeight-e.clientHeight),ge=({overflowSize:e,containerSize:t,elementOffset:n,elementSize:r})=>{if(e<=0)return 0;const i=n+r/2-t/2;return-Math.max(0,Math.min(i,e))},pe=(e,t,{axis:n="both"}={})=>{let r=0,i=0;"x"!==n&&"both"!==n||(r=ge({overflowSize:ye(e),containerSize:e.clientWidth,elementOffset:t.offsetLeft,elementSize:t.clientWidth})),"y"!==n&&"both"!==n||(i=ge({overflowSize:de(e),containerSize:e.clientHeight,elementOffset:t.offsetTop,elementSize:t.clientHeight})),e.style.transform=`translate(${r}px, ${i}px)`},be=()=>{if("undefined"==typeof window||!window.localStorage)return!1;try{return window.localStorage.getItem("__non_existing_key__"),!0}catch{return!1}},Se=()=>{if(!be())return{readable:!1,writable:!1};try{const e="__test_write__";return window.localStorage.setItem(e,"1"),window.localStorage.removeItem(e),{readable:!0,writable:!0}}catch{}return{readable:!0,writable:!1}},xe=(e,{fileName:n,target:r}={})=>{if(a(document))return;const i=document.createElement("a");let o=null;try{const t=Z(e)?e:o=URL.createObjectURL(e);i.href=t,n&&(i.download=n),r&&(i.target=r),document.body.appendChild(i),i.click()}finally{i.remove(),o&&setTimeout(()=>{t(o,"Object URL should not be null"),URL.revokeObjectURL(o)},0)}},Ae=e=>e instanceof File,Me=e=>{const t=e.lastIndexOf(".");return t<=0||t===e.length-1?[e,""]:[e.slice(0,t),e.slice(t+1).toLowerCase()]},Oe=e=>{if(!e)return[];const t=[];for(let n=0;n<e.length;n++)t.push(e[n]);return t},ke=(e,t)=>new File([e],t,{type:e.type}),ve=async(e,{skipFiles:t=[".DS_Store","Thumbs.db","desktop.ini","ehthumbs.db",".Spotlight-V100",".Trashes",".fseventsd","__MACOSX"]}={})=>{const n=new Set(t),r=await(async e=>{const t=e.createReader(),n=async()=>new Promise((e,r)=>{t.readEntries(async t=>{if(t.length)try{const r=await n();e([...t,...r])}catch(e){r(e)}else e([])},r)});return n()})(e);return(await $(r,async e=>e.isDirectory?ve(e,{skipFiles:t}):n.has(e.name)?[]:[await new Promise((t,n)=>{e.file(t,n)})])).flat()},Ee=async(e,t={})=>{const n=e?.items;if(!n)return[];const r=[];for(let e=0;e<n.length;e++){const i=n[e];if("webkitGetAsEntry"in i){const e=i.webkitGetAsEntry?.();if(e?.isDirectory){r.push(ve(e,t));continue}if(e?.isFile){r.push(new Promise((t,n)=>e.file(e=>t([e]),n)));continue}}const a=i.getAsFile();a&&r.push(Promise.resolve([a]))}return(await Promise.all(r)).flat()},_e=e=>Object.entries(e).reduce((e,[t,n])=>(void 0!==n&&(e[t]=n),e),{});export{re as FOCUSABLE_HTML_TAGS,t as assert,ke as blobToFile,ge as calculateCenterOffset,ee as calculateEuclideanDistance,te as calculateMovingSpeed,ne as calculatePercentage,q as camelToDashCase,J as camelToWords,pe as centerElementInContainer,k as chunk,ae as cloneBlob,M as compact,P as compose,_e as definedProps,R as delay,E as difference,xe as downloadFile,Y as everyAsync,Oe as fileListToFiles,U as filterParallel,H as filterSequential,D as findAsync,oe as getDOMRectIntersectionRatio,le as getElementOffsetRect,ue as getFocusableHtmlElements,Se as getLocalStorageCapabilities,ye as getXOverflowWidth,de as getYOverflowHeight,me as hasXOverflow,we as hasYOverflow,Q as hashString,v as intersection,C as invokeIfFunction,se as isAnchorHtmlElement,x as isArray,u as isBlob,l as isBool,ce as isContentEditableHtmlElement,f as isDate,S as isDecimal,i as isDefined,A as isEmptyArray,c as isEmptyObject,h as isError,Ae as isFile,p as isFiniteNumber,z as isFunction,fe as isHtmlElementFocusable,b as isInteger,be as isLocalStorageReadable,w as isMap,r as isNil,G as isNilOrEmptyString,n as isNull,o as isNumber,s as isObject,I as isPromise,y as isRegExp,d as isSet,Z as isString,g as isSymbol,a as isUndefined,m as isValidDate,he as moveFocusWithinContainer,T as noop,L as not,F as once,ie as parse2DMatrix,Me as parseFileName,_ as pipe,Ee as readFilesFromDataTransfer,B as reduceAsync,j as retry,$ as runParallel,X as runSequential,W as someAsync,K as splitStringIntoWords,N as timeout,V as toKebabCase,ve as traverseFileSystemDirectory,O as unique}; //# sourceMappingURL=index.mjs.map