UNPKG

@bothub-chat/ui

Version:

Bothub UI Components

2 lines (1 loc) 1.05 kB
import{__awaiter as t}from"tslib";const n=n=>t(void 0,void 0,void 0,(function*(){return n.name.match(/.png$/i)||n.name.match(/.jpg$/i)||n.name.match(/.jpeg$/i)?new Promise(((t,e)=>{const r=new FileReader;r.addEventListener("load",(()=>{var n,i;const o=null!==(i=null===(n=r.result)||void 0===n?void 0:n.toString())&&void 0!==i?i:null;if(null===o)return e(new Error("result not found"));t(o)})),r.readAsDataURL(n)})):null})),e=e=>t(void 0,void 0,void 0,(function*(){const t=yield Promise.all(e.map(n)),r=e.map(((n,e)=>({name:n.name,previewUrl:t[e],native:n})));return[...new Map([...r].map((t=>[t.name,t]))).values()]})),r=t=>{const n=Math.floor(t/60),e=t%60;return`${String(n).padStart(2,"0")}:${e.toFixed(1).padStart(2,"0").replace(".",",")}`};function i(t,n){if(!n||""===n.trim())return!0;return n.split(",").map((t=>t.trim())).filter(Boolean).some((n=>{if(n.endsWith("/*")){const e=n.slice(0,n.length-1);return t.startsWith(e)}return n===t}))}export{r as formatSeconds,e as formatUploadFiles,n as getPreviewUrlForFile,i as isFileTypeAccepted};