forked from oven-sh/bun
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmime.js
46 lines (37 loc) · 1.16 KB
/
mime.js
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
const json = await (await fetch("https://raw.githubusercontent.com/jshttp/mime-db/master/db.json")).json();
json["application/javascript"].extensions.push(`ts`, `tsx`, `mts`, `mtsx`, `cts`, `cjs`, `mjs`, `js`);
delete json["application/node"];
delete json["application/deno"];
delete json["application/wasm"];
var categories = new Set();
var all = "pub const all = struct {";
for (let key of Object.keys(json).sort()) {
const [category] = key.split("/");
categories.add(category);
all += `pub const @"${key}": MimeType = MimeType{.category = .@"${category}", .value = "${key}"};\n`;
}
const withExtensions = [
...new Set(
Object.keys(json)
.filter(key => {
return !!json[key]?.extensions?.length;
})
.flatMap(mime => {
return [...new Set(json[mime].extensions)].map(ext => {
return [`.{.@"${ext}", all.@"${mime}"}`];
});
})
.sort(),
),
];
all += "\n";
all += ` pub const extensions = ComptimeStringMap(MimeType, .{
${withExtensions.join(",\n")},
});
};`;
all += "\n";
// all += `pub const Category = enum {
// ${[...categories].map((a) => `@"${a}"`).join(", \n")}
// };
// `;
console.log(all);