@aplus-frontend/ui
Version:
55 lines (54 loc) • 1.38 kB
JavaScript
import i from "mime";
let s;
function c(n) {
s = n;
}
function u(n, a) {
const t = a.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 === i.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 && [...i.getAllExtensions(e) || []].map(
(o) => `.${o}`
).includes(n.name?.slice(p)))
return !0;
}
}
return !1;
}
function m(n) {
const a = {
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 a[t];
if (t.endsWith("/*")) {
const [e] = t.split("/");
return a[e] || e;
} else return /^\./.test(t) ? t : [...i.getAllExtensions(t) || []].map((e) => `.${e}`).join(",") || t;
}).join(",");
}
export {
u as fileMatchesAccept,
m as getAcceptText,
c as injectLocaleToAccept
};