Files
bun.sh/misctools/mime.js
Colin McDonnell f7f1b60444 Add bun-types, add typechecking, add child_process types (#1475)
* Add bun-types to packages

* Improve typing

* Fix types in tests

* Fix dts tests

* Run formatter

* Fix all type errors

* Add strict mode, fix type errors

* Add ffi changes

* Move workflows to root

* Add workflows

* Remove labeler

* Add child_process types

* Fix synthetic defaults issue

* Remove docs

* Move scripts

* Run prettier

* Include examples in typechecking

* captureStackTrace types

* moved captureStackTrace types to globals

* Address reviews

Co-authored-by: Colin McDonnell <colinmcd@alum.mit.edu>
Co-authored-by: Dylan Conway <dylan.conway567@gmail.com>
2022-11-09 15:40:40 -08:00

58 lines
1.2 KiB
JavaScript

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);