Last active
February 14, 2018 21:54
-
-
Save gnitnuj/9318fbe9eae86a6e1f7e01b7eaa28cc6 to your computer and use it in GitHub Desktop.
module to get content type from file extension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// this file exists just to name the gist, and because gist ordering is asciibetical, it's name starts with a capital letter. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require('path'); | |
/** | |
* getContentType | |
* Given a filepath, getContentType returns the mime-type associated to the content | |
* | |
* @param {string} - filepath | |
*/ | |
module.exports = (filePath) => { | |
switch (path.extname(filePath).toLowerCase()) { | |
case '.html': | |
return 'text/html'; | |
case '.png': | |
return 'image/png'; | |
case '.gif': | |
return 'image/gif'; | |
case '.jpg': | |
case '.jpeg': | |
return 'image/jpeg'; | |
case '.svg': | |
return 'image/svg+xml'; | |
case '.css': | |
return 'text/css'; | |
case '.js': | |
return 'text/javascript'; | |
default: | |
return 'application/json'; | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "content-type", | |
"version": "0.1.0" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment