UNPKG

@limetech/lime-elements

Version:
50 lines (47 loc) 1.31 kB
import { g as getFileIcon, a as getFileExtensionTitle, b as getFileColor, c as getFileBackgroundColor } from './file-metadata-ce643c6e.js'; /** * * @param file */ function createFileInfo(file) { const limeFile = { id: crypto.randomUUID(), filename: file.name, contentType: file.type, size: file.size, fileContent: file, }; limeFile.icon = { name: getFileIcon(limeFile), title: getFileExtensionTitle(limeFile), color: getFileColor(limeFile), backgroundColor: getFileBackgroundColor(limeFile), }; return limeFile; } /** * * @param file * @param accept */ function isTypeAccepted(file, accept) { if (accept === undefined || accept === '*') { return true; } const acceptList = accept.split(',').map((raw) => raw.trim()); return acceptList.some((acceptedType) => { if (acceptedType === file.contentType) { return true; } if (acceptedType.endsWith('/*')) { const baseType = acceptedType.split('/')[0]; return file.contentType.startsWith(`${baseType}/`); } if (acceptedType.startsWith('.')) { const fileType = acceptedType.split('.')[1]; return file.contentType.endsWith(`/${fileType}`); } }); } export { createFileInfo as c, isTypeAccepted as i }; //# sourceMappingURL=files-b1cef4e4.js.map