1 /* eslint-disable security/detect-object-injection */
4 const mimeDb
= require('mime-db');
6 const defaultType
= 'application/octet-stream';
8 for (const [mimeType
, entry
] of Object
.entries(mimeDb
)) {
9 if (entry
.extensions
) {
10 entry
.extensions
.forEach((ext
) => {
11 if (!(ext
in extension
)) {
14 extension
[ext
].push(mimeType
);
20 * Return a suitable type for a file extension.
21 * @param {string} ext file extension
22 * @param {string} def type to return if no match
24 const extensionToMime
= (ext
, def
= defaultType
) => extension
[ext
] && extension
[ext
][extension
[ext
].length
- 1] || def
;