forked from SolidOS/solid-panes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmimeTypes.ts
More file actions
46 lines (39 loc) · 905 Bytes
/
mimeTypes.ts
File metadata and controls
46 lines (39 loc) · 905 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
* Lightweight MIME type lookup
* Replaces the heavy mime-types package (146KB)
*/
const extToMime: Record<string, string> = {
// Web documents
html: 'text/html',
htm: 'text/html',
css: 'text/css',
js: 'text/javascript',
json: 'application/json',
xml: 'text/xml',
txt: 'text/plain',
md: 'text/markdown',
// RDF
ttl: 'text/turtle',
n3: 'text/n3',
rdf: 'application/rdf+xml',
jsonld: 'application/ld+json',
// Images
jpg: 'image/jpeg',
jpeg: 'image/jpeg',
png: 'image/png',
gif: 'image/gif',
svg: 'image/svg+xml',
webp: 'image/webp',
// Media
mp3: 'audio/mpeg',
mp4: 'video/mp4',
webm: 'video/webm',
// Documents
pdf: 'application/pdf',
}
export function lookup (filename: string): string | false {
const ext = filename.split('.').pop()?.toLowerCase()
if (!ext) return false
return extToMime[ext] || false
}
export default { lookup }