Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
getMimeInfo = function (contentType, response) {
var normalized,
detected;
if (!contentType) {
detected = fileType(response);
detected && (contentType = detected.mime);
}
// if contentType is not detected set text/plain as default
if (!contentType) {
contentType = CONTENT_TYPE_TEXT_PLAIN;
}
normalized = mimeFormat.lookup(contentType);
return {
mimeType: normalized.type, // sanitised mime type base
mimeFormat: normalized.format, // format specific to the type returned
charset: normalized.charset || CHARSET_UTF8,
extension: mimeType.extension(normalized.source) || E
};
},
mimeInfo: function (type, disposition) {
Header.isHeader(type) && (type = type.value);
Header.isHeader(disposition) && (disposition = disposition.value);
// validate that the content type exists
if (!(type && _.isString(type))) { return; }
var normalised = mimeFormat.lookup(type),
info = {};
_.assign(info, {
type: normalised.type, // sanitised mime type base
format: normalised.format, // format specific to the type returned
name: DEFAULT_RESPONSE_FILENAME,
ext: mimeType.extension(normalised.source) || E, // file extension from sanitised content type
charset: normalised.charset || UTF8,
// also storing some meta info for possible debugging
_originalContentType: type, // the user provided mime type
_sanitisedContentType: normalised.source, // sanitised mime type
_accuratelyDetected: !normalised.orphan // this being true implies worse case (raw render)
});
// build the file name from extension