UNPKG

860 BJavaScriptView Raw
1// TODO Check which types are actually supported in browsers. Chrome likes webm
2// from my testing, but we may need more.
3// We could use a library but they tend to contain dozens of KBs of mappings,
4// most of which will go unused, so not sure if that's worth it.
5const mimeToExtensions = {
6 'audio/mp3': 'mp3',
7 'audio/ogg': 'ogg',
8 'audio/webm': 'webm',
9 'image/gif': 'gif',
10 'image/heic': 'heic',
11 'image/heif': 'heif',
12 'image/jpeg': 'jpg',
13 'image/png': 'png',
14 'image/svg+xml': 'svg',
15 'video/mp4': 'mp4',
16 'video/ogg': 'ogv',
17 'video/quicktime': 'mov',
18 'video/webm': 'webm',
19 'video/x-matroska': 'mkv',
20 'video/x-msvideo': 'avi'
21}
22
23module.exports = function getFileTypeExtension (mimeType) {
24 // Remove the ; bit in 'video/x-matroska;codecs=avc1'
25 mimeType = mimeType.replace(/;.*$/, '')
26 return mimeToExtensions[mimeType] || null
27}