UNPKG

@kopexa/sight

Version:

Kopexa Sight Design System — React component library for GRC applications

60 lines (57 loc) 1.46 kB
"use client"; // src/components/file-upload/utils/format-accept-types.ts var WILDCARD_GROUPS = { "image/*": "common image formats", "audio/*": "common audio formats", "video/*": "common video formats", "application/*": "common document formats" }; var MIME_TO_LABEL = { "image/png": "PNG", "image/jpeg": "JPG", "image/jpg": "JPG", "application/pdf": "PDF", "text/csv": "CSV", "text/plain": "TXT" }; var EXT_TO_LABEL = { ".png": "PNG", ".jpg": "JPG", ".jpeg": "JPG", ".pdf": "PDF", ".csv": "CSV", ".txt": "TXT" }; function normalizeToken(token) { return token.trim().toLowerCase(); } function formatAcceptedTypes(accept) { var _a, _b; if (!accept || typeof accept !== "string") return ""; const tokens = accept.split(",").map(normalizeToken).filter(Boolean); const labels = []; for (const token of tokens) { if (WILDCARD_GROUPS[token]) { labels.push(WILDCARD_GROUPS[token]); continue; } if (token.startsWith(".")) { labels.push( (_a = EXT_TO_LABEL[token]) != null ? _a : token.replace(/^\./, "").toUpperCase() ); continue; } if (token.includes("/")) { labels.push((_b = MIME_TO_LABEL[token]) != null ? _b : token.split("/")[1].toUpperCase()); } } const seen = /* @__PURE__ */ new Set(); return labels.filter((x) => { if (seen.has(x)) return false; seen.add(x); return true; }).join(", "); } export { formatAcceptedTypes };