Skip to content

Instantly share code, notes, and snippets.

@gnitnuj gnitnuj/ContentType.js
Last active Feb 14, 2018

Embed
What would you like to do?
module to get content type from file extension
// this file exists just to name the gist, and because gist ordering is asciibetical, it's name starts with a capital letter.
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';
}
};
{
"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
You can’t perform that action at this time.