blob: 3bd7611917e88c5f8726fb719ed29b32aebd585b (
plain) (
blame)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
<script setup lang="ts">
import { types as extensionToMimeType, extensions as mimeTypeToExtension } from 'mime-types';
const mimeInfos = Object.entries(mimeTypeToExtension).map(([mimeType, extensions]) => ({ mimeType, extensions }));
const mimeToExtensionsOptions = Object.keys(mimeTypeToExtension).map(label => ({ label, value: label }));
const selectedMimeType = ref(undefined);
const extensionsFound = computed(() => (selectedMimeType.value ? mimeTypeToExtension[selectedMimeType.value] : []));
const extensionToMimeTypeOptions = Object.keys(extensionToMimeType).map((label) => {
const extension = `.${label}`;
return { label: extension, value: label };
});
const selectedExtension = ref(undefined);
const mimeTypeFound = computed(() => (selectedExtension.value ? extensionToMimeType[selectedExtension.value] : []));
</script>
<template>
<c-card>
<n-h2 style="margin-bottom: 0">
Mime type to extension
</n-h2>
<div style="opacity: 0.8">
Know which file extensions are associated to a mime-type
</div>
<c-select
v-model:value="selectedMimeType"
searchable
my-4
:options="mimeToExtensionsOptions"
placeholder="Select your mimetype here... (ex: application/pdf)"
/>
<div v-if="extensionsFound.length > 0">
Extensions of files with the <n-tag round :bordered="false">
{{ selectedMimeType }}
</n-tag> mime-type:
<div style="margin-top: 10px">
<n-tag
v-for="extension of extensionsFound"
:key="extension"
round
:bordered="false"
type="primary"
style="margin-right: 10px"
>
.{{ extension }}
</n-tag>
</div>
</div>
</c-card>
<c-card>
<n-h2 style="margin-bottom: 0">
File extension to mime type
</n-h2>
<div style="opacity: 0.8">
Know which mime type is associated to a file extension
</div>
<c-select
v-model:value="selectedExtension"
searchable
my-4
:options="extensionToMimeTypeOptions"
placeholder="Select your mimetype here... (ex: application/pdf)"
/>
<div v-if="selectedExtension">
Mime type associated to the extension <n-tag round :bordered="false">
{{ selectedExtension }}
</n-tag> file
extension:
<div style="margin-top: 10px">
<n-tag round :bordered="false" type="primary" style="margin-right: 10px">
{{ mimeTypeFound }}
</n-tag>
</div>
</div>
</c-card>
<div>
<n-table>
<thead>
<tr>
<th>Mime types</th>
<th>Extensions</th>
</tr>
</thead>
<tbody>
<tr v-for="{ mimeType, extensions } of mimeInfos" :key="mimeType">
<td>{{ mimeType }}</td>
<td>
<n-tag v-for="extension of extensions" :key="extension" round :bordered="false" style="margin-right: 10px">
.{{ extension }}
</n-tag>
</td>
</tr>
</tbody>
</n-table>
</div>
</template>
|