1

I've got a MIME type, and I want the corresponding media type.

For instance, PDF files can have many mime types:

  • application/pdf
  • application/x-pdf
  • application/acrobat
  • applications/vnd.pdf
  • application/x-download
  • application/download
  • text/pdf
  • text/x-pdf
  • (maybe more?)

I'm looking for a JavaScript library that would tell me that it's a PDF file if I give it any of these MIME types. Is there anything like it?

Any help much appreciated

Thomas
  • 1,491
  • 13
  • 23

1 Answers1

1
function isPdf(mimeType) {
    var pdfMimeTypes = [
        'application/pdf',
        'application/x-pdf',
        'application/acrobat',
        'applications/vnd.pdf',
        'application/x-download',
        'application/download',
        'text/pdf',
        'text/x-pdf'
    ];

    return pdfMimeTypes.indexOf(mimeType) > -1;
}
Kevin Boucher
  • 16,426
  • 3
  • 48
  • 55
  • 1
    I could do that, but I'm pretty sure it has already been done, probably in a better way that I would. I was hoping that there was something kind of official or widely used. [This](https://github.com/rnicholus/determinater) will do. – Thomas Jul 02 '15 at 09:07