UNPKG

@aplus-frontend/ui

Version:

55 lines (54 loc) 1.39 kB
import a from "mime"; let s; function c(n) { s = n; } function u(n, i) { const t = i.split(",").map((e) => e.trim()); for (const e of t) { if (e === "*") return !0; if (e.endsWith("/*")) { const [p] = e.split("/"), [r] = n?.type?.split("/") || []; if (p === r) return !0; } else if (/^\./.test(e)) { if (n.type === a.getType(e)) return !0; const p = n.name?.lastIndexOf("."); if (p > -1 && n.name?.slice(p) === e) return !0; } else { if (n.type === e) return !0; const p = n.name?.lastIndexOf("."); if (p > -1 && [...a.getAllExtensions(e) || []].map( (o) => `.${o}` ).includes(n.name?.slice(p))) return !0; } } return !1; } function m(n) { const i = { image: s("ap.apUpload.pictureType"), video: s("ap.apUpload.videoType"), audio: s("ap.apUpload.audioType"), application: s("ap.apUpload.documentType"), "*": s("ap.apUpload.allTypes") }; return n.split(",").map((t) => t.trim()).map((t) => { if (t === "*") return i[t]; if (t.endsWith("/*")) { const [e] = t.split("/"); return i[e] || e; } else return /^\./.test(t) ? t : [...a.getAllExtensions(t) || []].map((e) => `.${e}`).join(",") || t; }).join(","); } export { u as fileMatchesAccept, m as getAcceptText, c as injectUtilAccept };