Guesses (MIME) Content-Type based on file name.
Want to see pretty graphs? Log in now!
npm install guess-content-type
|17||downloads in the last month|
|Last Published By|
|Version||0.1.0 last updated a year ago|
Guesses (MIME) Content-Type (including charset) based on file name.
This is based on mime module, but has a more convenient interface if your goal is to explictly state that your content in text-based formats has UTF-8 encoding (which many editors have as output nowadays) . Without specifying a charset explicitly, most browsers will default to ISO-8859-1, or whatever the user preference is.
Don't use this module if you're not sure about the character encoding of the HTML or text content you're generating, because you'd be making things worse by specifying the wrong encoding. Check your editor's documentation first.
Note that problems with encoding (at least in Western countries) will only show up when you use non-ascii characters.
var guessType = require("guess-content-type") var contentType = guessType(filename)
contentType is now the (guessed) media type for
filename, or the media type including
charset=UTF-8 parameter if it's a text type. This can be put in the HTTP
filename may be an entire path or url as well.
Example guesses, used as tests
guesses = "a.txt": "text/plain; charset=UTF-8" "b.html": "text/html; charset=UTF-8" ".jpg": "image/jpeg" ".unknown-type": "application/octet-stream" "/": "application/octet-stream" "/some/path": "application/octet-stream" "http://google.com/abc.html": "text/html; charset=UTF-8" "http://google.com/abc.html?q": "text/html; charset=UTF-8" "http://google.com/abc.gif?q": "image/gif"
guess-content-type is released under the MIT License.
Copyright (c) 2013 Meryn Stol