1 /* eslint-disable security/detect-object-injection */
4 const mimeDb
= require('mime-db');
6 const defaultType
= 'application/octet-stream';
9 * Expects mime-db source data as object:
13 * compressible: <Boolean>
14 * extensions: <String[]>
15 * Populate `extension` as an index from extensions to mime-types.
18 for (const [mimeType
, entry
] of Object
.entries(mimeDb
)) {
19 for (const ext
of entry
?.extensions
|| []) {
20 if (!(ext
in extension
)) {
23 extension
[ext
].push(mimeType
);
28 * Return a suitable type for a file extension.
29 * @param {string} ext file extension
30 * @param {string} def type to return if no match
33 const extensionToMime
= (ext
, def
= defaultType
) => extension
?.[ext
]?.[0] || def
;