UNPKG

@limetech/lime-elements

Version:
53 lines (49 loc) 1.32 kB
'use strict'; const fileMetadata = require('./file-metadata-8b0b9ea3.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: fileMetadata.getFileIcon(limeFile), title: fileMetadata.getFileExtensionTitle(limeFile), color: fileMetadata.getFileColor(limeFile), backgroundColor: fileMetadata.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}`); } }); } exports.createFileInfo = createFileInfo; exports.isTypeAccepted = isTypeAccepted; //# sourceMappingURL=files-d660a1fa.js.map